Math for Causal Inference

Day 61. Endogeneity & the Instrumental-Variables Idea

When the regressor is correlated with the error, OLS is biased whatever the sample size. Omitted variables, measurement error and simultaneity are the three classic causes. An instrument moves the regressor but touches the outcome only through it, and the ratio of two covariances recovers the causal effect.

Video coming soon
Learning outcomes
  • ●Diagnose omitted-variable bias, attenuation from measurement error and simultaneity bias, and derive each probability limit.
  • ●State the instrumental-variable conditions (relevance, independence, exclusion) and draw them as a DAG.
  • ●Compute the IV estimate as reduced form divided by first stage.
  • ●Judge candidate instruments in labour, health and industrial-organisation settings.
2-HOUR SESSION PLAN
Theory 25′Warm-up (1–5) 20′Proofs (6–10) 35′Applied (11–15) 25′Python & Lab 15′
Colab notebook (.ipynb) Jump to the simulator

Theory

Endogeneity

In Y=α+βX+εY = \alpha + \beta X + \varepsilon, OLS estimates β\beta consistently only if Cov⁡(X,ε)=0\operatorname{Cov}(X, \varepsilon) = 0. Otherwise XX is endogenous and

plim⁡β^OLS=β+Cov⁡(X,ε)Var⁡(X).\operatorname{plim}\hat\beta_{OLS} = \beta + \frac{\operatorname{Cov}(X, \varepsilon)}{\operatorname{Var}(X)}.

More data do not help: the bias does not shrink with nn.

Three sources

  1. Omitted variables. If ε=γA+u\varepsilon = \gamma A + u with AA unobserved, the bias is γCov⁡(X,A)/Var⁡(X)\gamma\operatorname{Cov}(X, A)/\operatorname{Var}(X) (Day 50).
  2. Measurement error. If we observe X=X∗+eX = X^* + e with classical error ee, OLS is attenuated: plim⁡β^=λβ\operatorname{plim}\hat\beta = \lambda\beta, with reliability λ=Var⁡(X∗)/(Var⁡(X∗)+Var⁡(e))\lambda = \operatorname{Var}(X^*)/(\operatorname{Var}(X^*) + \operatorname{Var}(e)).
  3. Simultaneity. Price and quantity are set jointly by supply and demand; the OLS slope mixes the two curves.

Instruments

A variable ZZ is a valid instrument for XX if

  1. Relevance: Cov⁡(Z,X)≠0\operatorname{Cov}(Z, X) \ne 0;
  2. Independence: ZZ is as good as randomly assigned (no common cause with YY);
  3. Exclusion: ZZ affects YY only through XX.

Conditions 2 and 3 together give Cov⁡(Z,ε)=0\operatorname{Cov}(Z, \varepsilon) = 0. As a DAG: Z→X→YZ \to X \to Y, U→XU \to X, U→YU \to Y, with no arrow from ZZ to YY or from UU to ZZ.

The IV estimand

Take covariances of Y=α+βX+εY = \alpha + \beta X + \varepsilon with ZZ: Cov⁡(Z,Y)=βCov⁡(Z,X)\operatorname{Cov}(Z, Y) = \beta\operatorname{Cov}(Z, X). So

βIV=Cov⁡(Z,Y)Cov⁡(Z,X)=reduced formfirst stage,\beta_{IV} = \frac{\operatorname{Cov}(Z, Y)}{\operatorname{Cov}(Z, X)} = \frac{\text{reduced form}}{\text{first stage}},

where the first stage is the slope of XX on ZZ and the reduced form the slope of YY on ZZ. Intuition: the instrument shifts XX by the first stage and, through XX alone, shifts YY by the reduced form; the ratio is the effect per unit of XX.

What linearity buys

Day 56 showed that the instrument DAG does not identify P(y∣do⁡(x))P(y \mid \operatorname{do}(x)) nonparametrically. With a constant linear effect it identifies β\beta. With heterogeneous effects and a binary treatment it identifies a local effect for compliers (Day 63).

Classic instruments

Quarter of birth for schooling (compulsory-schooling laws); distance to a college; draft lottery numbers for military service; weather for agricultural supply; judge leniency for incarceration; lotteries for school places or health insurance.

Part 1 · Warm-up

Exercise 1 · Name the endogeneity

Which source of endogeneity dominates? (a) Regressing wages on years of schooling without ability. (b) Regressing health on self-reported income. (c) Regressing quantity of coffee sold on its price across months.

Show solution

Step 1. (a) Omitted variable: ability raises both schooling and wages.

Step 2. (b) Measurement error: reported income is noisy (also reverse causality from health to income).

Step 3. (c) Simultaneity: price and quantity are jointly determined by supply and demand.

Exercise 2 · Attenuation

