sergiocorreia / reghdfe

Linear, IV and GMM Regressions With Any Number of Fixed Effects
http://scorreia.com/software/reghdfe/
MIT License
214 stars 56 forks source link

[BUG] Ensure vcov matrix is symmetric to avoid numerical precision issues #281

Open mcaceresb opened 10 months ago

mcaceresb commented 10 months ago

Bug report

Please complete the following information:

Behavior

Steps to reproduce the problem

Unfortunately I am unable to provide a MWE. This is a numerical precision issue that arises when using reghdfe with administrative individual-level data I cannot share and have not reproduced with basic simulations. However, I can show the output from the HDFE object saved by my regression:

. mata issymmetric(HDFE.solution.V)
  0

. mata max(reldif(lowertriangle(HDFE.solution.V), uppertriangle(HDFE.solution.V)'))
  4.74795e-09

I propose forcing symmetry at the end of reghdfe_solve_ols, which solves it for me; e.g.

sol.V = makesymmetric((lowertriangle(sol.V) + uppertriangle(sol.V)')/2)
mcaceresb commented 10 months ago

PS: Actually I just realized the code I suggested is oddly convoluted. This does the same: sol.v = (sol.v + sol.v')/2