Skip to content
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

Large Fixed Effect Interaction #77

Closed
rrichmond opened this issue Dec 24, 2020 · 5 comments
Closed

Large Fixed Effect Interaction #77

rrichmond opened this issue Dec 24, 2020 · 5 comments

Comments

@rrichmond
Copy link

Hello,

I'm having issues running regressions with many interactions in the fixed effects. The data I'm using is here: https://www.dropbox.com/s/gpbkn90mzp5vojg/Example.csv?dl=0

Here's an example:

library(data.table)
library(fixest)

sub <- fread("./Example.csv")

mod1 <- fepois(export ~ log_sci + log_distw |
                   iso3_o + iso3_d, sub,
               cluster = ~iso3_o + iso3_d)

mod2 <- fepois(export ~ log_sci + log_distw |
                   i(iso3_o,hs_digit) + i(iso3_d,hs_digit), sub,
               cluster = ~iso3_o + iso3_d)

mod3 <- feols(log_export ~ log_sci + log_distw |
                  i(iso3_o,hs_digit) + i(iso3_d,hs_digit), sub,
              cluster = ~iso3_o + iso3_d)

Which in the case of the last two models returns:

Error in fepois(export ~ log_sci + log_distw | i(iso3_o, hs_digit) + i(iso3_d,  : 
  Problem evaluating the fixed-effects part of the formula:
Error : vector memory exhausted (limit reached?)
> > + + > 
Error : vector memory exhausted (limit reached?)
Error in feols(log_export ~ log_sci + log_distw | i(iso3_o, hs_digit) +  : 
  Problem evaluating the fixed-effects part of the formula:

Equivalent Stata code below for reference:

import delimited using Example.csv

encode iso3_d, generate(iso3_d_n)
encode iso3_o, generate(iso3_o_n)
tostring hs_digit, gen(hs_string)
encode hs_string, generate(hs_n)

ppmlhdfe export log_sci log_distw, absorb(iso3_d_n iso3_o_n) vce(cluster iso3_d_n iso3_o_n)
ppmlhdfe export log_sci log_distw, absorb(iso3_d_n##hs_n iso3_o_n##hs_n) vce(cluster iso3_d_n iso3_o_n)
reghdfe log_export log_sci log_distw, absorb(iso3_d_n##hs_n iso3_o_n##hs_n) vce(cluster iso3_d_n iso3_o_n)

Thanks for your help and for developing this package - It's been needed for a long time!

@lrberge
Copy link
Owner

lrberge commented Dec 25, 2020

Hi, that's perfectly normal! :-)

That's because i() should only be used to interact stuff that is not in the fixed-effects part (it creates a full matrix!). To interact two fixed-effects, you need to use the specific syntax fe1^fe2 or fe1^fe2^fe3 etc (the latter syntax is more general than i() with which you can interact only two values).

Thanks for the issue, you're not the only one having problems with that! ;-)
I understand this is confusing so I'll amend the help of i() to point to the appropriate syntax to interact the FEs and I will make it an error with a message stating the way to go.

@rrichmond
Copy link
Author

Makes sense! Thanks for clarifying.

@Steve-Koller
Copy link

Thank you for creating this excellent package! I am running into a similar issue as rrichmond; below is a MWE.

model1 = feols(y~x1+x2+x3 | fe_1^fe_2, dataframe)

Error in cpp_quf_gnl(x) : vector
Error in feols(y~x1+x2+x3 | : 
  Problem evaluating the fixed-effects part of the formula:
Error in cpp_quf_gnl(x) : vector

By any chance do you have any insight into how to address this error? I haven't been able to find any issues or threads elsewhere dealing with it. Thank you in advance and apologies if it's a silly user error!

@lrberge
Copy link
Owner

lrberge commented Nov 30, 2021

Hi Steve and thanks for the words!

It's another problem, the syntax is legit. Could you show a fully reproducible example? Btw which version do you use?

@Steve-Koller
Copy link

Of course, thank you! I am using version 0.3.1.

After starting to put together a fully reproducible example, I was able to isolate which FE variable was causing the issue— it was a zip code variable of numeric data type. I converted it to a factor and now it works fine. Sorry for posting with such a basic error. Thank you very much for your response, I should be all set now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants