R Under development (unstable) (2024-02-14 r85901 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(655320) > x <- rnorm(5000,mean=200) > x2 <- rnorm(length(x)) > x3 <- rexp(length(x)) > ## create individual and firm > id <- factor(sample(1500,length(x),replace=TRUE)) > firm <- factor(sample(1300,length(x),replace=TRUE)) > shoe <- factor(sample(100,length(x),replace=TRUE)) > shirt <- factor(sample(100,length(x),replace=TRUE)) > ## effects > id.eff <- rnorm(nlevels(id)) > firm.eff <- rnorm(nlevels(firm)) > shoe.eff <- rnorm(nlevels(shoe)) > shirt.eff <- rnorm(nlevels(shirt)) > ## left hand side > y <- x + 0.25*x2 + 0.5*x3 + id.eff[id] + firm.eff[firm] + shoe.eff[shoe] + shirt.eff[shirt] + rnorm(length(x)) > > ## estimate > print(est <- felm(y ~ x+x2 + x3 |id+firm+shoe+shirt)) x x2 x3 0.996 0.254 0.492 > cat('Components:',nlevels(est$cfactor),'largest:',sum(est$cfactor == '1'),'\n') Components: 7 largest: 4993 > ## extract the group fixed effects > ## verify that id and firm coefficients are 1 > options(scipen=8) > > for(ef in c('ln','ref','zm','zm2')) { + fe <- getfe(est,ef=ef) + ## merge back + + ideff <- fe[paste('id',id,sep='.'),'effect'] + firmeff <- fe[paste('firm',firm,sep='.'),'effect'] + shoeeff <- fe[paste('shoe',shoe,sep='.'),'effect'] + shirteff <- fe[paste('shirt',shirt,sep='.'),'effect'] + if(ef %in% c('zm','zm2')) { + icpt <- fe[paste('icpt',1:nlevels(est$cfactor),sep='.'),'effect'][est$cfactor] + lmres <- lm(y ~ x + x2 + x3 + ideff + firmeff + shoeeff +shirteff + icpt-1) + acc <- coef(lmres)[c('ideff','firmeff','shoeeff','shirteff','icpt')] + } else { + lmres <- lm(y ~ x + x2 + x3 + ideff + firmeff + shoeeff +shirteff-1) + acc <- coef(lmres)[c('ideff','firmeff','shoeeff','shirteff')] + } + print(summary(lmres,digits=8)) + cat('accuracy:',sprintf('%.8e',acc),'\n') + } Warning in is.estimable(ef, obj$fe) : non-estimable function, largest error 0.5 in coordinate 1530 ("firm.87") Warning in getfe.kaczmarz(obj, se, ef = ef, bN = bN, robust = robust, cluster = cluster, : Supplied function seems non-estimable Call: lm(formula = y ~ x + x2 + x3 + ideff + firmeff + shoeeff + shirteff - 1) Residuals: Min 1Q Median 3Q Max -2.327 -0.418 0.000 0.420 2.294 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.99628 0.00007 14227.8 <2e-16 *** x2 0.25423 0.00943 27.0 <2e-16 *** x3 0.49156 0.00913 53.8 <2e-16 *** ideff 1.00000 0.00799 125.2 <2e-16 *** firmeff 1.00000 0.00793 126.1 <2e-16 *** shoeeff 1.00000 0.00844 118.5 <2e-16 *** shirteff 1.00000 0.00913 109.5 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.666 on 4993 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 6.49e+07 on 7 and 4993 DF, p-value: <2e-16 accuracy: 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 Call: lm(formula = y ~ x + x2 + x3 + ideff + firmeff + shoeeff + shirteff - 1) Residuals: Min 1Q Median 3Q Max -2.327 -0.418 0.000 0.420 2.294 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.996277 0.000117 8538.8 <2e-16 *** x2 0.254233 0.009429 27.0 <2e-16 *** x3 0.491555 0.009133 53.8 <2e-16 *** ideff 1.000000 0.007982 125.3 <2e-16 *** firmeff 1.000000 0.007927 126.2 <2e-16 *** shoeeff 1.000000 0.008441 118.5 <2e-16 *** shirteff 1.000000 0.009131 109.5 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.666 on 4993 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 6.49e+07 on 7 and 4993 DF, p-value: <2e-16 accuracy: 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 Call: lm(formula = y ~ x + x2 + x3 + ideff + firmeff + shoeeff + shirteff + icpt - 1) Residuals: Min 1Q Median 3Q Max -2.327 -0.418 0.000 0.420 2.294 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.99628 0.00121 821.22 < 2e-16 *** x2 0.25423 0.00943 26.96 < 2e-16 *** x3 0.49156 0.00913 53.81 < 2e-16 *** ideff 1.00000 0.00799 125.14 < 2e-16 *** firmeff 1.00000 0.00793 126.06 < 2e-16 *** shoeeff 1.00000 0.00844 118.46 < 2e-16 *** shirteff 1.00000 0.00913 109.48 < 2e-16 *** icpt 1.00000 0.14957 6.69 0.000000000025 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.666 on 4992 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 5.67e+07 on 8 and 4992 DF, p-value: <2e-16 accuracy: 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 Call: lm(formula = y ~ x + x2 + x3 + ideff + firmeff + shoeeff + shirteff + icpt - 1) Residuals: Min 1Q Median 3Q Max -2.327 -0.418 0.000 0.420 2.294 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.99628 0.00122 815.03 < 2e-16 *** x2 0.25423 0.00943 26.96 < 2e-16 *** x3 0.49156 0.00913 53.81 < 2e-16 *** ideff 1.00000 0.00799 125.14 < 2e-16 *** firmeff 1.00000 0.00793 126.06 < 2e-16 *** shoeeff 1.00000 0.00844 118.46 < 2e-16 *** shirteff 1.00000 0.00913 109.48 < 2e-16 *** icpt 1.00000 0.14815 6.75 0.000000000016 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.666 on 4992 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 5.67e+07 on 8 and 4992 DF, p-value: <2e-16 accuracy: 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00 > > > proc.time() user system elapsed 1.34 0.12 1.46