Math for Causal Inference

Day 72. Triple Differences & Changes-in-Changes

Two extensions of DiD. Triple differences add a within-state comparison group that is not targeted by the policy, so state-specific shocks cancel. Changes-in-changes drops additivity altogether and maps ranks across distributions, giving effects on whole outcome distributions that do not depend on the outcome's scale.

Video coming soon
Learning outcomes
  • ●Compute a triple-difference estimate and state the single parallel-trends assumption it needs.
  • ●Write the fully interacted DDD regression.
  • ●Derive the changes-in-changes counterfactual distribution and compute it by rank matching.
  • ●Choose between DiD, DDD and CiC in labour and health applications.
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

Triple differences

DiD fails if the treated state has its own shock in the post period. If the policy targets a subgroup (married women of child-bearing age; low-income adults), we can use an untargeted subgroup in the same states to absorb state shocks:

DDD=(ΔYˉT,A−ΔYˉC,A)⏟DiD, affected group−(ΔYˉT,B−ΔYˉC,B)⏟DiD, unaffected group,DDD = \underbrace{\big(\Delta\bar Y_{T, A} - \Delta\bar Y_{C, A}\big)}_{\text{DiD, affected group}} - \underbrace{\big(\Delta\bar Y_{T, B} - \Delta\bar Y_{C, B}\big)}_{\text{DiD, unaffected group}},

where T,CT, C index treated and control states, A,BA, B the affected and unaffected subgroups, and Δ\Delta the before–after change.

Assumption: the bias of the DiD (non-parallel trends) is the same for the two subgroups. DDD does not need two separate parallel-trends assumptions; it needs only that the difference between subgroups would have evolved in parallel across states (Olden and Møen).

Regression: a saturated regression with state-group, period and subgroup indicators and all their interactions; the coefficient on the triple interaction T×Post×AT \times \text{Post} \times A is the DDD.

Changes-in-changes (Athey and Imbens)

DiD assumes additivity: the counterfactual shift is the same in levels for everyone. CiC instead assumes

  • untreated outcomes are Y(0)=h(U,t)Y(0) = h(U, t) with hh strictly increasing in an unobserved "rank" UU;
  • the distribution of UU within each group does not change over time (it may differ between groups).

Then a treated unit at rank qq in its group's pre-period distribution would have the outcome of the control-group rank that the same UU maps to. The counterfactual distribution of the treated in the post period is

FY(0),11(y)=F10(F00−1(F01(y))),F_{Y(0), 11}(y) = F_{10}\Big(F_{00}^{-1}\big(F_{01}(y)\big)\Big),

where FgtF_{gt} is the observed distribution in group gg, period tt. Equivalently, the counterfactual for a treated pre-period outcome yy is F01−1(F00(y))F_{01}^{-1}(F_{00}(y)): find yy's rank among control units before, then the control outcome at that rank after.

Why CiC

CiC gives quantile treatment effects (effects at the median, at the 10th percentile), not just a mean, and is invariant to monotone transformations of the outcome: levels and logs give the same answer, resolving Day 67's scale problem. It requires continuous outcomes (or bounds for discrete ones) and support overlap.

Part 1 · Warm-up

Exercise 1 · A triple difference

Changes in log wages (%), before and after a state mandated maternity benefits: treated state, married women 20–40: −5; treated state, others: −1; control states, married women 20–40: +1; control states, others: +2. Compute the DiD for each group and the DDD.

Show solution

Step 1. Affected group DiD: −5−1=−6-5 - 1 = -6.

Step 2. Unaffected group DiD: −1−2=−3-1 - 2 = -3.

Step 3. DDD: −6−(−3)=−3-6 - (-3) = -3.

Answer: −3%: the mandate's cost was partly shifted to targeted workers' wages. The DiD for the affected group alone (−6) includes a state-wide shock of −3.

Exercise 2 · The regression coefficient

In the saturated DDD regression, which coefficient is the DDD, and what do the two-way interactions absorb?

Show solution

Step 1. The coefficient on Treated state×Post×Affected\text{Treated state} \times \text{Post} \times \text{Affected}.

