R Under development (unstable) (2024-02-21 r85967 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=1,digits=4,warn=1) > set.seed(42) > x <- rnorm(500) > x2 <- rnorm(length(x)) > > ## create individual and firm > id <- factor(sample(40,length(x),replace=TRUE)) > firm <- factor(sample(30,length(x),replace=TRUE,prob=c(2,rep(1,29)))) > foo <- factor(sample(20,length(x),replace=TRUE)) > ## effects > id.eff <- rnorm(nlevels(id)) > firm.eff <- rnorm(nlevels(firm)) > foo.eff <- rnorm(nlevels(foo)) > ## left hand side > y <- x + 0.25*x2 + id.eff[id] + firm.eff[firm] + foo.eff[foo] + rnorm(length(x)) > > # make a data frame > fr <- data.frame(y,x,x2,id,firm,foo) > ## estimate and print result > est <- felm(y ~ x+x2|id+firm+foo, data=fr, keepX=TRUE) > > alpha=getfe(est) > bccorr(est,alpha,corrfactors=c(3,1)) corr v1 v2 cov d1 d2 d12 -0.049334 0.999331 0.695755 -0.041137 0.048487 0.088972 -0.005234 > fevcov(est,alpha) id firm foo id 0.69244 -0.02273 -0.04353 firm -0.02273 0.59472 0.02932 foo -0.04353 0.02932 1.01086 attr(,"bias") id firm foo id 0.092285 -0.002635 -0.002846 firm -0.002635 0.057675 -0.002682 foo -0.002846 -0.002682 0.036962 > varvars(est,alpha) [1] 0.007358 0.005979 0.009864 > > > proc.time() user system elapsed 1.85 0.10 1.98