## create covariates
x <- rnorm(50000)
x2 <- rnorm(length(x))
## create individual and firm
id <- factor(sample(5000,length(x),replace=TRUE))
firm <- factor(sample(3000,length(x),replace=TRUE))
## 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
est <- felm(y ~ x+x2 + G(id)+G(firm))
summary(est)
## extract the group effects
alpha <- getfe(est,se=TRUE)
## find some differences, with standard errors
head(alpha,3)
ef <- function(v) {
w <- c(v[2]-v[1],v[3]-v[2],v[3]-v[1])
names(w) <-c('id2-id1','id3-id2','id3-id1')
w
}
attr(ef,'noP') <- TRUE
getfe(est,ef=ef,se=TRUE)
summary(lm(y ~ x+x2+id+firm-1))Run the code above in your browser using DataLab