True Var⁡(X∗)=4\operatorname{Var}(X^*) = 4, measurement-error variance 1, true slope 0.5. What does OLS estimate?

Show solution

Step 1. Reliability: λ=4/(4+1)=0.8\lambda = 4/(4 + 1) = 0.8.

Step 2. plim⁡β^=0.8×0.5=0.4\operatorname{plim}\hat\beta = 0.8 \times 0.5 = 0.4.

Answer: 0.4, a 20% underestimate.

Exercise 3 · The covariance ratio

Cov⁡(Z,Y)=0.6\operatorname{Cov}(Z, Y) = 0.6 and Cov⁡(Z,X)=0.3\operatorname{Cov}(Z, X) = 0.3. Compute βIV\beta_{IV}.

Show solution

Step 1. βIV=0.6/0.3=2.0\beta_{IV} = 0.6/0.3 = 2.0.

Exercise 4 · Reduced form over first stage

A regression of YY on ZZ gives 0.06; of XX on ZZ gives 0.4. Compute the IV estimate.

Show solution

Step 1. Both slopes share the denominator Var⁡(Z)\operatorname{Var}(Z), which cancels in the ratio.

Step 2. βIV=0.06/0.4=0.15\beta_{IV} = 0.06/0.4 = 0.15.

Exercise 5 · Check the conditions

For each candidate instrument, which condition is most doubtful? (a) Rainfall as an instrument for farm income in a regression of child health on income. (b) Number of siblings for schooling. (c) A randomised offer of a training voucher for training participation.

Show solution

Step 1. (a) Exclusion: rainfall also affects health directly (malaria, water quality).

Step 2. (b) Independence: family size is chosen and correlated with parental resources.

Step 3. (c) Relevance is testable, independence is guaranteed by randomisation; exclusion is plausible if the offer itself does not change behaviour except through training.

Part 2 · Proofs

Exercise 6 · Omitted-variable bias

Let Y=βX+γA+uY = \beta X + \gamma A + u with uu uncorrelated with (X,A)(X, A). Prove plim⁡β^OLS=β+γCov⁡(X,A)/Var⁡(X)\operatorname{plim}\hat\beta_{OLS} = \beta + \gamma\operatorname{Cov}(X, A)/\operatorname{Var}(X) for the short regression.

Show solution

Step 1. β^OLS→Cov⁡(X,Y)/Var⁡(X)\hat\beta_{OLS} \to \operatorname{Cov}(X, Y)/\operatorname{Var}(X) by the LLN.

Step 2. Cov⁡(X,Y)=βVar⁡(X)+γCov⁡(X,A)+0\operatorname{Cov}(X, Y) = \beta\operatorname{Var}(X) + \gamma\operatorname{Cov}(X, A) + 0.

Step 3. Divide by Var⁡(X)\operatorname{Var}(X). ■\blacksquare

Exercise 7 · Attenuation bias

Let Y=βX∗+uY = \beta X^* + u and X=X∗+eX = X^* + e, with ee independent of (X∗,u)(X^*, u) and mean 0. Prove plim⁡β^=λβ\operatorname{plim}\hat\beta = \lambda\beta.

Show solution

Step 1. Cov⁡(X,Y)=Cov⁡(X∗+e,βX∗+u)=βVar⁡(X∗)\operatorname{Cov}(X, Y) = \operatorname{Cov}(X^* + e, \beta X^* + u) = \beta\operatorname{Var}(X^*).

Step 2. Var⁡(X)=Var⁡(X∗)+Var⁡(e)\operatorname{Var}(X) = \operatorname{Var}(X^*) + \operatorname{Var}(e).

Step 3. Ratio: βVar⁡(X∗)/(Var⁡(X∗)+Var⁡(e))=λβ\beta\operatorname{Var}(X^*)/(\operatorname{Var}(X^*) + \operatorname{Var}(e)) = \lambda\beta. ■\blacksquare

Exercise 8 · Simultaneity bias

Demand Q=−bP+udQ = -bP + u_d and supply Q=sP+usQ = sP + u_s (b,s>0b, s > 0), with independent shocks of variances σd2,σs2\sigma_d^2, \sigma_s^2. Prove the OLS slope of QQ on PP converges to (sσd2−bσs2)/(σd2+σs2)(s\sigma_d^2 - b\sigma_s^2)/(\sigma_d^2 + \sigma_s^2).

Show solution

Step 1. Equilibrium: −bP+ud=sP+us-bP + u_d = sP + u_s, so P=(ud−us)/(b+s)P = (u_d - u_s)/(b + s).

Step 2. Q=sP+us=(sud+bus)/(b+s)Q = sP + u_s = (s u_d + b u_s)/(b + s).

