-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feols() incorrectly says FE's are colinear with regressors. #538
Comments
A small note to the comment above that I thought was clear but didn't mention explicitly, |
I'm not sure why my comment disappeared, sorry. But what I meant was that you essentially have one fixed effect for every observation. There is no remaining variation to estimate the coefficient for |
You are right. I'm just saying the error message doesn't reflect that fact and it would be helpful to developers if the error message described the problem better. |
Right! That would be helpful. |
Thank you! |
@Alejandro-Ortiz-WBG, the comment is not "Fixed effects" are indicator variables for each unique value of df <- data.frame(y = rnorm(3), x = rnorm(3), fe = rnorm(3, 1, 3))
model.matrix(~ 0 + x + factor(fe), data = df)
#> x factor(fe)0.37770054215013 factor(fe)0.51974892031667
#> 1 -0.9281797 1 0
#> 2 0.6688002 0 1
#> 3 0.8449222 0 0
#> factor(fe)1.18450468893623
#> 1 0
#> 2 0
#> 3 1 The three indicators are collinear with x. I think you mean the numeric vector This is a very edge case because it will only happen when each value of the incorrect fixed effect is unique. This error wouldn't happen if say |
@kylebutts You are right that the error would not happen if there were more observations than FEs. The point is, however, the error message reads |
@ja-ortiz-uniandes You are mixing up the variable you called |
@kylebutts Thanks, you are right. I do believe that adding clarity to the message would be useful, something along the lines of "As many FE as observations makes estimation not possible." Saying simply "x is collinear with the FEs" gives you the idea that the variable |
As always, thanks for developing such an incredible program. I use it almost daily!
Reproducible example
Expected behavior
Change the error message to include cases where there is one value per observation on the FE. This can either be done by amending the error such that it says "'x', is collinear with the fixed effects or there is not enough within-group variation in the FE variable" or preferably by including a new error message "insufficient within group variation in variable 'fe' to estimate fixed effects. Please check you model specification"
Why this matters
This is not a high priority issue. Fixing it would make using the program easier when you accidentally write an incorrect model specification. Sometimes, this can be rather difficult to diagnose. In particular if regressions are nested or inside functions, or both. In these cases formulas are typically constructed and it is not always obvious why the program failed. Correcting the error message makes the issue clearer and can save developers time in such situations (ehem...).
The text was updated successfully, but these errors were encountered: