Causal Inference Basics

Instrumental variables

An instrument is a nudge that moves the treatment but touches the outcome through no other door — letting you extract a causal effect even when confounders are unmeasured.

Read these first

On this page 5
  1. Why it exists
  2. How it works
  3. A real example you have seen
  4. Remember this
  5. What to learn next

One lesson, three depths. Pick the one that fits you today — you can switch any time.

Beginner — No maths. Plain English.

An instrumental variable is an outside nudge that changes whether people get the treatment, while having no other way of affecting the outcome.

You want to know whether extra tuition classes improve marks. Keen students attend more classes and study harder at home — keenness contaminates every direct comparison, and you cannot measure keenness. Stuck? Not quite.

Suppose discount vouchers for the classes were posted to randomly chosen households. The voucher nudges some students into classes. And a paper voucher cannot alter anyone's marks by itself — no marks-door except through the classes it encourages. That voucher is an instrument: a lever connected to the treatment, and to nothing else.

Why it exists

Every method so far — stratifying, matching, weighting — requires measuring the confounders. Keenness, ambition, severity: often unmeasurable. That wall stops adjustment-based methods cold.

The instrument goes around the wall. The voucher's randomness is clean — keenness did not decide who got one. So any marks difference between voucher-receivers and non-receivers must have travelled through the one connecting road: attendance. Comparing the marks bump against the attendance bump recovers the per-class effect, with keenness never measured.

How it works

              keenness  (unmeasured!)
              ↙        ↘
        classes    →    marks
        ↑
   voucher  ─ ─ ─ no other path to marks ─ ─ ✗

voucher group: +2 classes on average, +6 marks on average
so 6 extra marks came from 2 extra classes: 3 marks per class

Sharing out the bump is the whole trick. The voucher caused 2 extra classes and 6 extra marks. If classes are the only bridge, those 6 marks came from those 2 classes — 3 marks each.

The price is a pair of promises. The nudge must genuinely move the treatment (relevance — checkable). And it must have no side road to the outcome. That second promise is called exclusion, and it is an argument, not a test. If voucher-households also felt richer and bought books, the road forks and the answer corrupts.

A real example you have seen

Does military service change lifetime earnings? Volunteers differ from non-volunteers in unmeasurable ways. The Vietnam-era draft lottery — birthdays literally drawn from a drum — nudged random men into service. Economists used the lottery as an instrument and settled a decades-old question. Rainfall nudging crop yields, distance-to-college nudging enrolment — the hunt for clean nudges is half of modern empirical economics.

Remember this

  • An instrument moves the treatment, and reaches the outcome through nothing else.
  • The effect is the outcome bump shared across the treatment bump the nudge caused.
  • Relevance is checkable; exclusion is an argument you must win with domain knowledge.

What to learn next

Developer — Code and libraries.

Setup

bash
pip install numpy

Verified with numpy 1.26.4.

Recovering the truth without measuring the confounder

Diligence drives class attendance and marks — and stays out of the dataset for the analysis. The voucher is random. True effect: +3 marks per class.

iv.py
import numpy as np

rng = np.random.default_rng(18)
n = 20_000
diligence = rng.normal(0, 1, n)                  # unobserved: drives classes AND marks
voucher = (rng.random(n) < 0.5).astype(float)    # a randomly posted discount coupon
classes = 2 + 1.5 * diligence + 2.0 * voucher + rng.normal(0, 1, n)
marks = 40 + 3.0 * classes + 8.0 * diligence + rng.normal(0, 5, n)   # truth: +3 per class

ols = np.polyfit(classes, marks, 1)[0]
v = voucher == 1
wald = (marks[v].mean() - marks[~v].mean()) / (classes[v].mean() - classes[~v].mean())
print(f"plain regression:    {ols:+.2f} marks per class")
print(f"instrumented (Wald): {wald:+.2f} marks per class  (truth: +3.00)")
Output
plain regression:    +5.84 marks per class
instrumented (Wald): +2.79 marks per class  (truth: +3.00)

The walkthrough

Plain regression nearly doubles the effect: +5.84. Diligent students take more classes and score higher regardless; linear regression hands attendance the credit for diligence's work. No amount of data repairs this — the bias is structural.

The Wald estimator divides two clean differences. Voucher randomness makes both the marks gap (numerator) and the classes gap (denominator) causal effects of the voucher. Their ratio, +2.79, is the per-class effect — within noise of +3.00, with diligence never entering the code after data generation.