Step 3. Cov⁡(P,Q)=(sσd2−bσs2)/(b+s)2\operatorname{Cov}(P, Q) = (s\sigma_d^2 - b\sigma_s^2)/(b + s)^2 and Var⁡(P)=(σd2+σs2)/(b+s)2\operatorname{Var}(P) = (\sigma_d^2 + \sigma_s^2)/(b + s)^2.

Step 4. Ratio as stated. ■\blacksquare OLS is a variance-weighted mix of the supply slope ss and the demand slope −b-b.

Exercise 9 · IV is consistent

With Y=α+βX+εY = \alpha + \beta X + \varepsilon, Cov⁡(Z,ε)=0\operatorname{Cov}(Z, \varepsilon) = 0 and Cov⁡(Z,X)≠0\operatorname{Cov}(Z, X) \ne 0, prove β^IV=Cov⁡^(Z,Y)/Cov⁡^(Z,X)→β\hat\beta_{IV} = \widehat{\operatorname{Cov}}(Z, Y)/\widehat{\operatorname{Cov}}(Z, X) \to \beta.

Show solution

Step 1. Sample covariances converge to population ones (LLN).

Step 2. Cov⁡(Z,Y)=βCov⁡(Z,X)+Cov⁡(Z,ε)=βCov⁡(Z,X)\operatorname{Cov}(Z, Y) = \beta\operatorname{Cov}(Z, X) + \operatorname{Cov}(Z, \varepsilon) = \beta\operatorname{Cov}(Z, X).

Step 3. By the continuous mapping theorem (denominator non-zero), the ratio converges to β\beta. ■\blacksquare

Exercise 10 · A second measurement as an instrument

Two independent noisy measurements X1=X∗+e1X_1 = X^* + e_1 and X2=X∗+e2X_2 = X^* + e_2 are available. Prove that IV with X1X_1 as the regressor and X2X_2 as the instrument is consistent for β\beta in Y=βX∗+uY = \beta X^* + u.

Show solution

Step 1. Write Y=βX1+(u−βe1)Y = \beta X_1 + (u - \beta e_1): the error includes −βe1-\beta e_1.

Step 2. Cov⁡(X2,u−βe1)=0\operatorname{Cov}(X_2, u - \beta e_1) = 0, since e2,X∗e_2, X^* are independent of uu and e1e_1.

Step 3. Cov⁡(X2,X1)=Var⁡(X∗)≠0\operatorname{Cov}(X_2, X_1) = \operatorname{Var}(X^*) \ne 0.

Step 4. By Exercise 9, IV converges to β\beta. ■\blacksquare

Part 3 · Applied

Exercise 11 · College proximity and the return to schooling

In a stylised version of Card's study, growing up near a four-year college raises schooling by 0.32 years (first stage) and log wages by 0.042 (reduced form). OLS gives 0.075. Compute the IV return and interpret the gap.

Show solution

Step 1. β^IV=0.042/0.32≈0.131\hat\beta_{IV} = 0.042/0.32 \approx 0.131.

Step 2. IV exceeds OLS (13.1% versus 7.5% per year).

Step 3. Possible reasons: measurement error attenuates OLS; the compliers (people whose schooling depends on proximity) may have high returns but face high costs (Day 63).

Answer: about 13% per year. A larger IV than OLS is common in this literature and does not by itself mean ability bias is negative.

Exercise 12 · The demand for fish

At a wholesale fish market, stormy weather at sea reduces the catch (a supply shifter) but does not affect buyers' demand. On stormy days log price is 0.30 higher and log quantity 0.36 lower than on calm days. Estimate the price elasticity of demand. Why not regress quantity on price?

Show solution

Step 1. Weather shifts supply along a fixed demand curve, tracing out its slope.

Step 2. β^IV=−0.36/0.30=−1.2\hat\beta_{IV} = -0.36/0.30 = -1.2.

Step 3. OLS on price mixes supply and demand responses (Exercise 8).

Answer: demand elasticity about −1.2: a 1% price rise lowers the quantity demanded by 1.2%.

Exercise 13 · Self-reported calories

A nutrition survey regresses weight gain on self-reported daily calories. True intake has variance 160,000 kcal², reporting error variance 90,000 kcal². If each extra kcal per day truly adds 0.002 kg per month, what does OLS find? Suggest a fix.

Show solution

Step 1. λ=160,000/(160,000+90,000)=0.64\lambda = 160{,}000/(160{,}000 + 90{,}000) = 0.64.

Step 2. plim⁡β^=0.64×0.002=0.00128\operatorname{plim}\hat\beta = 0.64 \times 0.002 = 0.00128 kg per kcal per month.

Step 3. Fix: a second, independent measure (food diary or doubly labelled water) as an instrument (Exercise 10).

