## create covariates
x <- rnorm(1000)
x2 <- rnorm(length(x))
## individual and firm
id <- factor(sample(20,length(x),replace=TRUE))
firm <- factor(sample(13,length(x),replace=TRUE))
## effects for them
id.eff <- rnorm(nlevels(id))
firm.eff <- rnorm(nlevels(firm))
## left hand side
u <- rnorm(length(x))
y <- x + 0.5*x2 + id.eff[id] + firm.eff[firm] + u
## estimate and print result
est <- felm(y ~ x+x2+G(id)+G(firm))
summary(est)
## compare with lm
summary(lm(y ~ x + x2 + id + firm-1))
## alternatively
felm(y ~ x + x2,fl=list(id=id,firm=firm))
getfe(est)
## make an iv-example, Q is instrumented by x3, report robust s.e.
x3 <- rnorm(length(x))
Q <- 0.3*x3 + x + 0.2*x2 + id.eff[id] + 0.7*u + rnorm(length(x),sd=0.3)
y <- y + Q
ivest <- felm(y ~ x + x2 + G(id)+G(firm) + Q, iv=Q ~ x3)
summary(ivest,robust=TRUE)
Run the code above in your browser using DataLab