Instruments¶
examples/schooling_iv.py
estimates the return to a year of schooling for Californian workers born in
the United States, with quarter of birth as the instrument (Angrist and
Krueger 1991). The page shows what to do when the instruments turn out to be
too weak to identify the effect, which is the outcome here. Check that with
the first-stage F, and get inference that stays valid anyway from the
sup-score test.
Compulsory-schooling laws bind by age. A child’s birthday therefore affects how much schooling they have reached when they may leave, which makes quarter of birth a candidate instrument.
from acs_data import PREDICTORS, load_acs, rhs
from penalized_stream import double_selection_iv_stream, double_selection_stream
acs = pl.scan_parquet(load_acs()).filter(pl.col("birthplace") <= 56) # born in a state
controls = rhs([p for p in PREDICTORS if p not in ("education", "degree_field")])
instruments = "C(birth_quarter) + C(birth_quarter):C(birthplace)"
The candidate controls are the person’s characteristics other than schooling itself. The job’s characteristics are left out, because schooling changes them. The instruments are the quarter of birth and its interactions with the state of birth: about 200 indicators, as in Belloni, Chen, Chernozhukov and Hansen (2012).
OLS¶
ols = double_selection_stream("log_wage ~ schooling", acs, controls=controls)
OLS, post-double-selection 0.0727 (se 0.0010)
OLS, no controls 0.1029 (se 0.0010)
A year of schooling goes with 7.3 log points higher wages among people with the same selected characteristics. Without controls the figure is 10.3 log points.
Selecting the instruments¶
iv = double_selection_iv_stream(f"log_wage ~ 1 + [schooling ~ {instruments}]", acs,
controls=controls, select_instruments=True)
select_instruments=True: the lasso of schooling on the instruments and controls selected no instrument
With select_instruments=True, a lasso of schooling on the instruments and
the controls chooses the instruments, as hdm’s rlassoIV does. With the
plug-in penalty, an instrument enters only if it predicts schooling beyond
what chance would produce among 200 candidates. None does. In these cohorts,
the quarter of birth says almost nothing about years of schooling once the
other characteristics are held fixed. That is the right answer: 2SLS on
these instruments would not be reliable. The function raises an error
rather than fit it.
Three instruments, every one used¶
few = double_selection_iv_stream("log_wage ~ 1 + [schooling ~ C(birth_quarter)]", acs,
controls=controls, sup_score=True)
po = double_selection_iv_stream("log_wage ~ 1 + [schooling ~ C(birth_quarter)]", acs,
controls=controls, method="partialling_out")
print(f"first-stage F: {few.f_stat_1st_stage[0]:.2f}")
2SLS, quarter of birth (union of selected controls) 0.4000 (se 0.4441)
2SLS, quarter of birth (partialling out, hdm's) 0.3852 (se 0.4017)
first-stage F: 0.30
With the three quarter-of-birth indicators as the only instruments, lassos
select controls for the wage, for schooling and for each instrument. The
default estimate is 2SLS with the union of those controls. With
method="partialling_out", it is hdm’s estimate: 2SLS on each variable’s
residual from its own selected controls.
The two estimates agree with each other, but neither should be reported. The first-stage F is 0.30, far below the usual threshold of 10. When the instruments are this weak, 2SLS is biased toward OLS, and its standard error understates the uncertainty.
The sup-score test¶
sup_score=True adds the sup-score test (Belloni, Chen, Chernozhukov and
Hansen 2012) at the cost of one more pass over the data. It tests the effect
without relying on the instruments’ strength. Under the null that the effect
is a, the wage less a times schooling, both net of their selected controls,
is uncorrelated with every instrument. The test rejects when some
instrument’s correlation is larger than chance allows.
test = few.double_selection.sup_score
print(test.summary_text())
print(test.grid[[0, 25, 50, 75, 100]])
sup-score test (bound, hetero; 3 instruments): effect = 0: statistic 1.488, critical value 2.633, p = 0.5288
sup-score 95% confidence set: every value (the test rejects none)
┌───────────┬───────────┬─────────┬──────────┐
│ value ┆ statistic ┆ p_value ┆ rejected │
╞═══════════╪═══════════╪═════════╪══════════╡
│ -8.481492 ┆ 0.993695 ┆ 1.0 ┆ false │
│ -4.040726 ┆ 1.035734 ┆ 1.0 ┆ false │
│ 0.400039 ┆ 0.466321 ┆ 1.0 ┆ false │
│ 4.840805 ┆ 0.879448 ┆ 1.0 ┆ false │
│ 9.28157 ┆ 0.915562 ┆ 1.0 ┆ false │
└───────────┴───────────┴─────────┴──────────┘
The test does not reject a zero effect, and it rejects no value at all. Its 95% confidence set is the whole line, solved exactly rather than read off a grid. The table samples the default grid, the 2SLS estimate plus or minus 20 standard errors. Even an effect of 9 per year, over a hundred times the OLS estimate, is not rejected, because the statistic stays near 1 everywhere, well below the critical value of 2.63. This is how weak instruments should look: they carry no information about the effect, and the confidence set says so, where a 2SLS interval of 0.40 ± 0.87 would suggest they carry some.
The default critical value is the bound c Φ⁻¹(1 − 0.05/(2p)), with c = 1.1
and p instruments, which lassopack’s ivlasso also uses. It is
conservative. sup_score_options={"method": "bootstrap"} uses the multiplier
bootstrap instead, which gives a tighter test.