Search code examples
rlinear-regressionlm

Remove Factor Variables from Fixed Effects Regression lm Object in R


I estimate a fixed effects model in R using the lm() function. The fixed effects are included as factor(FE). Furthermore, I include district specific time trends which are included in the model as factor(distr):trend. In total, this results in about 250 coefficients estimated. Since I am only interested in around 10 coefficients, I would like to remove the rest of the model object. Specifically, I would like to remove everything of these additional coefficients of the object. For further understanding, the current workflow is:

  1. estimate regression using lm() - everything works well
  2. compute HAC standard errors using coeftest() with vcvovHAC - computation takes forever for so many parameters
  3. plug models into stargazer() and suppress all the not needed variables from the table - works well

As you can see, the problem occurs when computing the standard errors of the parameters.

To address several possibly upcoming hints/questions:

  1. Why are you not using plm package?
  • Residuals are somehow grouped which gets annoying in the process of model diagnostics. Also, afaik residuals are reordered somehow and cannot be merged with the data easily again
  1. Why are you not using fixest package?
  • It is not possible to use with stargazer.

I already removed the coefficients of the model using model$coefficients. Then, when using summary(model) the standard errors of the omitted coefficients are still shown and the coefficients are displayed as NA. Then, the problem happens again with coeftest() since the many coefficients are still present.

So, I would like to remove these coefficients from the model object entirely, in order to continue working with the object!

I am very happy for any hints on a possible solution!


Solution

  • After many hours of searching to solve the problem, I came to the conclusion that no feasible solution exists. I decided to use the fixest package and its corresponding etable() function and am very happy now. Can only recommend to use this package!