Answer: OLS understates the effect by 36%.

Exercise 14 · Rainfall, income and child health

An analyst instruments household income with rainfall in a regression of child height on income. Suppose rainfall also improves child health directly (cleaner water) by 0.02 sd per unit, and raises income by 0.1 units per unit of rainfall. By how much is the IV estimate biased?

Show solution

Step 1. With a direct effect δ\delta of ZZ on YY: Cov⁡(Z,Y)=βCov⁡(Z,X)+δVar⁡(Z)\operatorname{Cov}(Z, Y) = \beta\operatorname{Cov}(Z, X) + \delta\operatorname{Var}(Z).

Step 2. So βIV=β+δ/π\beta_{IV} = \beta + \delta/\pi, where π\pi is the first-stage slope.

Step 3. Bias =0.02/0.1=0.2= 0.02/0.1 = 0.2 sd per unit of income.

Answer: a small exclusion violation becomes a large bias when the first stage is weak.

Exercise 15 · The Vietnam draft lottery

Draft eligibility was determined by a lottery on birth dates. Evaluate the three IV conditions for estimating the effect of military service on later earnings.

Show solution

Step 1. Relevance: eligible men served more often (testable: the first stage is about 15 points).

Step 2. Independence: the lottery was random.

Step 3. Exclusion: eligibility could affect earnings other than through service, for example by encouraging men to stay in school to obtain deferments.

Answer: relevance and independence hold; exclusion needs argument and checks (e.g. schooling of eligible versus ineligible men).

Verify in Python

import numpy as np

rng = np.random.default_rng(61); n = 1_000_000
slope = lambda y, x: np.cov(x, y)[0, 1] / np.var(x, ddof=1)
iv = lambda y, x, z: np.cov(z, y)[0, 1] / np.cov(z, x)[0, 1]

# Omitted ability, with an instrument (true effect 0.08)
A = rng.normal(size=n); Z = rng.normal(size=n)
S = 0.3 * Z + 2 * A + rng.normal(0, 2, n)
W = 0.08 * S + 0.10 * A + rng.normal(0, .3, n)
print(f"schooling: OLS {slope(W, S):.4f}  IV {iv(W, S, Z):.4f}  (truth 0.08)")

# Measurement error: Exercise 2 and a second measurement as instrument
Xs = rng.normal(0, 2, n); Y = .5 * Xs + rng.normal(size=n)
X1 = Xs + rng.normal(size=n); X2 = Xs + rng.normal(size=n)
print(f"attenuation: OLS {slope(Y, X1):.3f} (0.4)  IV with second measure {iv(Y, X1, X2):.3f} (0.5)")

# Simultaneity: Exercise 8 with b = 1.2, s = 0.8, sd_d = sd_s = 1, and a supply shifter (weather)
b, s = 1.2, .8
ud = rng.normal(size=n); storm = rng.normal(size=n); us = rng.normal(size=n) - 0.5 * storm
P = (ud - us) / (b + s); Q = -b * P + ud
print(f"market: OLS {slope(Q, P):.3f} (formula {(s * 1 - b * 1.25) / (1 + 1.25):.3f})  IV demand slope {iv(Q, P, storm):.3f} (truth -1.2)")

# Exercises 11-14
print("college IV:", round(.042 / .32, 3), " fish elasticity:", -.36 / .30, " calories:", .64 * .002, " rainfall bias:", round(.02 / .1, 3))

Key takeaways

  • Endogeneity (Cov⁡(X,ε)≠0\operatorname{Cov}(X, \varepsilon) \ne 0) comes from omitted variables, measurement error or simultaneity, and does not vanish with more data.
  • An instrument must move the treatment (relevance), be as good as random (independence) and act only through the treatment (exclusion).
  • βIV=Cov⁡(Z,Y)/Cov⁡(Z,X)\beta_{IV} = \operatorname{Cov}(Z, Y)/\operatorname{Cov}(Z, X) = reduced form ÷ first stage; small exclusion violations are magnified by weak first stages.

Simulation Lab: Endogeneity & the IV Idea

Open full screen →

Ability bias and measurement error push OLS off the truth; an instrument's group means recover the return to schooling.

1.522.537.51012.51517.5years of schooling (as measured)log wage
OLS
0.099
IV = RF ÷ FS
0.073
0.114 ÷ 1.55
truth
0.080
OLS slopeIV slope through group meansnear a college (Z = 1)far (Z = 0)

Simulated workers: ability raises both schooling and log wages (true return 0.08). Living near a college (the instrument) raises schooling but has no other route to wages. OLS (orange) absorbs ability bias and measurement-error attenuation; IV (green) uses only the schooling differences created by the instrument: the slope through the two group means (large dots).

Day 60Day 62