sergiocorreia / ivreghdfe

Run IV/2SLS with many levels of fixed effects (i.e. ivreg2+reghdfe)
MIT License
77 stars 27 forks source link

assert_msg(): 3498 cols(vars)!=cols(y) #10

Open cacostame opened 5 years ago

cacostame commented 5 years ago

Hi Sergio, Thank you very much for creating ivreghdfe.

To give you some context: I have a dataset containing firms, their establishments and their location. I have more or less 5000 firms and 12000 establishments, during more than 10 years and more than 50 municipalities. Currently, I am trying to run a regression at the headquarter (hq) level; something like

ivreghdfe y (x=z) i.year i.mun_hq if hq==1, absorb(idfirm) robust first

where mun_hq is a fixed effect indicating the municipality in which the firm's headquarter is located.

After running it I am getting the following message

(dropped 553 singleton observations) assert_msg(): 3498 cols(var)!=cols(y) FixedEffects::_partial_out(): - function returned error FixedEffects::partial_out(): - function returned error

: - function returned error r(3498); Do you have an idea of what could be wrong? Thanks a lot Camilo
sergiocorreia commented 5 years ago

Yes. That assert happens if for whatever reason there was a problem loading the data from Stata to Mata. In this case, Mata expected certain number of variables but received a different. Two options

1) Use reghdfes pool(#) option, so that variables get loaded one at a time:

ivreghdfe price weight, a(turn, pool(1))

2) Absorb the year and mun_hq variables. Using your example:

ivreghdfe y (x=z) if hq==1, absorb(idfirm year mun_hq ) robust first

Doing this will not only be much faster, but is also likely to fix the problem (which might be caused by a huge number of regressors, if your mun_hq variable has many categories.

Best, Sergio

cacostame commented 5 years ago

Thank you Sergio for the solution. It fixed the problem.