R Under development (unstable) (2024-02-22 r85974 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)) > ## effects > id.eff <- rnorm(nlevels(id)) > firm.eff <- rnorm(nlevels(firm)) > shoe.eff <- rnorm(nlevels(shoe)) > ## left hand side > y <- x + 0.25*x2 + 0.5*x3 + id.eff[id] + firm.eff[firm] + shoe.eff[shoe] + rnorm(length(x)) > > ## estimate > summary(est <- felm(y ~ x+x2 + x3 | id + firm + shoe)) Call: felm(formula = y ~ x + x2 + x3 | id + firm + shoe) Residuals: Min 1Q Median 3Q Max -2.716 -0.422 0.000 0.421 2.208 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.9950 0.0210 47.4 <2e-16 *** x2 0.2531 0.0211 12.0 <2e-16 *** x3 0.5182 0.0207 25.0 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.995 on 2185 degrees of freedom Multiple R-squared(full model): 0.914 Adjusted R-squared: 0.803 Multiple R-squared(proj model): 0.577 Adjusted R-squared: 0.0313 F-statistic(full model):8.25 on 2814 and 2185 DF, p-value: <2e-16 F-statistic(proj model): 992 on 3 and 2185 DF, p-value: <2e-16 *** Standard errors may be too high due to more than 2 groups and exactDOF=FALSE > cat('Components:',nlevels(est$cfactor),'largest:',sum(est$cfactor == '1'),'\n') Components: 7 largest: 4993 > ## extract the group fixed effects > for(ef in c('ln','ref')) { + 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'] + + ## verify that id and firm coefficients are 1 + options(scipen=8) + print(summary(lm(y ~ x + x2 + x3 + ideff + firmeff + shoeeff -1),digits=8)) + } Warning in is.estimable(ef, obj$fe) : non-estimable function, largest error 0.3 in coordinate 184 ("id.198") 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 - 1) Residuals: Min 1Q Median 3Q Max -2.716 -0.422 0.000 0.421 2.208 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.9949750 0.0000765 13004.6 <2e-16 *** x2 0.2530979 0.0093197 27.2 <2e-16 *** x3 0.5182466 0.0090240 57.4 <2e-16 *** ideff 1.0000000 0.0079960 125.1 <2e-16 *** firmeff 1.0000000 0.0078187 127.9 <2e-16 *** shoeeff 1.0000000 0.0107776 92.8 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.658 on 4994 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 7.73e+07 on 6 and 4994 DF, p-value: <2e-16 Call: lm(formula = y ~ x + x2 + x3 + ideff + firmeff + shoeeff - 1) Residuals: Min 1Q Median 3Q Max -2.716 -0.422 0.000 0.421 2.208 Coefficients: Estimate Std. Error t value Pr(>|t|) x 0.994975 0.000123 8061.2 <2e-16 *** x2 0.253098 0.009320 27.2 <2e-16 *** x3 0.518247 0.009024 57.4 <2e-16 *** ideff 1.000000 0.007997 125.0 <2e-16 *** firmeff 1.000000 0.007816 127.9 <2e-16 *** shoeeff 1.000000 0.010777 92.8 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.658 on 4994 degrees of freedom Multiple R-squared: 1, Adjusted R-squared: 1 F-statistic: 7.73e+07 on 6 and 4994 DF, p-value: <2e-16 > > # Perform a bootstrap > a <- felm(y ~ x+x2 + x3 | id + firm, nostats=TRUE, Nboot=10, bootexpr=quote(x/x3*x2)) > mean(a$boot) [1] 0.55391 > sd(a$boot) [1] 0.10028 > > proc.time() user system elapsed 2.04 0.15 1.87