Step 2. Treated state×Post\text{Treated state} \times \text{Post} absorbs state-wide shocks; Affected×Post\text{Affected} \times \text{Post} absorbs nationwide trends for the targeted group; Treated state×Affected\text{Treated state} \times \text{Affected} absorbs permanent differences.

Exercise 3 · What DDD buys

Give an example of a shock DiD cannot handle but DDD can, and one DDD cannot handle.

Show solution

Step 1. Handled: a recession hitting the treated state at the same time as the mandate, affecting all workers in the state equally.

Step 2. Not handled: a second policy in the treated state at the same time that also targets married women (for example a child-care subsidy).

Exercise 4 · One CiC counterfactual

Control-group outcomes before: 5, 8, 12, 15; after: 6, 10, 15, 20. A treated unit had 12 before. Using ranks, what is its counterfactual post-period outcome? What does DiD's additive shift imply?

Show solution

Step 1. Rank of 12 among controls before: third of four (F00(12)=0.75F_{00}(12) = 0.75).

Step 2. Control outcome at the same rank after: 15.

Step 3. CiC counterfactual: 15. DiD shift: control mean rises from 10 to 12.75 (+2.75), so DiD predicts 12+2.75=14.7512 + 2.75 = 14.75.

Answer: CiC lets the change depend on the rank: higher-ranked units gained more.

Exercise 5 · Logs or levels?

Why does CiC give the same estimated effects (after transformation) whether the outcome is wages or log wages?

Show solution

Step 1. CiC uses only ranks and quantiles; a strictly increasing transformation preserves ranks.

Answer: the counterfactual of log⁡Y\log Y is the log of the counterfactual of YY (Exercise 9).

Part 2 · Proofs

Exercise 6 · DDD removes common bias

Let each subgroup DiD equal ATTs+bsATT_s + b_s, where bsb_s is its parallel-trends bias, with ATTB=0ATT_B = 0 for the unaffected subgroup. Show DDD=ATTADDD = ATT_A if bA=bBb_A = b_B.

Show solution

Step 1. DDD=(ATTA+bA)−(0+bB)DDD = (ATT_A + b_A) - (0 + b_B).

Step 2. With bA=bBb_A = b_B: DDD=ATTADDD = ATT_A. ■\blacksquare

Exercise 7 · The triple interaction

Show that in the saturated regression with all main effects and interactions of SS (treated state), PP (post) and AA (affected), the coefficient on S×P×AS \times P \times A is the DDD of cell means.

Show solution

Step 1. Eight cells and eight parameters: fitted values equal cell means.

Step 2. Within A=aA = a, the coefficients on S×PS \times P plus (aa times) the triple interaction give the DiD for subgroup aa.

Step 3. Subtracting the A=0A = 0 DiD from the A=1A = 1 DiD leaves the triple-interaction coefficient. ■\blacksquare

Exercise 8 · The CiC counterfactual

Assume Y(0)=h(U,t)Y(0) = h(U, t), hh strictly increasing in UU, and U∣G=gU \mid G = g has the same distribution in both periods. Prove FY(0),11(y)=F10(F00−1(F01(y)))F_{Y(0), 11}(y) = F_{10}(F_{00}^{-1}(F_{01}(y))) (continuous distributions).

Show solution

Step 1. Controls: F0t(y)=P(h(U,t)≤y∣G=0)=FU∣0(h−1(y,t))F_{0t}(y) = P(h(U, t) \le y \mid G = 0) = F_{U \mid 0}(h^{-1}(y, t)).

Step 2. So h−1(y,1)=FU∣0−1(F01(y))h^{-1}(y, 1) = F_{U \mid 0}^{-1}(F_{01}(y)) and h(u,0)=F00−1(FU∣0(u))h(u, 0) = F_{00}^{-1}(F_{U \mid 0}(u)); hence h(h−1(y,1),0)=F00−1(F01(y))h(h^{-1}(y, 1), 0) = F_{00}^{-1}(F_{01}(y)).

