Learning objectives
By the end of this lecture you should be able to:
- classify sources of endogeneity and show why each makes OLS inconsistent;
- derive the IV and 2SLS estimators, prove consistency and asymptotic normality, and compute correct standard errors;
- diagnose weak instruments and use weak-instrument-robust inference (Anderson–Rubin);
- test overidentifying restrictions and endogeneity, and state what each test can and cannot establish;
- interpret IV estimates with heterogeneous effects as local average treatment effects (LATE).
Motivation
Economic data are generated by choices. People choose their schooling, firms choose their inputs, and governments choose policies in response to conditions. When a regressor is chosen with knowledge of factors that also affect the outcome, the regressor is correlated with the error and OLS no longer recovers the coefficient of interest. Instrumental variables offer a way out: find a source of variation in the regressor that is unrelated to the error. The method is powerful and widely misused. Its validity rests on an untestable exclusion restriction, its precision on instrument strength, and its interpretation on assumptions about who responds to the instrument.
1. Endogeneity
A regressor \(X_j\) in the structural equation \(Y=X'\beta+u\) is endogenous if \(E[X_ju]\neq0\). Here \(\beta\) is the causal or structural parameter, not the projection coefficient. OLS then converges to \(\beta+Q_{XX}^{-1}E[Xu]\neq\beta\). The classic sources are:
- omitted variables (Lecture 3): ability in a wage equation;
- simultaneity (Lecture 6): price and quantity determined jointly by supply and demand;
- measurement error (Lecture 3): observed schooling equals true schooling plus noise;
- selection on gains: those who expect larger returns choose more treatment.
2. The instrumental-variables estimator
Partition \(X=(X_1',X_2')'\) into exogenous regressors \(X_1\) (including the constant) and endogenous \(X_2\). An instrument vector \(Z=(X_1',Z_2')'\), with \(\ell\ge k\) elements, must satisfy:
Instrument conditions. (i) Exogeneity: \(E[Zu]=0\). (ii) Relevance: \(Q_{ZX}=E[ZX']\) has full column rank \(k\). The order condition \(\ell\ge k\) (at least as many excluded instruments as endogenous regressors) is necessary for (ii).
Exogeneity has two parts: the instrument is as good as randomly assigned with respect to \(u\), and it affects \(Y\) only through \(X\) (the exclusion restriction). With \(\ell=k\) (just identification), premultiplying \(Y=X'\beta+u\) by \(Z\) and taking expectations gives \(E[ZY]=E[ZX']\beta\), so
One regressor, one instrument. \(\beta_1=\operatorname{Cov}(Z,Y)/\operatorname{Cov}(Z,X)\): the ratio of the reduced form to the first stage. With a binary instrument this is the Wald estimator
3. Two-stage least squares
With \(\ell>k\) (over-identification), \(E[Z(Y-X'b)]=0\) is \(\ell\) equations in \(k\) unknowns. 2SLS uses the combination that projects \(X\) onto the instruments:
Two-stage interpretation. Stage 1 regresses each column of \(X\) on \(Z\) to get \(\widehat X=P_ZX\). Stage 2 regresses \(y\) on \(\widehat X\). The point estimates coincide, because \(\widehat X'\widehat X=X'P_ZX\) and \(\widehat X'y=X'P_Zy\). The second-stage OLS standard errors are wrong, because they use residuals \(y-\widehat X\widehat\beta\) instead of \(y-X\widehat\beta\). Always use a dedicated IV routine.
Never do "forbidden regressions". Plugging in fitted values from a nonlinear first stage (probit, squared fitted values) does not give a consistent estimator in general. Linear projection of \(X\) onto \(Z\) is what makes the first-stage residuals orthogonal to everything in the second stage.
Theorem 5.1 (Asymptotics of 2SLS). Under i.i.d. sampling, \(E[Zu]=0\), \(\operatorname{rank}(Q_{ZX})=k\), \(Q_{ZZ}\) positive definite, and finite fourth moments,
with \(\Omega=E[ZZ'u^2]\). Under homoskedasticity, \(V=\sigma^2(Q_{XZ}Q_{ZZ}^{-1}Q_{ZX})^{-1}\).
Proof. \(\widehat\beta-\beta=\big[(\tfrac{X'Z}{n})(\tfrac{Z'Z}{n})^{-1}(\tfrac{Z'X}{n})\big]^{-1}(\tfrac{X'Z}{n})(\tfrac{Z'Z}{n})^{-1}\tfrac{Z'u}{n}\). Apply the WLLN to each moment matrix, the CLT to \(n^{-1/2}Z'u\to_dN(0,\Omega)\), and Slutsky. ∎
2SLS is the efficient GMM estimator under homoskedasticity. With heteroskedasticity, two-step GMM with weight matrix \(\widehat\Omega^{-1}\) is more efficient (Lecture 8).
IV is less precise than OLS. In the just-identified single-regressor case under homoskedasticity, \(\operatorname{avar}(\widehat\beta_{IV})=\operatorname{avar}(\widehat\beta_{OLS})/\rho^2_{XZ}\), where \(\rho_{XZ}\) is the correlation between \(X\) and \(Z\). With \(\rho_{XZ}=0.2\), the variance is 25 times larger. IV trades bias for variance.
4. Weak instruments
When the first stage is weak, the asymptotic normal approximation of Theorem 5.1 is poor even in large samples.
- Bias toward OLS. With many weak instruments, 2SLS is biased toward the OLS probability limit. Approximately, \(E[\widehat\beta_{2SLS}]-\beta\approx(\operatorname{plim}\widehat\beta_{OLS}-\beta)/(F+1)\), where \(F\) is the population first-stage \(F\) statistic (Staiger and Stock, 1997).
- Size distortion. Nominal 5% Wald tests can reject far more often than 5%, and confidence intervals undercover.
- Bound et al. (1995) showed that quarter-of-birth estimates of the return to schooling with many weak instruments could be reproduced with randomly generated instruments.
Diagnosis. With one endogenous regressor, report the first-stage \(F\) for the excluded instruments, computed with a variance estimator matching the error structure. Under heteroskedasticity or clustering, use the effective \(F\) of Montiel Olea and Pflueger (2013). The rule of thumb \(F>10\) (Stock and Yogo, 2005) limits the 2SLS bias to about 10% of the OLS bias. Lee, McCrary, Moreira and Porter (2022) show that a 5% \(t\)-test with \(|t|>1.96\) requires a first-stage \(F\) of about 104.7 for correct size, or else adjusted critical values (the tF procedure).
Robust inference. The Anderson–Rubin (AR) test of \(H_0:\beta=\beta_0\) regresses \(Y-X_2'\beta_0\) on \(Z\) and tests the coefficients on the excluded instruments \(Z_2\). Under \(H_0\) this is a valid test however weak the instruments are, because \(Y-X_2'\beta_0=X_1'\gamma+u\) has no endogenous regressor. Inverting the AR test over a grid of \(\beta_0\) yields a confidence set with correct coverage. The set may be unbounded when instruments are weak: that is an honest statement that the data are uninformative. In the just-identified case, AR is efficient among robust tests. With over-identification, the conditional likelihood ratio (CLR) test of Moreira (2003) has better power.
5. Testing
Over-identification (Sargan–Hansen \(J\)). With \(\ell>k\), test whether all moment conditions can hold simultaneously:
Under homoskedasticity, \(J=nR^2\) from regressing the 2SLS residuals on \(Z\) (Sargan). Limitations: \(J\) tests coherence among instruments, not validity. If all instruments are invalid in the same direction, \(J\) has no power. And with heterogeneous effects, different valid instruments identify different LATEs, so \(J\) can reject even when all instruments are valid.
Endogeneity (Durbin–Wu–Hausman). Regress the endogenous regressor on \(Z\), save the first-stage residual \(\widehat v\), and add it to the structural equation (the control function regression). The OLS coefficients on \(X\) in this augmented regression equal 2SLS. A robust \(t\) test on \(\widehat v\) tests \(H_0:E[X_2u]=0\). Failing to reject is not evidence of exogeneity when the instruments are weak, because the test then has little power.
6. Heterogeneous effects and LATE
Let \(D\in\{0,1\}\) be a treatment with potential outcomes \(Y(1),Y(0)\), and \(Z\in\{0,1\}\) an instrument with potential treatments \(D(1),D(0)\). The population divides into compliers (\(D(1)=1,D(0)=0\)), always-takers, never-takers and defiers.
Theorem 5.2 (Imbens and Angrist, 1994). Assume (i) independence: \((Y(1),Y(0),D(1),D(0))\perp Z\); (ii) exclusion: \(Z\) affects \(Y\) only through \(D\); (iii) first stage: \(P(D=1\mid Z=1)\neq P(D=1\mid Z=0)\); (iv) monotonicity: \(D(1)\ge D(0)\), so there are no defiers. Then
Proof. \(Y=Y(0)+D\,(Y(1)-Y(0))\). By independence and exclusion, \(E[Y\mid Z=1]-E[Y\mid Z=0]=E[(D(1)-D(0))(Y(1)-Y(0))]\). Under monotonicity, \(D(1)-D(0)\in\{0,1\}\), so this equals \(P(\text{complier})\cdot E[Y(1)-Y(0)\mid\text{complier}]\). The denominator equals \(P(\text{complier})\). ∎
The Wald/IV estimand is therefore the average effect for compliers, the people whose treatment the instrument changes. It is not, in general, the ATE, nor the effect on the treated. Different instruments move different people and identify different LATEs. External validity has to be argued, not assumed. The characteristics of compliers can be described from the data (Abadie, 2003), which helps that argument.
Worked example
Draft lottery and earnings (Angrist, 1990). The instrument is draft eligibility \(Z\), assigned by lottery number; the treatment is Vietnam-era military service \(D\). Use stylized numbers. Among eligible men, 35% served; among ineligible men, 19% served. Mean annual earnings are $15,300 for eligible and $15,650 for ineligible men. Then
Interpretation: military service reduced annual earnings by about $2,200 for men who served because they were draft-eligible (compliers). The lottery makes independence credible. The exclusion restriction could fail if eligibility changed behavior directly, for example through staying in school to obtain deferments. Always-takers (volunteers) and never-takers (the exempt) do not contribute to the estimate.
Problem set
-
IV with a binary instrument. Show that \(\operatorname{Cov}(Z,Y)/\operatorname{Cov}(Z,X)\) equals the Wald estimator when \(Z\) is binary.
Solution
For binary \(Z\) with \(p=P(Z=1)\), \(\operatorname{Cov}(Z,W)=p(1-p)\big(E[W\mid Z=1]-E[W\mid Z=0]\big)\) for any \(W\). Take the ratio for \(W=Y\) and \(W=X\); the factor \(p(1-p)\) cancels.
-
Measurement error and IV. Two independent noisy measures of schooling are available: \(x_1=x^*+v_1\) and \(x_2=x^*+v_2\). Show that using \(x_2\) as an instrument for \(x_1\) consistently estimates \(\beta\) in \(y=\beta x^*+u\).
Solution
\(y=\beta x_1+(u-\beta v_1)\). Then \(\operatorname{Cov}(x_2,u-\beta v_1)=0\) because \(v_1,v_2,u,x^*\) are mutually independent except through \(x^*\), and \(\operatorname{Cov}(x_2,x_1)=\operatorname{Var}(x^*)\neq0\). So \(\operatorname{plim}\widehat\beta_{IV}=\beta\operatorname{Var}(x^*)/\operatorname{Var}(x^*)=\beta\).
-
2SLS standard errors. Explain precisely why manual two-step 2SLS yields incorrect standard errors, and write the correct homoskedastic variance estimator.
Solution
The second step estimates \(\sigma^2\) from \(y-\widehat X\widehat\beta=u+(X-\widehat X)\beta\), which contains first-stage error. The correct estimator is \(\widehat\sigma^2(X'P_ZX)^{-1}\) with \(\widehat\sigma^2=n^{-1}\sum_i(Y_i-X_i'\widehat\beta)^2\), using the original \(X\).
-
Anderson–Rubin. In a just-identified model with one endogenous regressor, show that the AR confidence set is unbounded whenever the first stage is not significant at the chosen level.
Solution
The AR statistic for \(\beta_0\) is the Wald statistic for \(\pi_Y-\beta_0\pi_X=0\), where \(\pi_Y\) and \(\pi_X\) are the reduced-form and first-stage coefficients. As \(|\beta_0|\to\infty\), it converges to the Wald statistic for \(\pi_X=0\). If that is below the critical value, every sufficiently large \(|\beta_0|\) is accepted, so the set is unbounded.
-
LATE. In the draft example, suppose 2% of men are defiers (they serve only if not eligible). Write the Wald estimand in terms of complier and defier effects, and explain why it need not lie between them.
Solution
The numerator is \(\pi_c\Delta_c-\pi_d\Delta_d\) and the denominator \(\pi_c-\pi_d\), where \(\pi\) and \(\Delta\) are shares and average effects. The ratio is a weighted average with a negative weight on defiers, so it can lie outside \([\Delta_c,\Delta_d]\), even with the opposite sign when effects are heterogeneous.
Computational lab
Goal: see weak-instrument bias, size distortion, and the robustness of Anderson–Rubin.
import numpy as np
rng = np.random.default_rng(5)
def draw(n=500, pi=0.05, rho=0.8, beta=1.0):
z = rng.normal(size=n)
e = rng.multivariate_normal([0, 0], [[1, rho], [rho, 1]], size=n)
x = pi * z + e[:, 1] # first stage
y = beta * x + e[:, 0] # structural equation, Corr(u, v) = rho
b_ols = (x @ y) / (x @ x)
b_iv = (z @ y) / (z @ x)
u = y - b_iv * x
se_iv = np.sqrt((z**2 * u**2).sum()) / abs(z @ x) # robust just-identified IV s.e.
wald_rej = abs((b_iv - beta) / se_iv) > 1.96
r = y - beta * x # AR test of H0: beta = 1
g = (z @ r) / (z @ z); er = r - g * z
ar_rej = abs(g / (np.sqrt((z**2 * er**2).sum()) / (z @ z))) > 1.96
F = ((z @ x)**2 / (z @ z)) / (((x - (z @ x) / (z @ z) * z)**2).sum() / (n - 1))
return b_ols, b_iv, wald_rej, ar_rej, F
for pi in (0.05, 0.15, 0.5):
R = np.array([draw(pi=pi) for _ in range(3000)])
print(f"pi={pi}: median F={np.median(R[:,4]):6.1f} median OLS={np.median(R[:,0]):.2f} "
f"median IV={np.median(R[:,1]):.2f} Wald size={R[:,2].mean():.3f} AR size={R[:,3].mean():.3f}")
Tasks: (i) explain why the median IV estimate moves toward the OLS limit as \(F\) falls; (ii) confirm that AR has correct size for every \(\pi\) while the Wald test does not; (iii) invert AR over a grid of \(\beta_0\) to build a confidence set. In R, ivreg::ivreg() or fixest::feols(y ~ 1 | x ~ z) with fitstat(~ivwald); ivmodel for AR and CLR. In Stata, ivreg2 (with ffirst) and weakiv.
Coding exercises
These exercises use real data and run in Python. Install the packages once with
pip install wooldridge statsmodels linearmodels scipy. The wooldridge package contains the datasets
from Wooldridge's Introductory Econometrics; statsmodels ships U.S. and Danish macroeconomic series.
Try the starter code first, then open the solution. Every printed result below was produced by running the solution code exactly as shown.
Exercise 5.1 — Card (1995): college proximity as an instrument for schooling
Data: card — 3,010 men from the NLS Young Men cohort, earnings in 1976; nearc4 = grew up near a four-year college.
- Estimate OLS of
lwageoneduc,exper,expersq,black,smsa,south,smsa66and regional dummiesreg662–reg669. - Estimate the first stage (
educonnearc4and the controls). Report the robust first-stage \(F\). - Estimate 2SLS with
linearmodels(robust standard errors), treatingexperandexpersqas exogenous as in Card's simplest specification. - Compute the Anderson–Rubin 95% confidence set by inverting the AR test over a grid of \(\beta_0\).
import numpy as np, wooldridge as wd, statsmodels.formula.api as smf
from linearmodels.iv import IV2SLS
df = wd.data("card")
ctrl = "exper + expersq + black + smsa + south + smsa66 + " + " + ".join(f"reg66{i}" for i in range(2, 10))
iv = IV2SLS.from_formula(f"lwage ~ 1 + {ctrl} + [educ ~ nearc4]", data=df).fit(cov_type="robust")
# TODO: OLS, first stage F, AR test: regress (lwage - b0*educ) on nearc4 + controls for a grid of b0
Solution, output and discussion
import numpy as np, wooldridge as wd, statsmodels.formula.api as smf
from linearmodels.iv import IV2SLS
df = wd.data("card")
ctrl = "exper + expersq + black + smsa + south + smsa66 + " + " + ".join(f"reg66{i}" for i in range(2, 10))
ols = smf.ols(f"lwage ~ educ + {ctrl}", data=df).fit(cov_type="HC1")
fs = smf.ols(f"educ ~ nearc4 + {ctrl}", data=df).fit(cov_type="HC1")
iv = IV2SLS.from_formula(f"lwage ~ 1 + {ctrl} + [educ ~ nearc4]", data=df).fit(cov_type="robust")
print(f"OLS return to educ: {ols.params['educ']:.4f} (se {ols.bse['educ']:.4f})")
print(f"first stage: nearc4 -> educ = {fs.params['nearc4']:.4f}, robust F = {fs.tvalues['nearc4']**2:.1f}")
print(f"2SLS return to educ: {iv.params['educ']:.4f} (se {iv.std_errors['educ']:.4f})")
acc = []
for b0 in np.arange(-0.10, 0.60, 0.0025):
df["ytil"] = df["lwage"] - b0 * df["educ"]
t = smf.ols(f"ytil ~ nearc4 + {ctrl}", data=df).fit(cov_type="HC1").tvalues["nearc4"]
if abs(t) < 1.96:
acc.append(b0)
print(f"Anderson-Rubin 95% set: [{min(acc):.3f}, {max(acc):.3f}] vs Wald: [{iv.params['educ']-1.96*iv.std_errors['educ']:.3f}, {iv.params['educ']+1.96*iv.std_errors['educ']:.3f}]")
Output:
OLS return to educ: 0.0747 (se 0.0036)
first stage: nearc4 -> educ = 0.3199, robust F = 14.1
2SLS return to educ: 0.1315 (se 0.0540)
Anderson-Rubin 95% set: [0.030, 0.280] vs Wald: [0.026, 0.237]
The 2SLS return (about 13%) is close to double the OLS estimate (7.5%), with a standard error about fifteen times larger. The first-stage \(F\) is above 10 but well below the ~105 needed for the usual \(t\)-test to have exactly correct size (Lee et al., 2022). The Anderson–Rubin set is therefore wider than the Wald interval and asymmetric, extending further to the right. It is valid regardless of instrument strength. Interpretation: a LATE for men whose schooling responded to living near a college, who plausibly face higher marginal returns. The exclusion restriction is open to challenge — proximity to a college correlates with urban labor markets and family background, which the controls only partly capture.
Exercise 5.2 — Returns to education for married women: over-identification and endogeneity tests
Data: mroz — 753 married women, PSID 1975 (428 in the labor force); fatheduc, motheduc = parents' education.
- For women in the labor force (
inlf == 1), estimatelwageoneduc,exper,expersqby OLS and by 2SLS usingfatheducandmotheducas instruments foreduc. - Report the first-stage \(F\) for the two excluded instruments.
- Test the over-identifying restriction (robust Hansen \(J\) / Wooldridge score test).
- Test the endogeneity of
educwith the control-function regression.
import wooldridge as wd, statsmodels.formula.api as smf
from linearmodels.iv import IV2SLS
df = wd.data("mroz").query("inlf == 1").copy()
iv = IV2SLS.from_formula("lwage ~ 1 + exper + expersq + [educ ~ fatheduc + motheduc]", data=df).fit(cov_type="robust")
# TODO: iv.first_stage, iv.wooldridge_overid, control function: add first-stage residual to OLS
Solution, output and discussion
import wooldridge as wd, statsmodels.formula.api as smf
from linearmodels.iv import IV2SLS
df = wd.data("mroz").query("inlf == 1").copy()
ols = smf.ols("lwage ~ educ + exper + expersq", data=df).fit(cov_type="HC1")
iv = IV2SLS.from_formula("lwage ~ 1 + exper + expersq + [educ ~ fatheduc + motheduc]", data=df).fit(cov_type="robust")
print(f"OLS educ: {ols.params['educ']:.4f} (se {ols.bse['educ']:.4f})")
print(f"2SLS educ: {iv.params['educ']:.4f} (se {iv.std_errors['educ']:.4f})")
fs = smf.ols("educ ~ fatheduc + motheduc + exper + expersq", data=df).fit(cov_type="HC1")
print(f"first-stage robust F (2 instruments): {fs.wald_test('fatheduc = 0, motheduc = 0', scalar=True).statistic/2:.1f}")
o = iv.wooldridge_overid
print(f"over-identification (Wooldridge score): stat = {o.stat:.3f}, p = {o.pval:.3f}")
df["vhat"] = smf.ols("educ ~ fatheduc + motheduc + exper + expersq", data=df).fit().resid
cf = smf.ols("lwage ~ educ + exper + expersq + vhat", data=df).fit(cov_type="HC1")
print(f"control function: educ = {cf.params['educ']:.4f} (equals 2SLS), vhat t = {cf.tvalues['vhat']:.2f}, p = {cf.pvalues['vhat']:.3f}")
Output:
OLS educ: 0.1075 (se 0.0132)
2SLS educ: 0.0614 (se 0.0332)
first-stage robust F (2 instruments): 49.5
over-identification (Wooldridge score): stat = 0.443, p = 0.505
control function: educ = 0.0614 (equals 2SLS), vhat t = 1.60, p = 0.110
The 2SLS estimate is smaller than OLS and much less precise. The instruments are strong, and the over-identification
test does not reject, so the two parental-education instruments give mutually consistent answers. That does not
prove both are valid: if both are correlated with unobserved ability in the same direction, the test has no power. The
control-function coefficient on educ equals 2SLS exactly, and the endogeneity test is not significant at 10% (p ≈ 0.11), so
the data cannot sharply distinguish OLS from 2SLS here. Note also the sample selection: wages are observed only for
women who work, so these regressions condition on participation (Heckman, 1979).
Reading
Required: Angrist and Pischke, Mostly Harmless Econometrics, chapter 4; Hansen, Econometrics, chapter 12. Further: Imbens and Angrist (1994), "Identification and estimation of local average treatment effects", Econometrica 62(2); Angrist (1990), "Lifetime earnings and the Vietnam era draft lottery", AER 80(3); Bound, Jaeger and Baker (1995), JASA 90(430); Staiger and Stock (1997), Econometrica 65(3); Stock and Yogo (2005), in Identification and Inference for Econometric Models; Montiel Olea and Pflueger (2013), JBES 31(3); Andrews, Stock and Sun (2019), "Weak instruments in IV regression: theory and practice", Annual Review of Economics 11; Lee, McCrary, Moreira and Porter (2022), "Valid t-ratio inference for IV", AER 112(10).