## create covariates
x <- rnorm(100000)
x2 <- rnorm(length(x))
## create individual and firm
id <- factor(sample(20,length(x),replace=TRUE))
firm <- factor(sample(8,length(x),replace=TRUE,prob=c(2,rep(1,7))))
## 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))
## make a data frame
dset <- data.frame(y,x,x2,id,firm)
## estimate and print result
est <- felm(y ~ x+x2,fl=list(id=id,firm=firm),data=dset)
print(est)
## extract the group effects, and print them
print(getfe(est))
## compare with an ordinary lm
summary(lm(y ~ x+x2+id+firm-1,data=dset))
## compare with lmer
if(require(lme4))
coef(lmer(y ~ x + x2 + (1|id) + (1|firm),data=dset))
Run the code above in your browser using DataLab