Step 3. Treated in period 1 without treatment: FY(0),11(y)=P(U≤h−1(y,1)∣G=1)F_{Y(0), 11}(y) = P(U \le h^{-1}(y, 1) \mid G = 1).

Step 4. Since U∣G=1U \mid G = 1 is stable, this equals P(h(U,0)≤h(h−1(y,1),0)∣G=1)=F10(F00−1(F01(y)))P(h(U, 0) \le h(h^{-1}(y, 1), 0) \mid G = 1) = F_{10}(F_{00}^{-1}(F_{01}(y))). ■\blacksquare

Exercise 9 · Invariance to monotone transformations

Let gg be strictly increasing and apply CiC to g(Y)g(Y). Show the counterfactual for a treated pre-period value yy becomes g(F01−1(F00(y)))g\big(F_{01}^{-1}(F_{00}(y))\big).

Show solution

Step 1. The distribution of g(Y)g(Y) satisfies Fg(g(y))=F(y)F^g(g(y)) = F(y) and (Fg)−1(q)=g(F−1(q))(F^g)^{-1}(q) = g(F^{-1}(q)).

Step 2. Counterfactual for g(y)g(y): (F01g)−1(F00g(g(y)))=g(F01−1(F00(y)))(F^g_{01})^{-1}(F^g_{00}(g(y))) = g(F_{01}^{-1}(F_{00}(y))). ■\blacksquare

Exercise 10 · When CiC equals DiD

Suppose h(u,t)=u+δth(u, t) = u + \delta_t (an additive time shift). Show the CiC counterfactual mean equals the DiD counterfactual.

Show solution

Step 1. Controls' distribution shifts by δ1−δ0\delta_1 - \delta_0: F01−1(F00(y))=y+δ1−δ0F_{01}^{-1}(F_{00}(y)) = y + \delta_1 - \delta_0.

Step 2. Each treated unit's counterfactual is its pre-period outcome plus δ1−δ0\delta_1 - \delta_0; averaging gives Yˉ10+(Yˉ01−Yˉ00)\bar Y_{10} + (\bar Y_{01} - \bar Y_{00}).

Step 3. That is the DiD counterfactual. ■\blacksquare

Part 3 · Applied

Exercise 11 · Mandated maternity benefits

Exercise 1's numbers resemble Gruber's study of state maternity mandates. Interpret the DDD of −3% for workers and employers.

Show solution

Step 1. Married women of child-bearing age, the group whose expected health costs rose, saw relative wage declines of 3%.

Step 2. Unaffected workers in the same states absorb the state-wide shock (−3% in the DiD for others).

Answer: employers shifted most of the mandate's cost onto targeted workers' wages, with little employment change: incidence on workers.

Exercise 12 · Medicaid expansion by income

Change in uninsured rate (points): expansion states, low-income adults −9; high-income adults −2. Non-expansion states: low-income −4; high-income −1. Compute the DDD and give its assumption.

Show solution

Step 1. Low-income DiD: −9−(−4)=−5-9 - (-4) = -5.

Step 2. High-income DiD: −2−(−1)=−1-2 - (-1) = -1.

Step 3. DDD: −5−(−1)=−4-5 - (-1) = -4 points.

Answer: expansion cut low-income uninsurance by 4 points; assumption: absent expansion, the low–high income gap in uninsurance would have evolved the same way in both sets of states. (If high-income adults also benefited, through spillovers, the DDD understates the effect.)

Exercise 13 · Distributional effects of a training programme

In the simulation below, training raises earnings by more for workers with high latent earnings capacity. Compare the DiD estimate with CiC quantile effects at the 10th, 50th and 90th percentiles.

Show solution

Step 1. DiD gives one number (the average effect).

Step 2. CiC maps each treated unit's pre-period rank through the control group's distributions to build the counterfactual distribution, then compares quantiles.

Step 3. The code shows quantile effects rising from slightly negative at the 10th percentile to large at the 90th, close to the simulated truth.

Step 4. DiD (about 2.8) also overstates the mean effect (about 1.8), because untreated earnings grow multiplicatively, so additive parallel trends fail; CiC's mean effect (1.7) is close.

