lrberge / fixest

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

Collinearity diagnostics with fixed effects and more than two predictor variables #412

Closed grlju closed 9 months ago

grlju commented 1 year ago

Hi Laurent,

Thanks for the great package. I am getting an error message when trying to run collinearity diagnostics with fixed effects and more than two predictor variables.

See this example:

library(fixest)
data(trade)

gravity_pois = fepois(Euros ~ log(dist_km) + Origin + Destination | Product + Year, trade)
collinearity(gravity_pois)

I get the following error:

Checking Collinearity: simple with fixed-effects:..OK,  multiple:.............................OK, multiple with cluster.Error in feols(fml2estimate, linbase, fixef = new_dum_names[id_cluster],  : 
  Error in str2lang(value_raw) : <text>:1:2: unexpected input
1: __
     ^
This error was unforeseen by the author of the function feols. If you think your call to the function is legitimate, could you report?

I tried to look at the source code, but it looks a bit too complicated for me.

Thanks, Greg

Sualk3 commented 1 year ago

I have the exact same problem! I am using three-way fixed effects - error occurs for fepois and feols. I thought it might be connected to clustering, but so far nothing worked out. Anyone any idea what to try?

lrberge commented 9 months ago

Hello and thanks for the kind words :-)

The problem is fixed, sorry for the long delay!!

ozgur-ozer commented 8 months ago

Hello, thank you for making this package available. Today, while running a model, I encountered this error. I also tested the code provided by @grlju and received the same error. Thanks.


data(trade)
gravity_pois = fepois(Euros ~ log(dist_km) + Origin + Destination | Product + Year, trade)
collinearity(gravity_pois)

Checking Collinearity: simple with fixed-effects:..OK,  multiple:.............................OK, multiple with cluster.Error in feols(fml2estimate, linbase, fixef = new_dum_names[id_cluster],  : 
  Error in str2lang(value_raw) : <text>:1:2: unexpected input
1: __
     ^
This error was unforeseen by the author of the function feols. If you think your call to the function is legitimate, could you report?```
lrberge commented 8 months ago

Hi, you need to update to the current github version.

Here are the current results:

gravity_pois = fepois(Euros ~ log(dist_km) + Origin + Destination | Product + Year, trade)
collinearity(gravity_pois)
#> Checking Collinearity: 
#> - simple with fixed-effects:..OK
#> - multiple:.............................OK
#> - multiple with fixed-effects.............................OK
#> [1] "No visible collinearity problem. (Doesn't mean there's none!)"

# example with collinear variable
data(base_did)
est = feols(y ~ x1 + treat | id + period, base_did)
collinearity(est)
#> [1] "Variable 'treat' is collinear with the fixed-effects `id`."
ozgur-ozer commented 8 months ago

Thanks! It worked.