DPredict · Guide test 183
Durbin–Wu–Hausman endogeneity tests
Test whether regressors can be treated as exogenous by comparing ordinary and instrumental variable estimates.
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 · Durbin–Wu–Hausman endogeneity 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 F varies across samples when H₀ is true.
- 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
- first-stage fitted values of x from the instruments
- zero when x is exogenous
The verdict
F(1, 197) = 13.02, p < .001
p ≤ α = .050: reject H₀
Only as good as the instruments: with weak or invalid instruments the comparison means little.
- Statistic
- 13.019
- p-value
- 0.0004
Durbin–Wu–Hausman endogeneity test on 200 observations: outcome y, regressor x, instruments z₁ and z₂: F(1, 197) = 13.02, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: specified regressors are exogenous.
Assumptions
Valid excluded instruments, identification and correct structural specification; conventional forms may require homoskedasticity.
Formula
Parameters and notation
Z includes instruments and exogenous controls; v̂ are first-stage residuals, one per suspected endogenous regressor.
Structure of the method
Regress suspected endogenous predictors on valid instruments and exogenous controls, retain first-stage residuals, and add those residuals to the structural regression. A joint restriction on their coefficients yields an endogeneity test under the stated model. Related OLS–IV difference formulations require compatible covariance calculations.
Estimated and nuisance parameters
First-stage coefficients, structural coefficients, residual-inclusion coefficients, and appropriate covariance estimates are fitted. Instrument relevance and exogeneity are assumptions to investigate, not parameters learned merely by running the diagnostic. Multiple suspected endogenous regressors produce multiple residual terms.
Settings and design choices
Prespecify endogenous variables, excluded instruments, included controls, covariance/cluster structure, and the F/Wald variant. Testing different instrument sets until exogeneity is not rejected is an invalid model-selection shortcut. Track which observations survive missing-data handling in both stages.
Fitting and adaptation
Refit first and second stages consistently when the sample or instrument set changes. Use a documented robust residual-inclusion test when the classical homoskedastic assumptions are unsuitable. If machine-learning first stages are substituted, generated-regressor inference and sample splitting require an explicitly justified modern procedure rather than unchanged classical p-values.
Sensitivity and robustness
Weak instruments reduce discrimination, and invalid instruments can cause misleading results in either direction. Structural misspecification or omitted dynamics may resemble endogeneity. Report first-stage evidence and identification assumptions alongside the test; nonrejection does not prove exogeneity, and rejection does not reveal which exclusion restriction is scientifically credible.
How to use and calibrate
Use a joint residual-inclusion F/Wald test or the equivalent OLS–IV Hausman formulation with correct covariance.
Example application
Assess whether an explanatory variable can be treated as exogenous given credible instruments.
Interpretation and pitfalls
Watch out
Invalid or weak instruments undermine interpretation. Failure to reject is not proof of exogeneity.
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 Wu–Hausman row for endogeneity.
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 183, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT183.