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

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

Open
mcaceresb opened this issue Oct 23, 2023 · 1 comment
Assignees

Comments

@mcaceresb
Copy link

Bug report

Please complete the following information:

  • Stata version: 17.0 MP
  • OS: Rocky Linux 9.2 (kernel 5.14.0)
  • which reghdfe gives version 6.12.4 12sep2023

Behavior

  • Expected behavior: Symmetric vcov matrix
  • Actual behavior: The variance-covariance matrix computed in reghdfe_solve_ols may not be symmetric (I get this error under some circumstances with reghdfe_vce_cluster specifically, but I imagine it might be generic). This causes EreturnPost/ereturn pots to give a warning: warning: variance matrix is nonsymmetric or highly singular and instead of the vcov matrix it posts a matrix that is all 0s, resulting in missing SEs. The matrix is approximately symmetric, so it's a numerical precision issue.

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
Copy link
Author

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

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

2 participants