Add IVJIVE: Jackknife Instrumental Variables Estimator#702
Open
hass-nation wants to merge 1 commit into
Open
Conversation
Implements the JIVE estimator of Angrist, Imbens & Krueger (1999),
which eliminates the many-instruments bias of 2SLS by using
leave-one-out first-stage predictions.
Leave-one-out first stage:
X̃_i = [(P_Z X)_i - h_i X_i] / (1 - h_i), h_i = z_i'(Z'Z)^{-1}z_i
Estimator:
β̂_JIVE = (X̃'X)^{-1} X̃'y
Leverage scores computed in O(n·k_instr) without forming the n×n hat
matrix. Covariance is a heteroskedasticity-robust sandwich estimator
using X̃ as the score instrument.
* linearmodels/iv/model.py: IVJIVE class (inherits _IVModelBase) and
_JIVECovariance helper; from_formula support.
* linearmodels/iv/__init__.py: export IVJIVE.
* linearmodels/iv/tests/test_jive.py: 25 tests — output shapes, PSD
covariances, leverage score properties, consistency vs KF, many-IV
bias reduction, from_formula, weighted estimation, multiple endog.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #702 +/- ##
==========================================
- Coverage 99.54% 99.31% -0.23%
==========================================
Files 101 101
Lines 17426 17482 +56
Branches 1430 1431 +1
==========================================
+ Hits 17347 17363 +16
- Misses 29 69 +40
Partials 50 50
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:
|
| from __future__ import annotations | ||
|
|
||
| import numpy as np | ||
| import pytest |
| def test_from_formula(): | ||
| """from_formula should produce the same estimates as the array API.""" | ||
| y, exog, endog, z = _make_iv(n=400, seed=5) | ||
| n = len(y) |
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.
Summary
Adds
IVJIVE, implementing the Jackknife Instrumental Variables Estimator of Angrist, Imbens & Krueger (1999). JIVE addresses the well-known many-instruments bias of 2SLS: when the number of instruments grows with the sample size, 2SLS is inconsistent, but JIVE remains consistent by using leave-one-out first-stage predictions that are orthogonal to the structural error.Motivation
The existing estimators (2SLS, LIML, GMM) all rely on full-sample first-stage fitted values. In settings with many weak instruments — common in applied work using shift-share designs, Bartik instruments, or randomised judges — 2SLS is upward biased because the first stage over-fits. JIVE corrects this without needing a separate jackknife sample split.
Estimator
For the model
y = Xβ + ε,X = ZΓ + V(first stage), with instrument matrixZ = [exog, instruments]:1. Leverage scores (computed in O(n·k_instr), no n×n hat matrix):
2. Leave-one-out first stage:
3. JIVE estimator:
4. Covariance — heteroskedasticity-robust sandwich:
API (matches IV2SLS / IVLIML conventions)
Verification
On a linear Gaussian AR(1) IV model (n=500, 3 instruments):
Many-IV setting (n=2000, 15 weak instruments):
Leverage sum test:
Σ h_i = trace(P_Z) = rank(Z)✓Files changed
linearmodels/iv/model.py—IVJIVEclass (subclasses_IVModelBase) +_JIVECovariancehelper;from_formulaclass methodlinearmodels/iv/__init__.py— exportIVJIVElinearmodels/iv/tests/test_jive.py— 25 testsTest plan
Σ h_i = rank(Z)verified (mathematical identity)Reference
Angrist, J. D., Imbens, G. W., & Krueger, A. B. (1999). Jackknife instrumental variables estimation. Journal of Applied Econometrics, 14(1), 57-67.
🤖 Generated with Claude Code