Repository navigation
BUG: Use weights in IV specification tests - #737
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
Sargan, Basmann, Durbin, Wu-Hausman, the Wooldridge tests and the C-statistic were computed from unweighted data when the model was estimated with weights. Use the weighted residuals and the scaled regressors and instruments, and pass the weights to the refits.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
=======================================
Coverage 99.53% 99.53%
=======================================
Files 101 101
Lines 17501 17531 +30
Branches 1436 1440 +4
=======================================
+ Hits 17419 17449 +30
Misses 31 31
Partials 51 51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an IV model is fit with
weights, the specification tests inIVResultsandIVGMMResultswere computed from the unweighted data. Some of them also mixed in the residuals of the weighted fit. On the simulated test data,durbin()andwu_hausman()came out negative (about -2.6) for a weightedIV2SLS.Affected:
sargan(and sobasmann),durbin,wu_hausman,wooldridge_score,wooldridge_regression,wooldridge_overidandc_stat. They now use the weighted residuals and the root-weight scaled regressors and instruments (_wy,_wx,_wz), the same data the estimators use. The refits insidedurbin/wu_hausmanandc_statnow pass the model weights. Unweighted results are unchanged, since the weights are then all 1.Comparisons:
AER::ivreg(y_robust ~ x3 + x4 + x5 + x1 | x3 + x4 + x5 + z1 + z2, weights = weights)onsimulated-data.dta,summary(m, diagnostics = TRUE): Sargan 1.3091639 and Wu-Hausman 0.0126420. On main linearmodels gives 2.8064 and -2.5984. With this change it gives 1.3091639 and 0.0126420.Tests: added
test_weighted_sargan_wu_hausman(the R values above) andtest_weighted_diagnostics_match_rescaled_data(all of the tests above, forIV2SLSwith one and two endogenous variables, andc_statforIVGMM) totest_postestimation.py. Both fail on main and pass with this change.linearmodels/tests/ivandlinearmodels/tests/systempass locally, and black, isort, ruff and flake8 are clean on the changed files.