DPredict · Guide test 184
Sargan overidentification test
Tests the joint compatibility of excess instruments under the classical instrumental variable assumptions.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Instrumental variables (2SLS / LIML / GMM) — What is the effect of a treatment that is not randomly assigned, using a variable that shifts the treatment but affects the outcome only through it?
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Sargan overidentification test
0 makes x exogenous: OLS and 2SLS estimate the same thing.
Not 0: z₂ violates the exclusion restriction (an invalid instrument).
Your data
Simulated with known truthLeft: how strongly the instruments move x (a flat line means weak instruments). Right: OLS and the instrumented slope; they part when x is endogenous.
If H₀ were true
- The reference: how χ² varies across samples when H₀ is true (χ² approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = < .001).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- 2SLS residuals
- overidentifying restrictions: 2 instruments, 1 endogenous regressor
The verdict
χ²(1) = 12.35, p < .001
p ≤ α = .050: reject H₀
It can only detect instruments that disagree with each other: if both are invalid in the same way, it passes.
- Statistic
- 12.345
- p-value
- 0.0004
Sargan overidentification test on 200 observations: outcome y, regressor x, instruments z₁ and z₂: χ²(1) = 12.35, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: overidentifying instrument restrictions are valid.
Assumptions
Correctly specified, identified linear IV model, valid instruments under H0 and homoskedastic errors for classical Sargan calibration.
Formula
Parameters and notation
R² comes from regressing IV residuals on all instruments; df=L−K, where L is instrument count and K instrumented equation coefficient count, counting included exogenous variables consistently.
Structure of the method
Fit the identified IV model, regress its residuals on the full instrument matrix, and scale the auxiliary centered R-squared by sample size. The overidentification degrees of freedom count excess independent moment conditions relative to estimated structural coefficients. A just-identified system supplies no such restriction to test.
Estimated and nuisance parameters
Structural IV coefficients, residuals, auxiliary projection coefficients, and the homoskedastic error scale are estimated. Instrument count must reflect matrix rank and include exogenous controls consistently on both sides of the degrees-of-freedom calculation.
Settings and design choices
Specify instrument set, control set, weights, observation sample, and homoskedastic Sargan formulation. Many nearly redundant instruments should not be counted as independent restrictions. A heteroskedasticity-robust covariance option elsewhere in a regression summary does not necessarily convert the reported Sargan diagnostic into Hansen's J test.
Fitting and adaptation
Refit the IV model and auxiliary regression after any change to instruments or controls. Assess instrument selection independently or disclose it; deleting instruments until the test passes invalidates a simple final p-value interpretation. If heteroskedasticity is part of the design, choose a correctly weighted robust GMM overidentification procedure instead.
Sensitivity and robustness
Rejection concerns joint instrument/model compatibility and does not identify the invalid instrument. Weak or numerous instruments, finite samples, heteroskedasticity, and structural misspecification can distort interpretation. Nonrejection cannot certify all exclusions, especially when the test has little power or some instruments share the same invalidity.
How to use and calibrate
Use χ²L−K asymptotically; a just-identified model has no overidentifying restriction to test.
Example application
Check joint compatibility of extra instruments with the IV model.
Interpretation and pitfalls
Watch out
Rejection cannot identify which instrument is invalid. The classical test is not heteroskedasticity robust.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Read the Sargan row for overidentification; assumes valid homoskedastic moment covariance and more instruments than endogenous regressors. It does not prove all instruments are valid.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: ivreg
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
n<-200;z1<-rnorm(n);z2<-rnorm(n);u<-rnorm(n);v<-rnorm(n);x<-.8*z1+.5*z2+.6*u+v;y<-1+.7*x+u;d<-data.frame(y,x,z1,z2)
fit<-ivreg::ivreg(y~x|z1+z2,data=d);print(summary(fit,diagnostics=TRUE))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Validated — Executed successfully in the validation environment · needs ivreg
set.seed(2026)
n<-200;z1<-rnorm(n);z2<-rnorm(n);u<-rnorm(n);v<-rnorm(n);x<-.8*z1+.5*z2+.6*u+v;y<-1+.7*x+u;d<-data.frame(y,x,z1,z2)
fit<-ivreg::ivreg(y~x|z1+z2,data=d);print(summary(fit,diagnostics=TRUE))
Output
Call:
ivreg::ivreg(formula = y ~ x | z1 + z2, data = d)
Residuals:
Min 1Q Median 3Q Max
-2.81154 -0.78622 0.05302 0.74224 2.96374
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.14902 0.07769 14.790 < 2e-16 ***
x 0.63258 0.09110 6.944 5.34e-11 ***
Diagnostic tests:
df1 df2 statistic p-value
Weak instruments 2 197 58.611 < 2e-16 ***
Wu-Hausman 1 197 40.828 1.17e-09 ***
Sargan 1 NA 0.055 0.814
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.097 on 198 degrees of freedom
Multiple R-Squared: 0.5863, Adjusted R-squared: 0.5843
Wald test: 48.22 on 1 and 198 DF, p-value: 5.34e-11Sources
- ivmodel — ivmodel · ivmodelAuthor documentation/source reviewed: ivmodel 1.9.1.search.r-project.org
- ivmodelsearch.r-project.org
- ivregsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 184, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT184.