## create covariates
x <- rnorm(100000)
x2 <- rnorm(length(x))
## create individual and firm
id <- factor(sample(3000,length(x),replace=TRUE))
firm <- factor(sample(1500,length(x),replace=TRUE,prob=c(2,rep(1,1499))))
## effects
id.eff <- rlnorm(nlevels(id))
firm.eff <- rexp(nlevels(firm))
## left hand side
y <- x + 0.25*x2 + id.eff[id] + firm.eff[firm] + rnorm(length(x))
## estimate and print result
cat(date(),'Start lfe estimation
')
est <- felm(y ~ x+x2 + G(id)+G(firm))
summary(est)
## extract the group effects
alpha <- getfe(est)
cat(date(),'Done
')
cat(date(),'Compare with lm estimation\n')
lmsum <- summary(lm(y ~ x+x2+id+firm-1))
cat(date(),'Done\n')Run the code above in your browser using DataLab