Day 44. IPW & Hájek Estimators of the ATE
Re-weighting treated and control units by the inverse of their propensity scores to recreate the population each group is missing.
- ●Prove the inverse-probability-weighting identities for E[Y(1)], E[Y(0)] and the ATT.
- ●Compute Horvitz–Thompson and Hájek IPW estimates of the ATE and ATT by hand.
- ●Diagnose extreme weights with the effective sample size and understand trimming and stabilisation.
- ●Relate IPW to weighted regression and to survey weighting.
Theory
The idea
Under unconfoundedness and overlap (Day 42), a treated unit with propensity represents units with the same covariates, some of whom were not treated. Weighting each treated unit by rebuilds the whole population's distribution; weighting controls by rebuilds :
(This is Day 14's missing-data result applied twice.)
Estimators
Horvitz–Thompson (HT):
Hájek (normalised): divide each weighted sum by the sum of its weights instead of :
Hájek is invariant to shifting by a constant, keeps each mean within the range of the data, and usually has lower variance. It equals a weighted regression of on (Day 24).
ATT: treated units get weight 1; controls get (the odds of treatment), which reshapes the controls to look like the treated.
Weights and precision
When is near 0 or 1, a few units get huge weights and dominate the estimate. Diagnostics and remedies:
- Effective sample size: , the number of equally weighted units with the same precision.
- Trimming units with extreme (changes the estimand, Day 42) or truncating weights at a cap (adds a little bias).
- Using the estimated propensity score is, perhaps surprisingly, more efficient than using the true one (Hirano, Imbens & Ridder 2003).
Part 1 · Warm-up
Exercise 1 · Individual weights
A treated household has and a control household also has . What ATE weights do they get, and what do the weights mean?
Show solution
Step 1. Treated: . It stands in for itself and three similar households that were not treated.
Step 2. Control: . Controls with this profile are common, so each represents only a third more households.
Exercise 2 · An ATT weight
What ATT weight does the control household in Exercise 1 get?
Show solution
Step 1. Odds of treatment: .
Answer: 1/3. Profiles that are rarely treated get small weight when we want controls to resemble the treated.
Exercise 3 · Effective sample size
Four units have weights 1, 1, 1 and 10. Compute the ESS.
Show solution
Step 1. and .
Step 2. ESS .
Answer: four units carry the information of fewer than two: one unit dominates.
Exercise 4 · Hájek is location-invariant
Add 100 to every outcome. How do the HT and Hájek estimates of change?
Show solution
Step 1. Hájek: weighted average of is the old weighted average plus 100 (weights sum to one after normalising).
Step 2. HT: adds , which equals 100 only if the sample weights average exactly to 1.
Answer: Hájek shifts by exactly 100; HT shifts by 100 times a random factor, so it is not location-invariant.
Exercise 5 · Truncation
Weights above 20 are capped at 20. Which quantity does this change, and what is the trade-off?
Show solution
Step 1. The weighted means no longer exactly reproduce the population, so a small bias appears.
Step 2. Variance falls, often a lot.
Answer: a bias–variance trade-off (Day 8); report results with and without truncation.
Part 2 · Proofs
Exercise 6 · The IPW identity
Under unconfoundedness and , prove .
Show solution
Step 1. (the observed outcome of treated units).
Step 2. LIE: .
Step 3. Unconfoundedness: .
Step 4. The cancels: .
Exercise 7 · ATT weights
Under and , prove .
Show solution
Step 1. .
Step 2. LIE and unconfoundedness: .
Step 3. So the expectation equals .
Step 4. Also (unconfoundedness again). The two agree.
Dividing by (or normalising the weights) gives .
Exercise 8 · Hájek is weighted least squares
Show that regressing on an intercept and with weights gives the Hájek estimator.
Show solution
Step 1. WLS with columns fits a separate weighted mean in each arm (Day 24, Exercise 12).
Step 2. The treated arm's weighted mean is ; the control arm's is the analogous expression with .
Step 3. The slope on is their difference: .
In practice, use robust SEs that account for estimating (or bootstrap the whole procedure).
Exercise 9 · Why HT is less stable
Show that the HT estimate of can be written as , where is the Hájek mean, and explain the consequence.
Show solution
Step 1. By definition, .
Step 2. Multiply both sides by : , the HT mean.
Step 3. The factor has expectation 1 but varies from sample to sample, especially with extreme weights.
Answer: HT multiplies the Hájek mean by a noisy factor, adding variance proportional to the level of .
Exercise 10 · Weights that explode
Show that involves , and explain why limited overlap can make IPW very imprecise.
Show solution
Step 1. .
Step 2. If is close to 0 for a non-negligible share of units, this expectation is huge (or infinite if can be arbitrarily close to 0).
Answer: IPW variance is driven by the smallest propensities; poor overlap means imprecise IPW, which is why diagnostics come first.
Part 3 · Applied
Six households in a cash-transfer evaluation, with estimated propensities and monthly savings ($10):
| Household | |||
|---|---|---|---|
| 1 | 1 | 0.8 | 20 |
| 2 | 1 | 0.5 | 16 |
| 3 | 1 | 0.2 | 10 |
| 4 | 0 | 0.8 | 14 |
| 5 | 0 | 0.5 | 12 |
| 6 | 0 | 0.2 | 8 |
Exercise 11 · Naive and Horvitz–Thompson
Compute the naive difference in means and the HT estimate of the ATE.
Show solution
Step 1. Naive: treated mean ; control mean ; difference 4.0.
Step 2. HT for : .
Step 3. HT for : .
Step 4. .
Answer: naive 4.0 versus HT 0.5. The treated have higher propensities (likely better-off households), and weighting removes most of the gap.
Exercise 12 · Hájek
Compute the Hájek estimate of the ATE for the same households.
Show solution
Step 1. Treated weights : 1.25, 2, 5 (sum 8.25). Weighted mean: .
Step 2. Control weights : 5, 2, 1.25 (sum 8.25). Weighted mean: .
Step 3. .
Answer: 0.36. With six units HT and Hájek differ noticeably; Hájek's means (≈ 13) stay within the range of the data, whereas HT's (≈ 17.8) do not.
Exercise 13 · The ATT
Compute the IPW estimate of the ATT.
Show solution
Step 1. Treated mean (weight 1 each): 15.33.
Step 2. Control ATT weights : household 4: ; household 5: 1; household 6: (sum 5.25).
Step 3. Weighted control mean: .
Step 4. ATT .
Answer: 2.0 ($20/month). Controls that look like the treated (high ) get most of the weight.
Exercise 14 · Extreme weights in a hospital study
In a study of a surgical procedure, one untreated patient has and gets an ATE weight of 100; the next largest weight is 8. The estimate changes from a 3-point to a 9-point mortality reduction when this patient is dropped. What should be reported?
Show solution
Step 1. A single patient driving the estimate signals an overlap problem: almost everyone like this patient is treated.
Step 2. Report the ESS, the weight distribution and estimates with trimming (e.g. ) or truncation.
Step 3. Consider a doubly robust estimator (Day 45), which leans on an outcome model where weights are extreme and is less sensitive to a single large weight.
Answer: do not report a single IPW number; show its sensitivity to the extreme weight and redefine the estimand for the overlap population if needed.
Exercise 15 · Survey weights and IPW
National surveys oversample poor regions and publish weights equal to the inverse of each household's sampling probability. Explain the parallel with IPW and why both rely on knowing (or estimating well) a probability.
Show solution
Step 1. Survey sampling: each sampled household represents households in the population; weighting by gives unbiased population means (Horvitz & Thompson, 1952).
Step 2. IPW: each treated unit "was sampled" into treatment with probability , so weighting by recovers the population mean of .
Step 3. Survey designers know ; observational analysts must estimate and assume no unobserved confounding.
Answer: the same estimator; the difference is whether the selection probability is known by design or estimated under assumptions.
Verify in Python
import numpy as np
from scipy import optimize
T = np.array([1, 1, 1, 0, 0, 0]); e = np.array([.8, .5, .2, .8, .5, .2]); Y = np.array([20, 16, 10, 14, 12, 8.])
ht = (T * Y / e).mean() - ((1 - T) * Y / (1 - e)).mean()
hj = (T * Y / e).sum() / (T / e).sum() - ((1 - T) * Y / (1 - e)).sum() / ((1 - T) / (1 - e)).sum()
w = e / (1 - e); c = T == 0
print(f"naive {Y[T == 1].mean() - Y[T == 0].mean():.2f}, HT {ht:.2f}, Hajek {hj:.2f}, "
f"ATT {Y[T == 1].mean() - (w[c] * Y[c]).sum() / w[c].sum():.2f}")
# Monte Carlo: HT vs Hajek, true vs estimated propensity scores
rng = np.random.default_rng(44)
res = {"HT": [], "Hajek": [], "Hajek (true e)": []}
for _ in range(2000):
n = 500; x = rng.normal(size=n); X = np.column_stack([np.ones(n), x])
e_true = 1 / (1 + np.exp(-1.2 * x)); T = rng.random(n) < e_true
y = 50 + 5 * x + 2 * T + rng.normal(0, 3, n)
b = optimize.minimize(lambda b: -np.sum(T * (X @ b) - np.log1p(np.exp(X @ b))), np.zeros(2)).x
eh = 1 / (1 + np.exp(-X @ b))
res["HT"].append((T * y / eh).mean() - ((1 - T) * y / (1 - eh)).mean())
for key, ee in (("Hajek", eh), ("Hajek (true e)", e_true)):
res[key].append((T * y / ee).sum() / (T / ee).sum() - ((1 - T) * y / (1 - ee)).sum() / ((1 - T) / (1 - ee)).sum())
for k, v in res.items():
print(f"{k:15s} mean {np.mean(v):.3f} (truth 2) SD {np.std(v):.3f}")
Key takeaways
- Weighting by 1/e and 1/(1 − e) recreates the population's Y(1) and Y(0) under unconfoundedness and overlap.
- Prefer the normalised (Hájek) estimator; use odds weights for the ATT.
- Extreme weights signal poor overlap: check the ESS and report sensitivity to trimming.
Simulation Lab: Horvitz–Thompson vs Hájek
Open full screen →Monte Carlo of two IPW estimators; shift the outcome level and only the normalised (Hájek) version stays stable.
Weighting by 1/e(x) recreates a randomised comparison. Horvitz–Thompson divides by n; Hájek divides by the sum of the weights, so adding a constant to every outcome cannot move it. Raise the outcome level and watch HT spread out while Hájek stays put. True effect +1.