Beyond two groups: two-stage least squares (2SLS). Stage one regresses treatment on the instrument and keeps the predicted treatment — the portion of attendance the voucher explains, scrubbed of diligence. Stage two regresses the outcome on that prediction. With a single binary instrument, 2SLS collapses to the Wald ratio above. Production users reach for linearmodels.iv.IV2SLS (the standard-error bookkeeping is genuinely fiddly by hand).

Watch the denominator. The voucher moved attendance by 2 classes — a strong nudge. Had it moved attendance by 0.05, the ratio would divide by a whisper: tiny denominators amplify noise and bias catastrophically. This is the weak instrument problem, and checking the nudge's strength comes before believing any IV number.

Common mistakes

Falling in love with a weak instrument. A nudge that barely moves treatment produces estimates that are wild and biased toward the plain regression — the worst of both worlds. Convention demands a strong first stage (the classic bar: F-statistic above 10; modern practice asks for far more).

Exclusion violations by side channel. If vouchers made families feel wealthier and buy books, marks moved through a second road, and the ratio silently absorbs it. Exclusion cannot be tested from this data — argue it, and stress-test the argument.

Forgetting whose effect you estimated. The ratio describes compliers — students whose attendance the voucher changed. The always-attenders and never-attenders contributed nothing. If compliers benefit differently from others, the IV answer is theirs, not everyone's.

Instrumenting with something the confounder touches. "Distance to the coaching centre" fails if diligent families chose houses near coaching centres. An instrument correlated with the confounder is no instrument.

Try it yourself

Weaken the voucher to 0.1 * voucher and rerun with several seeds — watch the Wald estimate swing wildly around (and away from) the truth. Then break exclusion: add + 2.0 * voucher directly into marks and see the estimate absorb it. Two failure modes, both invisible from the output alone — which is the entire IV cautionary tale.

What to learn next

Researcher — Mathematics and papers.

Identification and the Wald/2SLS estimators

With outcome $Y$, endogenous treatment $D$, instrument $Z$, and unobserved confounding, the core moment condition is $\operatorname{Cov}(Z, \varepsilon) = 0$ in $Y = \beta D + \varepsilon$, giving

$$ \beta_{IV} = \frac{\operatorname{Cov}(Z, Y)}{\operatorname{Cov}(Z, D)} $$

  • $Z$ — the instrument; $D$ — the treatment; $\varepsilon$ — everything else affecting $Y$.

For binary $Z$, this is the Wald (1940) ratio. 2SLS generalises to multiple instruments/covariates: $\hat{\beta}_{2SLS} = (D'P_Z D)^{-1} D'P_Z Y$ with $P_Z$ the projection onto the instrument space. Requirements: relevance ($\operatorname{Cov}(Z, D) \ne 0$), exogeneity/exclusion ($Z \perp \varepsilon$ — random assignment plus no direct path), and — for the LATE interpretation below — monotonicity.

LATE: what a heterogeneous world lets you have

Imbens and Angrist (1994, Econometrica): with heterogeneous effects, partition units by potential treatment response to the instrument — always-takers, never-takers, compliers, defiers. Under monotonicity (no defiers), IV identifies the local average treatment effect:

$$ \beta_{IV} = \mathbb{E}[Y(1) - Y(0) \mid \text{complier}] $$

Angrist, Imbens and Rubin (1996, JASA) recast IV in potential-outcomes language. The draft-lottery study is Angrist (1990, AER). The complier population is instrument-specific: different instruments for the same treatment estimate different LATEs — not a bug, a fact about what nudges can reveal.

Weak instruments

With first-stage $F \to$ small, 2SLS bias approaches OLS bias (Bound, Jaeger and Baker, 1995, JASA — the quarter-of-birth cautionary reanalysis) and conventional inference fails. Staiger and Stock (1997, Econometrica) formalise weak-instrument asymptotics; the "F > 10" rule descends from Stock and Yogo (2005). Modern standards: Lee, McCrary, Moreira and Porter (2022, AER) show F > 104 is needed for conventional 5% tests to be honest; report Anderson–Rubin confidence sets, which stay valid at any instrument strength.

Connections across this section

  • Fuzzy regression discontinuity is IV with the cutoff indicator as instrument — LATE for cutoff-compliers.
  • Randomised experiments with non-compliance: assignment is the instrument for receipt; intention-to-treat ÷ compliance rate = the complier effect.
  • Mendelian randomisation: genetic variants as instruments for exposures (Davey Smith and Ebrahim, 2003, IJE) — exclusion debates (pleiotropy) in their sharpest form.
  • ML-era IV: deep/kernel instrumental variables (Hartford et al., 2017, ICML; Singh et al., 2019) learn nonlinear first stages; DML's partialling-out extends to IV moment functions with cross-fitting.

What to learn next