Type at least 2 letters. Enter opens the first result, Esc closes.

    Causal Inference · Lesson 6 · Estimating causal effects

    Instrumental variables: noncompliance, 2SLS and the local average treatment effect

    Advanced 85 min 3 interactive figures 5 videos Colab notebook

    Before this lesson: lesson 02 (potential outcomes, ATE, randomization), lesson 04 (backdoor paths, the do-operator), lesson 05 (adjustment). Helpful: projections and least squares (linear algebra 12) and regression standard errors (probability 13). Time: about 85 minutes, plus the notebook.


    Why this matters #

    • A/B tests with noncompliance. You randomize a notification that invites users to a new feature. Many users ignore it, and some find the feature by themselves. The random invitation is an instrument for using the feature. This is the standard way to estimate "the effect of seeing the feature" from an experiment where exposure was not forced.
    • Medicine and epidemiology. In trials, patients do not always take the drug they were assigned. Mendelian randomization uses genetic variants, which are assigned at conception, as instruments for an exposure such as LDL cholesterol.
    • Economics. Lottery numbers, distance to a college, the random assignment of judges or of case workers: many famous estimates of returns to schooling, of the effect of military service and of incarceration are IV estimates.
    • Machine learning. Deep IV (Hartford et al., 2017) and kernel IV (Singh, Sahani and Gretton, 2019) replace the linear stages by neural networks or kernels, for counterfactual prediction with hidden confounding. Demand models use cost shocks as instruments for price.

    1. Predict first #

    2. The picture #

    The problem. In lesson 04 we removed confounding by blocking every backdoor path from TT to YY. Here the only backdoor path is T←U→YT \leftarrow U \rightarrow Y, and UU is not measured. No adjustment set exists. Regression of YY on TT mixes the effect of TT with the effect of UU.

    The idea. Find a variable ZZ with three properties. ZZ moves TT. ZZ is "as good as random": it shares no common cause with YY. And ZZ reaches YY only through TT. In the graph: Z→T→YZ \rightarrow T \rightarrow Y, with U→TU \rightarrow T and U→YU \rightarrow Y, and no other arrow at ZZ.

    Note on notation. In lessons 03–04, ZZ was a set of conditioning variables. In this lesson, ZZ is the instrument.

    Two slopes and a ratio. Compare the units with Z=1Z = 1 and with Z=0Z = 0. Because ZZ is as good as random, the two groups have the same distribution of UU. So every difference between them is caused by ZZ:

    • the first stage γ\gamma: how much ZZ moves TT,   γ=E[T∣Z=1]−E[T∣Z=0]\;\gamma = \mathbb{E}[T \mid Z{=}1] - \mathbb{E}[T \mid Z{=}0];
    • the reduced form ρ\rho: how much ZZ moves YY,   ρ=E[Y∣Z=1]−E[Y∣Z=0]\;\rho = \mathbb{E}[Y \mid Z{=}1] - \mathbb{E}[Y \mid Z{=}0].

    ZZ can move YY only by moving TT. If one unit of TT moves YY by τ\tau, then moving TT by γ\gamma moves YY by τγ\tau\gamma. So ρ=τγ\rho = \tau\gamma, and

    τ=ργ=E[Y∣Z=1]−E[Y∣Z=0]E[T∣Z=1]−E[T∣Z=0].\tau = \frac{\rho}{\gamma} = \frac{\mathbb{E}[Y \mid Z{=}1] - \mathbb{E}[Y \mid Z{=}0]}{\mathbb{E}[T \mid Z{=}1] - \mathbb{E}[T \mid Z{=}0]} .

    This is the Wald estimator (Wald, 1940). In the scatter of YY against TT, it is the slope of the line through the two group means (TˉZ=0,YˉZ=0)(\bar T_{Z=0}, \bar Y_{Z=0}) and (TˉZ=1,YˉZ=1)(\bar T_{Z=1}, \bar Y_{Z=1}).

    Interactive figure: loading…

    Move the sliders and watch three lines. Dots are units: blue for Z=1Z = 1, orange for Z=0Z = 0. The magenta OLS line is tilted by the hidden confounder UU (dashed violet node). The dark IV line goes through the two big dots, the group means; its slope is the Wald estimate. The dashed aqua line has the true slope τ=0.5\tau = 0.5. Set confounding to 0: OLS becomes right. Choose weak instrument: the big dots almost touch and the IV line jumps with each new sample. Choose exclusion broken: the IV line is wrong by β/γ\beta/\gamma, and nothing in the picture warns you.

    Quick check

    In a randomized encouragement study, the encouraged group has mean treatment 0.550.55 and mean outcome 14.014.0. The other group has mean treatment 0.150.15 and mean outcome 12.012.0. What is the Wald estimate of the effect of TT on YY?

    3. Definitions and main results #

    3.1 The three IV conditions #

    We use potential outcomes (lesson 02). Write T(z)T(z) for the treatment a unit would take if ZZ were set to zz, and Y(t,z)Y(t, z) for the outcome if TT were set to tt and ZZ to zz. A variable ZZ is an instrument for the effect of TT on YY if:

    Condition In words In symbols In the graph Testable?
    Relevance ZZ moves TT Cov⁡(Z,T)≠0\operatorname{Cov}(Z, T) \ne 0 arrow Z→TZ \to T yes: first stage
    Exclusion ZZ changes YY only through TT Y(t,z)=Y(t)Y(t, z) = Y(t) for all t,zt, z no arrow Z→YZ \to Y, no path Z→M→YZ \to M \to Y that avoids TT no
    Independence (exogeneity) ZZ is as good as random Z⊥ ⁣ ⁣ ⁣⊥(Y(t),T(z))Z \perp\!\!\!\perp \big(Y(t), T(z)\big) for all t,zt, z no common cause of ZZ and YY no (only partly, see below)

    Randomization makes independence true by design (the coin does not look at the units). It does not make exclusion true: a random letter can still change behavior by itself. Exclusion is an assumption about the world, and it is where most IV studies are attacked.

    3.2 Linear model: the IV formula #

    Theorem (IV in a linear model). Let Y=α+τT+εY = \alpha + \tau T + \varepsilon, where ε\varepsilon collects everything else that affects YY (the hidden UU and noise). Assume relevance, Cov⁡(Z,T)≠0\operatorname{Cov}(Z, T) \ne 0, and Cov⁡(Z,ε)=0\operatorname{Cov}(Z, \varepsilon) = 0 (exclusion and independence: ZZ is not in ε\varepsilon and is not related to anything in ε\varepsilon). Then

    τ=Cov⁡(Z,Y)Cov⁡(Z,T).\tau = \frac{\operatorname{Cov}(Z, Y)}{\operatorname{Cov}(Z, T)} .

    Proof.

    1. Take the covariance of both sides of Y=α+τT+εY = \alpha + \tau T + \varepsilon with ZZ. Constants have zero covariance, so Cov⁡(Z,Y)=τCov⁡(Z,T)+Cov⁡(Z,ε)\operatorname{Cov}(Z, Y) = \tau \operatorname{Cov}(Z, T) + \operatorname{Cov}(Z, \varepsilon).
    2. Exclusion and independence give Cov⁡(Z,ε)=0\operatorname{Cov}(Z, \varepsilon) = 0, so Cov⁡(Z,Y)=τCov⁡(Z,T)\operatorname{Cov}(Z, Y) = \tau \operatorname{Cov}(Z, T).
    3. Relevance lets us divide by Cov⁡(Z,T)\operatorname{Cov}(Z, T). ■\blacksquare

    Compare OLS. The OLS slope is Cov⁡(T,Y)/Var⁡(T)=τ+Cov⁡(T,ε)/Var⁡(T)\operatorname{Cov}(T, Y)/\operatorname{Var}(T) = \tau + \operatorname{Cov}(T, \varepsilon)/\operatorname{Var}(T). The second term is the omitted-variable bias: TT is correlated with the hidden part ε\varepsilon. IV replaces "the variation of TT" by "the variation of TT that comes from ZZ", which is not related to ε\varepsilon.

    Binary ZZ gives the Wald estimator. If Z∈{0,1}Z \in \{0, 1\} with P(Z=1)=pP(Z{=}1) = p, then for any variable VV, Cov⁡(Z,V)=p(1−p)(E[V∣Z=1]−E[V∣Z=0])\operatorname{Cov}(Z, V) = p(1 - p)\big(\mathbb{E}[V \mid Z{=}1] - \mathbb{E}[V \mid Z{=}0]\big). The factor p(1−p)p(1 - p) cancels in the ratio, and Cov⁡(Z,Y)/Cov⁡(Z,T)=ρ/γ\operatorname{Cov}(Z, Y)/\operatorname{Cov}(Z, T) = \rho/\gamma.

    Quick check

    A study uses a lottery as an instrument for winning a housing voucher (TT) and measures later income (YY). Critics point out that lottery winners also receive a visit from a job counsellor, which losers do not get. Which IV condition is in danger?

    3.3 Noncompliance, compliance types and the LATE #

    Now let ZZ be a randomized encouragement (an invitation, an assignment) and TT the treatment actually taken. Both are binary. Each unit has two potential treatments T(0)T(0) and T(1)T(1). They define four compliance types:

    Type T(0)T(0) T(1)T(1) Behavior
    complier 0 1 takes the treatment if and only if encouraged
    always-taker 1 1 takes it in any case
    never-taker 0 0 never takes it
    defier 1 0 does the opposite of the encouragement

    We never see a unit's type: we see only one of T(0),T(1)T(0), T(1). A treated unit with Z=1Z = 1 can be a complier or an always-taker.

    The intention-to-treat (ITT) effect is the effect of the encouragement on YY: ITT=E[Y∣Z=1]−E[Y∣Z=0]\mathrm{ITT} = \mathbb{E}[Y \mid Z{=}1] - \mathbb{E}[Y \mid Z{=}0]. It is the reduced form ρ\rho. It is what a randomized experiment always identifies, whatever people do with the encouragement.

    Monotonicity means there are no defiers: Ti(1)≥Ti(0)T_i(1) \ge T_i(0) for every unit ii. The encouragement never pushes anyone away from the treatment.

    The local average treatment effect is the average effect for the compliers: τLATE=E[Y(1)−Y(0)∣complier]\tau_{\mathrm{LATE}} = \mathbb{E}[Y(1) - Y(0) \mid \text{complier}].

    Theorem (Imbens and Angrist, 1994; Angrist, Imbens and Rubin, 1996). Assume independence, exclusion, relevance (γ≠0\gamma \ne 0) and monotonicity. Then

    E[Y∣Z=1]−E[Y∣Z=0]E[T∣Z=1]−E[T∣Z=0]=E[Y(1)−Y(0)∣complier].\frac{\mathbb{E}[Y \mid Z{=}1] - \mathbb{E}[Y \mid Z{=}0]}{\mathbb{E}[T \mid Z{=}1] - \mathbb{E}[T \mid Z{=}0]} = \mathbb{E}[Y(1) - Y(0) \mid \text{complier}] .

    Proof. Write πC,πA,πN,πD\pi_C, \pi_A, \pi_N, \pi_D for the shares of the four types.

    1. Exclusion: Y(t,z)=Y(t)Y(t, z) = Y(t). So the outcome of a unit with encouragement zz is Y(T(z))Y(T(z)).
    2. Independence: ZZ is independent of (Y(0),Y(1),T(0),T(1))(Y(0), Y(1), T(0), T(1)). With consistency, E[Y∣Z=z]=E[Y(T(z))∣Z=z]=E[Y(T(z))]\mathbb{E}[Y \mid Z{=}z] = \mathbb{E}[Y(T(z)) \mid Z{=}z] = \mathbb{E}[Y(T(z))]. So ITT=E[Y(T(1))−Y(T(0))]\mathrm{ITT} = \mathbb{E}\big[Y(T(1)) - Y(T(0))\big].
    3. Split this average by type. For always-takers T(1)=T(0)=1T(1) = T(0) = 1, so the difference is Y(1)−Y(1)=0Y(1) - Y(1) = 0. For never-takers it is Y(0)−Y(0)=0Y(0) - Y(0) = 0. For compliers it is Y(1)−Y(0)Y(1) - Y(0). For defiers it is Y(0)−Y(1)Y(0) - Y(1). Hence ITT=πC E[Y(1)−Y(0)∣C]−πD E[Y(1)−Y(0)∣D]\mathrm{ITT} = \pi_C\, \mathbb{E}[Y(1) - Y(0) \mid C] - \pi_D\, \mathbb{E}[Y(1) - Y(0) \mid D].
    4. In the same way, γ=E[T(1)−T(0)]=πC−πD\gamma = \mathbb{E}[T(1) - T(0)] = \pi_C - \pi_D.
    5. Monotonicity: πD=0\pi_D = 0. So ITT=πC τLATE\mathrm{ITT} = \pi_C\, \tau_{\mathrm{LATE}} and γ=πC\gamma = \pi_C.
    6. Relevance: πC=γ≠0\pi_C = \gamma \ne 0, so we can divide: ITT/γ=τLATE\mathrm{ITT}/\gamma = \tau_{\mathrm{LATE}}. ■\blacksquare

    Read step 3 again: always-takers and never-takers drop out because of exclusion. The encouragement does not change their treatment, so under exclusion it does not change their outcome. The only people who carry the effect of ZZ are the compliers. Step 4 also gives a useful fact: the first stage is the share of compliers.

    Interactive figure: loading…

    Change the shares and switch the types on and off. Each circle is a person; filled means treated. Aqua compliers follow the coin, blue always-takers are always filled, orange never-takers are never filled, and magenta defiers do the opposite. Set the types to hidden to see what the data shows. With no defiers the Wald ratio equals the compliers' effect, whatever the always-takers' effect is. Add 10% defiers and give them a different effect: the ratio leaves the LATE.

    Quick check

    In an experiment, 30% of the encouraged users take the treatment and no one else does. The Wald estimate is 0.80.8. Which statement is correct?

    3.4 Two-stage least squares (2SLS) #

    Real studies have covariates and sometimes several instruments. Two-stage least squares handles this. In this subsection only, bold letters are matrices:

    • y\mathbf y is the nn-vector of outcomes;
    • X\mathbf X is the n×kn \times k matrix of regressors: a column of ones, the treatment TT, and pre-treatment covariates WW;
    • Z\mathbf Z is the n×ℓn \times \ell matrix of instruments: a column of ones, the instruments, and the same covariates WW (each covariate is its own instrument). We need ℓ≥k\ell \ge k.

    The model is y=Xβ+ε\mathbf y = \mathbf X \beta + \varepsilon with E[Z⊤ε]=0\mathbb{E}[\mathbf Z^\top \varepsilon] = 0. Let PZ=Z(Z⊤Z)−1Z⊤P_{\mathbf Z} = \mathbf Z(\mathbf Z^\top \mathbf Z)^{-1}\mathbf Z^\top, the projection onto the column space of Z\mathbf Z (linear algebra 12).

    1. First stage. Regress each column of X\mathbf X on Z\mathbf Z: X^=PZX\hat{\mathbf X} = P_{\mathbf Z}\mathbf X. For the columns that are already in Z\mathbf Z (ones, WW) nothing changes. The column TT is replaced by its fitted value T^\hat T: the part of TT explained by the instruments.
    2. Second stage. Regress y\mathbf y on X^\hat{\mathbf X}. Because PZP_{\mathbf Z} is symmetric and PZ2=PZP_{\mathbf Z}^2 = P_{\mathbf Z},
    β^2SLS=(X^⊤X^)−1X^⊤y=(X⊤PZX)−1X⊤PZy.\hat\beta_{\mathrm{2SLS}} = (\hat{\mathbf X}^\top \hat{\mathbf X})^{-1}\hat{\mathbf X}^\top \mathbf y = (\mathbf X^\top P_{\mathbf Z}\mathbf X)^{-1}\mathbf X^\top P_{\mathbf Z}\mathbf y .

    With exactly as many instruments as regressors (ℓ=k\ell = k, just identified), Z⊤X\mathbf Z^\top \mathbf X is square and the formula simplifies to β^=(Z⊤X)−1Z⊤y\hat\beta = (\mathbf Z^\top \mathbf X)^{-1}\mathbf Z^\top \mathbf y. With one instrument and no covariates this is the sample version of Cov⁡(Z,Y)/Cov⁡(Z,T)\operatorname{Cov}(Z, Y)/\operatorname{Cov}(Z, T).

    Why the just-identified formula simplifies

    If Z⊤X\mathbf Z^\top \mathbf X is square and invertible, then (X⊤Z(Z⊤Z)−1Z⊤X)−1=(Z⊤X)−1(Z⊤Z)(X⊤Z)−1(\mathbf X^\top \mathbf Z (\mathbf Z^\top \mathbf Z)^{-1} \mathbf Z^\top \mathbf X)^{-1} = (\mathbf Z^\top \mathbf X)^{-1} (\mathbf Z^\top \mathbf Z) (\mathbf X^\top \mathbf Z)^{-1}. Multiply by X⊤Z(Z⊤Z)−1Z⊤y\mathbf X^\top \mathbf Z (\mathbf Z^\top \mathbf Z)^{-1}\mathbf Z^\top \mathbf y: the middle factors (X⊤Z)−1X⊤Z(\mathbf X^\top \mathbf Z)^{-1}\mathbf X^\top \mathbf Z and (Z⊤Z)(Z⊤Z)−1(\mathbf Z^\top \mathbf Z)(\mathbf Z^\top \mathbf Z)^{-1} are identities, which leaves (Z⊤X)−1Z⊤y(\mathbf Z^\top \mathbf X)^{-1}\mathbf Z^\top \mathbf y. ■\blacksquare

    Standard errors. Under homoskedasticity, Var⁡^(β^)=σ^2(X⊤PZX)−1\widehat{\operatorname{Var}}(\hat\beta) = \hat\sigma^2 (\mathbf X^\top P_{\mathbf Z}\mathbf X)^{-1}, with σ^2=1n−k∑i(yi−xi⊤β^)2\hat\sigma^2 = \frac{1}{n - k}\sum_i (y_i - x_i^\top \hat\beta)^2. The residuals use the real regressors xix_i (with the real TiT_i). The robust (sandwich) version is (X^⊤X^)−1(∑iu^i2 x^ix^i⊤)(X^⊤X^)−1(\hat{\mathbf X}^\top \hat{\mathbf X})^{-1}\big(\sum_i \hat u_i^2\, \hat x_i \hat x_i^\top\big)(\hat{\mathbf X}^\top \hat{\mathbf X})^{-1} with u^i=yi−xi⊤β^\hat u_i = y_i - x_i^\top \hat\beta and x^i\hat x_i row ii of X^\hat{\mathbf X}.

    Why the two stages by hand give wrong standard errors. If you run the second stage with ordinary OLS software, it computes residuals yi−x^i⊤β^y_i - \hat x_i^\top\hat\beta, with the fitted T^i\hat T_i. These are not the model's errors: they contain the extra term (Ti−T^i)τ^(T_i - \hat T_i)\hat\tau. So σ^2\hat\sigma^2 is wrong, and the standard error can be too large or too small. The point estimate is right; the uncertainty is not. Use a 2SLS routine, or compute σ^2\hat\sigma^2 with the real TT.

    Covariates go in both stages. A covariate WW in the second stage must also be in the first stage (it is a column of Z\mathbf Z). Otherwise the first-stage residual is correlated with WW and the estimate is biased. Covariates must be pre-treatment: adjusting for a variable caused by TT or by ZZ breaks the design (lesson 04).

    The forbidden regression. Suppose TT is binary and you fit the first stage with a logistic (or probit) model, then plug its fitted probabilities into an OLS second stage. This is not 2SLS. 2SLS works because the OLS first-stage residual is uncorrelated with the fitted values and the covariates by construction. A nonlinear first stage loses this property, and the estimate can be inconsistent when the nonlinear model is wrong (Angrist and Pischke call this the "forbidden regression"). If you want a nonlinear first stage, use its fitted values as an instrument for TT, not as a regressor.

    More instruments than treatments. With ℓ>k\ell > k the model is over-identified. 2SLS combines the instruments in the best linear way. A test of over-identifying restrictions (Sargan, Hansen) checks whether the instruments give the same answer. It needs at least one valid instrument to mean anything, and with heterogeneous effects two valid instruments can give different LATEs, so a rejection does not always mean that an instrument is invalid.

    Quick check

    An analyst fits the first stage, saves T^\hat T, and then runs LinearRegression().fit(X=[T_hat, W], y). What is right and what is wrong?

    3.5 Weak instruments #

    An instrument is weak when it moves TT only a little. Then the first stage γ^\hat\gamma is close to 0, and in the ratio ρ^/γ^\hat\rho/\hat\gamma small noise in the denominator gives large changes in the estimate. Three things go wrong.

    1. The estimate is biased towards OLS. In a finite sample, γ^\hat\gamma contains some noise from the first-stage error, which is correlated with the confounding. With a weak instrument this noise is a large part of T^\hat T, and T^\hat T starts to behave like TT itself. At the limit γ=0\gamma = 0, the 2SLS estimate is centered near the OLS value.
    2. The distribution has heavy tails. With one instrument, the 2SLS estimator has no finite mean. Single estimates can be far away from the truth. Report medians in simulations.
    3. The usual confidence interval is too short. The usual 95% interval covers the truth less often than 95% of the time.

    The first-stage FF statistic measures strength. With one instrument it is the square of the tt-statistic of ZZ in the first-stage regression. Staiger and Stock (1997) proposed the rule of thumb F>10F > 10; Stock and Yogo (2005) gave tables of critical values. Always report the first stage.

    Interactive figure: loading…

    Choose a strength and press Run 500 samples. Each run simulates 500 data sets of 200 units with a true effect of 1 (aqua line) and strong confounding. The magenta histogram is OLS: precise and wrong (dashed line: its population value). The dark histogram is IV. With F≈100F \approx 100 it is centered on the truth. Lower the strength: the IV histogram widens, its center moves towards OLS, and the share of 95% intervals that contain the truth drops (about 70% at F≈1F \approx 1).

    Is F>10F > 10 enough?

    The rule F>10F > 10 was designed to keep the bias of 2SLS small relative to OLS. It does not make the usual tt-test reliable. Lee, McCrary, Moreira and Porter (2022) showed that, with one instrument, a usual 5% tt-test has a true size of at most 5% only if the first-stage FF is above about 104.7. For smaller FF their "tF" procedure replaces 1.96 by a larger critical value that depends on FF. The Anderson–Rubin test is valid at any instrument strength in the just-identified case: it tests τ=τ0\tau = \tau_0 by regressing Y−τ0TY - \tau_0 T on ZZ. With heteroskedastic errors, use a robust first-stage FF (or the effective FF of Montiel Olea and Pflueger, 2013). The widget shows the problem: at F≈10F \approx 10 the 2SLS median is almost exactly 1, but coverage is only about 91%.

    A famous warning is Bound, Jaeger and Baker (1995). Angrist and Krueger (1991) used quarter of birth as an instrument for years of schooling, with many interactions. Bound, Jaeger and Baker replaced the real quarter of birth by randomly generated quarters and obtained estimates close to the original ones, with standard errors that looked small. Many weak instruments can produce a confident answer from noise.

    Quick check

    Your first-stage FF is 3. What should you expect from the 2SLS estimate?

    3.6 Classic instruments and how they fail #

    Instrument ZZ Treatment TT Outcome YY Main threat
    draft lottery number (Angrist, 1990) military service later earnings exclusion: men with low numbers may stay in school to avoid the draft
    distance to a college (Card, 1995) years of schooling wages independence: families and local labour markets near colleges differ
    quarter of birth (Angrist and Krueger, 1991) schooling (through school-leaving laws) wages weak instrument; season of birth may affect health
    randomly assigned judge's leniency (e.g. Kling, 2006) incarceration or detention later employment, crime exclusion: judges differ in more than one decision; monotonicity can fail
    genetic variant (Mendelian randomization) an exposure, e.g. LDL cholesterol heart disease pleiotropy: the gene affects the outcome by other paths (exclusion); population structure (independence)
    randomized notification in an A/B test using the feature retention exclusion: the notification itself reminds users of the app

    The pattern: randomization or "nature" gives independence; the argument for exclusion must come from knowledge of the mechanism.

    3.7 What IV estimates, and what it does not #

    • The Wald ratio estimates the effect for compliers. Compliers are defined by the instrument: the people a draft lottery moves are not the people a college nearby moves. Two valid instruments can give two different, correct answers when effects differ between people.
    • The LATE equals the ATE only in special cases, for example when the effect is the same for everyone, or when everyone is a complier.
    • We cannot list the compliers. But we can estimate how many there are (πC=γ\pi_C = \gamma) and their average pre-treatment covariates (Abadie, 2003). Comparing them with the whole population tells the reader whom the estimate describes.
    • In a linear model with a constant effect, IV estimates the effect. The constant-effect assumption is what makes "the" possible; state it when you use it.

    Answers to section 1. (1) More than 0.12. The ITT effect of the notification is 0.51−0.39=0.120.51 - 0.39 = 0.12, and the first stage is 0.70−0.10=0.600.70 - 0.10 = 0.60, so the Wald estimate is 0.12/0.60=0.200.12/0.60 = 0.20: the effect of using the feature for compliers. Section 4 works this out. (2) No. TT is a collider on the path Z→T←U→YZ \to T \leftarrow U \to Y. Conditioning on TT opens this path (lesson 03), so the coefficient of ZZ is not 0 even when exclusion holds. Exclusion cannot be tested this way.

    4. Worked example #

    The setting (simulated). An app randomizes a notification ZZ about a new feature among 2,000 users, 1,000 per group. T=1T = 1 if the user uses the feature in the next week; Y=1Y = 1 if the user is still active four weeks later. The data:

    nn used the feature (T=1T = 1) retained (Y=1Y = 1)
    notified (Z=1Z = 1) 1,000 700 510
    not notified (Z=0Z = 0) 1,000 100 390

    Step 1: intention to treat. ITT=510/1000−390/1000=0.51−0.39=0.12\mathrm{ITT} = 510/1000 - 390/1000 = 0.51 - 0.39 = 0.12. Sending the notification raises retention by 12 percentage points. This number needs no assumption beyond the randomization.

    Step 2: first stage. γ=700/1000−100/1000=0.70−0.10=0.60\gamma = 700/1000 - 100/1000 = 0.70 - 0.10 = 0.60. So 60% of users are compliers. The 10% who use the feature without the notification are always-takers; the remaining 1−0.70=30%1 - 0.70 = 30\% are never-takers.

    Step 3: Wald ratio. τ^LATE=0.12/0.60=0.20\hat\tau_{\mathrm{LATE}} = 0.12/0.60 = 0.20. Assuming exclusion (the notification changes retention only through feature use) and monotonicity (the notification makes no one stop using the feature), using the feature raises retention by 20 points for compliers.

    Step 4: what the truth was. This is a simulation, so we know each type's potential outcomes (retention probabilities):

    Type share E[Y(0)]\mathbb{E}[Y(0)] E[Y(1)]\mathbb{E}[Y(1)] effect
    always-takers 0.10 0.50 0.90 0.40
    compliers 0.60 0.40 0.60 0.20
    never-takers 0.30 0.20 0.20 0.00

    Check the observed means. In the Z=1Z = 1 group, always-takers and compliers are treated: 0.10⋅0.90+0.60⋅0.60+0.30⋅0.20=0.09+0.36+0.06=0.510.10 \cdot 0.90 + 0.60 \cdot 0.60 + 0.30 \cdot 0.20 = 0.09 + 0.36 + 0.06 = 0.51 ✓. In the Z=0Z = 0 group, only always-takers are treated: 0.10⋅0.90+0.60⋅0.40+0.30⋅0.20=0.09+0.24+0.06=0.390.10 \cdot 0.90 + 0.60 \cdot 0.40 + 0.30 \cdot 0.20 = 0.09 + 0.24 + 0.06 = 0.39 ✓. The always-takers and never-takers add the same amount (0.09+0.060.09 + 0.06) to both groups, and cancel in the ITT. That is step 3 of the proof, with numbers.

    The true LATE is 0.200.20 ✓. The ATE is 0.10⋅0.40+0.60⋅0.20+0.30⋅0=0.160.10 \cdot 0.40 + 0.60 \cdot 0.20 + 0.30 \cdot 0 = 0.16. The IV estimate is right for compliers and wrong as an ATE.

    Step 5: the naive "as-treated" comparison. Compare users who used the feature with users who did not, ignoring ZZ. Count in shares of the whole population (Z=1Z = 1 for half of each type). The treated are all always-takers (share 0.10) and the compliers with Z=1Z = 1 (share 0.30). The untreated are all never-takers (share 0.30) and the compliers with Z=0Z = 0 (share 0.30).

    E[Y∣T=1]=0.10⋅0.90+0.30⋅0.600.40=0.270.40=0.675,\mathbb{E}[Y \mid T{=}1] = \frac{0.10 \cdot 0.90 + 0.30 \cdot 0.60}{0.40} = \frac{0.27}{0.40} = 0.675,
    E[Y∣T=0]=0.30⋅0.20+0.30⋅0.400.60=0.180.60=0.30.\mathbb{E}[Y \mid T{=}0] = \frac{0.30 \cdot 0.20 + 0.30 \cdot 0.40}{0.60} = \frac{0.18}{0.60} = 0.30 .

    The as-treated difference is 0.675−0.30=0.3750.675 - 0.30 = 0.375, almost twice the LATE. Engaged users (always-takers) use the feature and stay; disengaged users (never-takers) do neither. That is confounding by engagement, the hidden UU of this example.

    Step 6: the linear model of the track. Let Z,U∼N(0,1)Z, U \sim \mathcal N(0, 1), T=0.8Z+U+εTT = 0.8Z + U + \varepsilon_T, Y=0.5T+2U+εYY = 0.5T + 2U + \varepsilon_Y, all noises independent with variance 1. Then Var⁡(T)=0.64+1+1=2.64\operatorname{Var}(T) = 0.64 + 1 + 1 = 2.64 and Cov⁡(T,ε)=Cov⁡(T,2U+εY)=2\operatorname{Cov}(T, \varepsilon) = \operatorname{Cov}(T, 2U + \varepsilon_Y) = 2.

    • OLS slope: 0.5+2/2.64=0.5+0.758=1.2580.5 + 2/2.64 = 0.5 + 0.758 = 1.258. Biased by 0.758.
    • IV: Cov⁡(Z,Y)=0.5Cov⁡(Z,T)=0.5⋅0.8=0.4\operatorname{Cov}(Z, Y) = 0.5\operatorname{Cov}(Z, T) = 0.5 \cdot 0.8 = 0.4, so Cov⁡(Z,Y)/Cov⁡(Z,T)=0.4/0.8=0.5\operatorname{Cov}(Z, Y)/\operatorname{Cov}(Z, T) = 0.4/0.8 = 0.5 ✓.

    5. In code #

    NumPy checks the numbers of section 4 with simulated data. The notebook has these cells and the exercises.

    import numpy as np
    rng = np.random.default_rng(0)
    
    # (a) linear model with a hidden confounder U and an instrument Z
    n = 100_000
    Z, U = rng.normal(size=n), rng.normal(size=n)
    T = 0.8 * Z + U + rng.normal(size=n)
    Y = 0.5 * T + 2 * U + rng.normal(size=n)
    ols = np.cov(T, Y)[0, 1] / np.var(T, ddof=1)
    iv = np.cov(Z, Y)[0, 1] / np.cov(Z, T)[0, 1]
    print(f"OLS {ols:.3f}   IV {iv:.3f}   truth 0.5")
    # OLS 1.256   IV 0.503   truth 0.5
    
    # (b) 2SLS in matrix form, with the correct and the naive standard error
    X = np.column_stack([np.ones(n), T])                # regressors
    Zm = np.column_stack([np.ones(n), Z])               # instruments
    Xhat = Zm @ np.linalg.lstsq(Zm, X, rcond=None)[0]   # first stage: P_Z X
    beta = np.linalg.lstsq(Xhat, Y, rcond=None)[0]      # second stage
    XtPX_inv = np.linalg.inv(Xhat.T @ Xhat)
    s2_right = np.sum((Y - X @ beta) ** 2) / (n - 2)     # residuals with the real T
    s2_naive = np.sum((Y - Xhat @ beta) ** 2) / (n - 2)  # residuals with the fitted T
    print(f"2SLS {beta[1]:.3f}   SE right {np.sqrt(s2_right * XtPX_inv[1, 1]):.4f}"
          f"   SE naive {np.sqrt(s2_naive * XtPX_inv[1, 1]):.4f}")
    # 2SLS 0.503   SE right 0.0088   SE naive 0.0108
    
    # (c) encouragement design with compliance types (shares 10% / 60% / 30%)
    n = 200_000
    kind = rng.choice(["always", "complier", "never"], size=n, p=[0.1, 0.6, 0.3])
    Zb = rng.integers(0, 2, size=n)
    Tb = np.where(kind == "always", 1, np.where(kind == "never", 0, Zb))
    p0 = np.select([kind == "always", kind == "complier"], [0.5, 0.4], 0.2)   # P(Y(0) = 1)
    p1 = np.select([kind == "always", kind == "complier"], [0.9, 0.6], 0.2)   # P(Y(1) = 1)
    Yb = (rng.random(n) < np.where(Tb == 1, p1, p0)).astype(float)
    itt = Yb[Zb == 1].mean() - Yb[Zb == 0].mean()
    fs = Tb[Zb == 1].mean() - Tb[Zb == 0].mean()
    as_treated = Yb[Tb == 1].mean() - Yb[Tb == 0].mean()
    print(f"ITT {itt:.3f}   first stage {fs:.3f}   Wald {itt / fs:.3f}   as-treated {as_treated:.3f}")
    # ITT 0.123   first stage 0.601   Wald 0.204   as-treated 0.375
    

    In (b), the naive standard error is about 20% too large here; in other designs it is too small. In (c), the Wald ratio is close to the true LATE 0.20, and the as-treated difference is close to the 0.375 of step 5.

    6. Where it shows up #

    • Online experiments. "Intent to treat" is the default analysis of an A/B test. When exposure is not forced (a banner can be ignored, an email unopened), the Wald ratio with assignment as the instrument gives the effect of exposure for compliers; with one-sided noncompliance it is the effect on the exposed users. Randomized recommendations or randomized ranking changes are instruments for exposure to an item.
    • Medicine. Trials report ITT and often a complier average causal effect (CACE), which is the LATE. Mendelian randomization is a large field in genetic epidemiology; its main fights are about pleiotropy.
    • Economics and policy. Returns to schooling, effects of military service, of class size (Angrist and Lavy, 1999, used a class-size rule, which is also a regression discontinuity: see lesson 07), of detention and of welfare programs.
    • ML methods. Deep IV fits the first stage as a conditional density and the second stage as a network; kernel IV and dual IV do the same with kernels. They inherit every condition of this lesson: a flexible model does not repair a broken exclusion restriction or a weak instrument.
    • Pricing and demand. Price is set in response to demand shocks, so regressing sales on price is confounded. Cost shocks (input prices, taxes) move price but not demand, and serve as instruments.

    7. Common mistakes #

    • Reporting a LATE as the ATE. The Wald ratio describes compliers. Say who they are (their share and their covariates) and do not generalize without an argument.
    • "The instrument is random, so it is valid." Randomization gives independence only. Exclusion must be argued from the mechanism. Ask: by which other paths could ZZ reach YY?
    • Testing exclusion by controlling for TT. TT is a collider between ZZ and UU; conditioning on it creates a ZZ–YY association even when exclusion holds.
    • Running the second stage by hand and keeping its standard errors. The residuals must use the real TT. Use a 2SLS routine or compute σ^2\hat\sigma^2 yourself.
    • The forbidden regression. Plugging logistic or probit fitted values into an OLS second stage is not 2SLS. Use them as instruments instead.
    • Ignoring a weak first stage. Report the first stage, its FF, and the reduced form. With FF below about 10, the estimate is pulled towards OLS; even with FF around 10, use robust inference.
    • Covariates in the second stage only. Every exogenous covariate must be in both stages.
    • Forgetting monotonicity. If some units react against the encouragement (defiers), the Wald ratio is not a LATE unless defiers and compliers have the same effect.

    8. Check yourself #

    1. Write the three IV conditions in words and say which one the data can check.
      AnswerRelevance (ZZ moves TT): testable with the first stage. Exclusion (ZZ changes YY only through TT): not testable. Independence (ZZ shares no common cause with YY, as good as random): not testable in general, but true by design when ZZ is randomized. With discrete data, the instrumental inequality can reject some invalid instruments.
    2. A randomized encouragement raises take-up from 0.20 to 0.45 and the outcome mean from 3.0 to 3.5. Compute the ITT, the first stage and the Wald estimate.
      AnswerITT =3.5−3.0=0.5= 3.5 - 3.0 = 0.5. First stage =0.45−0.20=0.25= 0.45 - 0.20 = 0.25 (25% compliers). Wald =0.5/0.25=2.0= 0.5/0.25 = 2.0: under exclusion and monotonicity, the average effect for compliers.
    3. Why do always-takers not affect the Wald ratio, even if their effect is large?
      AnswerThe encouragement does not change their treatment (T(0)=T(1)=1T(0) = T(1) = 1). Under exclusion it then does not change their outcome either, so they add the same amount to E[Y∣Z=1]\mathbb{E}[Y \mid Z{=}1] and E[Y∣Z=0]\mathbb{E}[Y \mid Z{=}0], and they do not change the first stage. Their effect is invisible to the instrument.
    4. In Y=1+2T+εY = 1 + 2T + \varepsilon with Cov⁡(Z,T)=0.5\operatorname{Cov}(Z, T) = 0.5, the instrument has a direct effect: Cov⁡(Z,ε)=0.1\operatorname{Cov}(Z, \varepsilon) = 0.1. What does the IV formula give?
      AnswerCov⁡(Z,Y)=2⋅0.5+0.1=1.1\operatorname{Cov}(Z, Y) = 2 \cdot 0.5 + 0.1 = 1.1, so IV =1.1/0.5=2.2= 1.1/0.5 = 2.2. The bias is Cov⁡(Z,ε)/Cov⁡(Z,T)=0.2\operatorname{Cov}(Z, \varepsilon)/\operatorname{Cov}(Z, T) = 0.2: a small violation of exclusion is divided by the first stage, so it is large when the instrument is weak.
    5. Write the 2SLS estimator in matrix form and say what PZP_{\mathbf Z} does.
      Answerβ^=(X⊤PZX)−1X⊤PZy\hat\beta = (\mathbf X^\top P_{\mathbf Z}\mathbf X)^{-1}\mathbf X^\top P_{\mathbf Z}\mathbf y with PZ=Z(Z⊤Z)−1Z⊤P_{\mathbf Z} = \mathbf Z(\mathbf Z^\top \mathbf Z)^{-1}\mathbf Z^\top. PZP_{\mathbf Z} projects each regressor onto the column space of the instruments: it keeps only the variation in TT that the instruments explain.
    6. Two valid instruments for the effect of schooling on wages give 6% and 11% per year. Is one of them invalid?
      AnswerNot necessarily. Each instrument moves a different group of people (its compliers). If the return to schooling differs between people, the two LATEs differ, and both can be correct.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. What are the three conditions for an instrument ZZ?

    2. Which IV condition can be checked with data?

    3. Give the IV formula in a linear model.

    4. Compute the Wald estimate when the reduced form is 0.120.12 and the first stage is 0.600.60.

    5. What is the intention-to-treat (ITT) effect?

    6. Define a complier, using potential treatments.

    7. What does monotonicity assume in an IV design?

    8. What does the Wald ratio estimate under the four IV assumptions with heterogeneous effects?

    9. Why are the standard errors of a manual second stage wrong?

    10. What happens to 2SLS when the instrument is weak?

    Open the review →

    9. Interview angle #

    • "In an A/B test only 40% of the treated users saw the feature. How do you estimate the effect of seeing it?" — Keep the randomized comparison. Report the ITT. Divide it by the difference in exposure rates between the arms (Wald / 2SLS with assignment as the instrument). If control users cannot see the feature, this is the effect on users who saw it. State the exclusion assumption (assignment matters only through exposure) and check the first stage. Do not compare viewers with non-viewers: that is confounded by engagement.
    • "What makes a good instrument?" — Strong first stage, a convincing reason that it touches the outcome only through the treatment, and as-good-as-random assignment. Then say who the compliers are.
    • "Why not just control for confounders?" — Because the important ones are unobserved. IV trades the no-unmeasured-confounding assumption for exclusion and independence of ZZ.
    • "Your first-stage FF is 8. What do you do?" — Expect bias towards OLS and bad coverage. Report the reduced form, use Anderson–Rubin intervals, look for a stronger instrument or more data.

    10. Practice #

    The notebook for this lesson has five exercises, each with a check cell and a folded solution:

    1. iv_ratio and ols_slope: compare OLS, IV and the truth on simulate_iv data with a hidden confounder.
    2. two_sls(y, T, Z, W): 2SLS in NumPy with homoskedastic and robust standard errors; compare with the naive two-step standard error.
    3. wald(df): ITT, first stage and LATE in an encouragement design with compliance types; compare with the true complier effect and the ATE.
    4. Weak instruments: median, spread and 95% coverage of 2SLS for several first-stage strengths.
    5. A broken exclusion restriction: check by simulation that the bias is β/γ\beta/\gamma.

    11. Watch and read #

    The charter-school lottery example; reduced form, first stage and their ratio.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Why the ITT and the as-treated comparison answer different questions.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The full lecture: the linear IV derivation, compliance types and the LATE proof.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    • Scott Cunningham, Causal Inference: The Mixtape, ch. 7 "Instrumental Variables", free online: the Wald estimator, 2SLS, weak instruments, judge designs.
    • Nick Huntington-Klein, The Effect, ch. 19 "Instrumental Variables", free online: the conditions explained with graphs.
    • Brady Neal, Introduction to Causal Inference, course notes (free PDF), ch. 9: instrumental variables and the LATE proof.
    • Imbens and Angrist (1994), "Identification and Estimation of Local Average Treatment Effects", Econometrica; Angrist, Imbens and Rubin (1996), "Identification of Causal Effects Using Instrumental Variables", JASA. The original LATE papers.
    • Lee, McCrary, Moreira and Porter (2022), Valid t-ratio Inference for IV, American Economic Review (arXiv version): why F>10F > 10 is not enough for the tt-test.
    • Angrist and Pischke, Mostly Harmless Econometrics (2009), ch. 4 (book): 2SLS, the forbidden regression, weak instruments.