R Under development (unstable) (2024-02-19 r85946 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(lfe) Loading required package: Matrix > options(lfe.threads=2,digits=5,warn=1) > set.seed(65318) > x <- rnorm(500) > x2 <- rnorm(length(x)) > > ## create individual and firm > id <- factor(sample(10,length(x),replace=TRUE)) > firm <- factor(sample(6,length(x),replace=TRUE,prob=c(2,rep(1,5)))) > > ## effects > id.eff <- rnorm(nlevels(id)) > firm.eff <- rnorm(nlevels(firm)) > > ## left hand side > y <- x + 0.25*x2 + id.eff[id] + firm.eff[firm] + rnorm(length(x)) > x[sample(500,20)] <- NA > y[sample(500,20)] <- NA > ## estimate > summary(est <- felm(y ~ x+x2 | id+firm)) Call: felm(formula = y ~ x + x2 | id + firm) Residuals: Min 1Q Median 3Q Max -3.310 -0.660 -0.022 0.743 2.643 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.9702 0.0507 19.12 < 2e-16 *** x2 0.3254 0.0506 6.43 3.3e-10 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.03 on 443 degrees of freedom (40 observations deleted due to missingness) Multiple R-squared(full model): 0.791 Adjusted R-squared: 0.783 Multiple R-squared(proj model): 0.486 Adjusted R-squared: 0.468 F-statistic(full model): 105 on 16 and 443 DF, p-value: <2e-16 F-statistic(proj model): 210 on 2 and 443 DF, p-value: <2e-16 > getfe(est) effect obs comp fe idx id.1 -1.636089 40 1 id 1 id.2 0.042766 46 1 id 2 id.3 -0.733947 47 1 id 3 id.4 -0.855250 46 1 id 4 id.5 2.092365 32 1 id 5 id.6 1.123941 52 1 id 6 id.7 1.429550 50 1 id 7 id.8 -0.918586 43 1 id 8 id.9 -2.481822 51 1 id 9 id.10 -0.346876 53 1 id 10 firm.1 0.000000 120 1 firm 1 firm.2 -0.844583 74 1 firm 2 firm.3 0.675597 78 1 firm 3 firm.4 0.748129 64 1 firm 4 firm.5 -1.542114 55 1 firm 5 firm.6 2.193690 69 1 firm 6 > summary(lm(y ~ x + x2 + id + firm -1)) Call: lm(formula = y ~ x + x2 + id + firm - 1) Residuals: Min 1Q Median 3Q Max -3.310 -0.660 -0.022 0.743 2.643 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.9702 0.0507 19.12 < 2e-16 *** x2 0.3254 0.0506 6.43 3.3e-10 *** id1 -1.6361 0.1786 -9.16 < 2e-16 *** id2 0.0428 0.1705 0.25 0.802 id3 -0.7339 0.1753 -4.19 3.4e-05 *** id4 -0.8552 0.1748 -4.89 1.4e-06 *** id5 2.0924 0.2012 10.40 < 2e-16 *** id6 1.1239 0.1680 6.69 6.8e-11 *** id7 1.4296 0.1706 8.38 7.2e-16 *** id8 -0.9186 0.1766 -5.20 3.0e-07 *** id9 -2.4818 0.1667 -14.89 < 2e-16 *** id10 -0.3469 0.1663 -2.09 0.038 * firm2 -0.8446 0.1548 -5.46 8.1e-08 *** firm3 0.6756 0.1528 4.42 1.2e-05 *** firm4 0.7481 0.1614 4.64 4.7e-06 *** firm5 -1.5421 0.1690 -9.12 < 2e-16 *** firm6 2.1937 0.1587 13.82 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.03 on 443 degrees of freedom (40 observations deleted due to missingness) Multiple R-squared: 0.791, Adjusted R-squared: 0.783 F-statistic: 98.8 on 17 and 443 DF, p-value: <2e-16 > > proc.time() user system elapsed 0.92 0.07 0.98