I wish to add the overall intercept of a fixed effects model ("within" panel data analysis). This is common practice in Stata and I wish to mimic the Stata output by including the overall intercept.
library(stargazer)
library(plm)
data("Hedonic", package = "plm")
mod_fe <- plm(mv ~ age + crim, data = Hedonic, index = "townid")
overallint <- within_intercept(mod_fe)
overallint # 10.25964
stargazer(mod_fe, type = "text")
Dependent variable:
---------------------------
mv
----------------------------------------
age -0.004***
(0.001)
crim -0.009***
(0.002)
----------------------------------------
Observations 506
R2 0.147
Adjusted R2 -0.046
F Statistic 35.431*** (df = 2; 412)
Note: *p<0.1; **p<0.05; ***p<0.01
I could not find any relevant information to add the intercept. The mod_fe object does not store the intercept so I could not pull it from there. The within_intercept function calculates the actual value.
Read the documentation for
within_intercept(and the contained example) and you find that the function can output a model object with the intercept as well (and not only the intercept) with argumentreturn.model = TRUE.A fully worked example incl. stargazer output comparing a FE model with and without intercept is:
NB: the model object returned by
within_interceptin this case identifies itself technically as a pooling model.