lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

How to include the intercept term in the model? #430

Closed StarryCatte closed 9 months ago

StarryCatte commented 11 months ago

I found that the intercept term is automatically omitted when using the 'feols' function for regression. How can I include the intercept term in my model?

library(fixest)
data("iris")

res = feols(Sepal.Length ~ Sepal.Width + Petal.Length | Species, iris)
summary(res)

OLS estimation, Dep. Var.: Sepal.Length
Observations: 150 
Fixed-effects: Species: 3
Standard-errors: Clustered (Species) 
             Estimate Std. Error t value Pr(>|t|)    
Sepal.Width  0.432217   0.161308 2.67945 0.115623    
Petal.Length 0.775629   0.126546 6.12925 0.025601 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RMSE: 0.305129     Adj. R2: 0.859538
                 Within R2: 0.641507
lrberge commented 9 months ago

Hi, the intercept has no real meaning in the presence of fixed effects. Indeed all variables are demeaned with respect to the fixed-effects. Hence an intercept, once demeaned, would be equal to a vector of 0s, leading to its removal during the estimation.

If you want an intercept (within fixest), you need to abandon the fixed-effects slot and use factors (which may not be doable in practice):

res = feols(Sepal.Length ~ Sepal.Width + Petal.Length + as.factor(Species), iris)