Reputation: 341
So I have a model I estimated using feols()
from the fixest
package. I have to extract all coefficients and export them to a different program to calculate the predicted values for other observations (not in R). For this I used the following code:
model.coef <- c(unlist(fixef(my_model)), coef(my_model))
I then saved and exported my results. However, I have noticed that neither coef()
or fixef()
extract the model's constant. I also know that there must be a constant as all my factor variables are missing one (the first) level and similarly for my fixed effects, each one is missing one level. Hence, I was wondering if there is a way to recover the value of this constant. I tried doing something like:
predict(my_model, newdata = data.frame(
"var1" = 0, "var2" = 0,
"factor1" = factor(0), ..., "result_var" = NA)
)
However this too cumbersome and it doesn't even work! Since I get the following error:
Error when creating the linear matrix: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
I would like to know how can I recover the model's constant, I have found nothing so far looking through fixest
documentation.
Any help would be greatly appreciated.
Upvotes: 0
Views: 1913
Reputation: 341
I found the problem, the model does not have a constant and the reason why I had less fixed effects than levels was because exactly one of them always had NA
in an independent variable giving the illusion that one level was omitted. That's the same reason why I was getting that error, since I inputted the fixed effect not included in the model. I will leave this post in case some else has this problem in the future.
Upvotes: 4