I am trying to get fitted values out of a linear model with many factors, which I would like to estimate using the felm
function from the R package lfe
. Unless I am misinterpreting what is meant by the fitted.values
returned by the function, it looks like these values do not match the output I get when I build them manually. Here is an example adapted from the package documentation:
library(lfe)
set.seed(42)
nn = 10
n1 = 3
x <- rnorm(nn)
f1 <- sample(n1, length(x), replace=TRUE)
y <- 2.13*x + cos(f1) + rnorm(length(x), sd=0.5)
est <- felm(y ~ x | f1)
estb <- lm(y~x+factor(f1)-1)
# we have exactly the same coefficients
getfe(est)['effect']/estb$coefficients[2:(n1+1)]
est$coefficients/estb$coefficients[1]
# but different fitted values -- in fact all having the same group offset
estb$fitted.values-est$fitted.values
What are these offsets? Does felm
intend to return a different kind of fitted value? Thanks for looking