Answer: CiC reveals that the programme helps those with high earnings capacity and may slightly hurt those at the bottom, information a mean DiD hides.

Exercise 14 · A threat to DDD

In Exercise 12, expansion states also launched an outreach campaign for low-income families in the same year. What happens to the DDD?

Show solution

Step 1. The campaign affects the same state × group × period cell as the expansion.

Answer: DDD attributes the campaign's effect to the expansion; it cannot separate policies that coincide in all three dimensions.

Exercise 15 · Which design?

Choose DiD, DDD or CiC: (a) a hospital-quality programme in one region, with a coinciding regional recession that affects all hospitals; patients' conditions not targeted are also observed. (b) A minimum-wage increase whose effect on the whole wage distribution is of interest. (c) A national school-meals expansion compared with a neighbouring country, with no subgroup structure.

Show solution

Step 1. (a) DDD: compare targeted with untargeted conditions within region to remove the recession.

Step 2. (b) CiC (or distributional DiD) for quantile effects.

Step 3. (c) DiD, after checking pre-trends and scale.

Verify in Python

import numpy as np

# Exercises 1 and 12
ddd = lambda tA, cA, tB, cB: (tA - cA) - (tB - cB)
print("maternity DDD:", ddd(-5, 1, -1, 2), " Medicaid DDD:", ddd(-9, -4, -2, -1))

# Exercise 4: one CiC counterfactual
c0 = np.array([5, 8, 12, 15.]); c1 = np.array([6, 10, 15, 20.])
q = (c0 <= 12).mean(); print("rank", q, "-> counterfactual", np.quantile(c1, q, method="inverted_cdf"), " DiD:", 12 + c1.mean() - c0.mean())

# Exercise 13: changes-in-changes on simulated earnings
rng = np.random.default_rng(72); n = 20_000
U0, U1 = rng.normal(0, 1, n), rng.normal(.5, 1, n)                 # controls, treated (different rank distributions)
h = lambda u, t: np.exp(2.5 + .4 * u + .15 * t * (1 + .3 * u))      # nonlinear, increasing in u
y00, y01 = h(U0, 0), h(rng.normal(0, 1, n), 1)                       # controls before / after (fresh draws, same distribution)
y10 = h(U1, 0); U1b = rng.normal(.5, 1, n)
y11_0 = h(U1b, 1); y11 = y11_0 * (1 + .05 + .1 * (U1b - .5))         # treated after, effect grows with u
cf = np.quantile(y01, np.searchsorted(np.sort(y00), y10) / n)        # CiC counterfactuals for treated pre-period units
did = y11.mean() - (y10.mean() + y01.mean() - y00.mean())
print(f"DiD {did:.2f}  CiC mean effect {y11.mean() - cf.mean():.2f}  true mean effect {(y11 - y11_0).mean():.2f}")
for p in (.1, .5, .9):
    print(f"q{int(p * 100)}: CiC {np.quantile(y11, p) - np.quantile(cf, p):.2f}  truth {np.quantile(y11, p) - np.quantile(y11_0, p):.2f}")

Key takeaways

  • DDD subtracts the DiD of an untargeted subgroup in the same states; it needs only that their difference would have trended in parallel.
  • CiC replaces additive parallel trends with stable rank distributions, giving quantile effects and scale invariance.
  • Neither can separate policies that coincide in every dimension used for comparison.

Simulation Lab: Triple Differences

Open full screen →

A state shock biases DiD for the targeted group; subtracting other workers in the same state removes it.

-3.0treated stateaffected3.0comparison statesaffected-1.0treated stateothers2.0comparison statesothers
DiD, affected group
-6.00
DiD, other workers
-3.00
DDD
-3.00
truth
-3.00

Changes in log wages (%) before and after a state mandate that raises costs of employing married women aged 20–40 (the affected group). A state-wide shock hits everyone in the treated state; a national trend hits the affected group everywhere. DiD for the affected group picks up the state shock; DDD subtracts it using other workers in the same state. Only a shock specific to the treated state and the affected group (the violation) biases DDD.

Day 71Day 73