linearmodels icon indicating copy to clipboard operation
linearmodels copied to clipboard

ENH: Add Hausman specification test

Open eirki opened this issue 4 years ago • 5 comments

This adds the Hausman specification test, commonly used to choose between a fixed effects model and a random effects model. The function includes the options include_constant, sigmamore, and sigmaless - which mirrors Stata.

I haven't updated the documentation, but will be happy to do so if you want.

The function calculating an alternative covariance can perhaps be removed and replaced with adding a parameter to the covariance estimation.

I realize there is already a wu_hausman method for testing exogeneity in IV models, but I could not find a way to re-use it. Maybe the mathematics could be extracted into a shared function. Also I guess I should make the naming consistent.

Finally, I have written tests, but they do not look at the actual numerical results. Do you generally generate these using Stata and then test against them?

eirki avatar Feb 27 '20 10:02 eirki

Codecov Report

Merging #249 (3bf7264) into main (556bde7) will decrease coverage by 0.05%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #249      +/-   ##
==========================================
- Coverage   99.44%   99.38%   -0.06%     
==========================================
  Files          88       88              
  Lines       15557    15647      +90     
  Branches     1528     1540      +12     
==========================================
+ Hits        15470    15551      +81     
- Misses         38       41       +3     
- Partials       49       55       +6     
Impacted Files Coverage Δ
linearmodels/panel/results.py 97.76% <100.00%> (-1.99%) :arrow_down:
linearmodels/tests/panel/_utility.py 100.00% <100.00%> (ø)
linearmodels/tests/panel/test_results.py 100.00% <100.00%> (ø)
linearmodels/panel/model.py 97.80% <0.00%> (+0.02%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 556bde7...3bf7264. Read the comment docs.

codecov[bot] avatar Feb 27 '20 11:02 codecov[bot]

Should this be a method attached to a RandomEffectsResults class? This would likely simplify the calculations and logic. It also makes sure that we aren't trying to compare invalid models (e.g. a 2-way FE model with a RE model).

bashtage avatar Feb 28 '20 11:02 bashtage

That's a good idea, I've moved it to a method.

I'm trying to generate test data using Stata, but the generated .do-file uses a stats command that I cannot find. Could you point me in the right direction?

eirki avatar Feb 28 '20 13:02 eirki

I will keep a big eye on this issue. Hausman tests for FE and RE deserves a add! Currently I need to calculate by myself based on the estimates of FE and RE.

FeiYao-Edinburgh avatar Mar 25 '20 21:03 FeiYao-Edinburgh

I have now added tests against pre-calculated values from Stata. Let me know if anything needs to be changed/added!

eirki avatar Apr 28 '20 11:04 eirki