The effect of a variable

examples/gender_gap.py estimates the gender wage gap among California’s workers aged 25 to 64, controlling for characteristics that lassos select from about 2,000 indicators. It estimates the gap three ways: post-double-selection, double machine learning and the debiased lasso. All three give a coefficient with a valid standard error, which a lasso’s own coefficient does not have.

from acs_data import WAGE_PREDICTORS, load_acs, rhs
from hdfe_stream import feols_stream
from penalized_stream import debiased_lasso_stream, double_ml_stream, double_selection_stream

acs = load_acs()
controls = rhs([p for p in WAGE_PREDICTORS if p != "female"])

The candidate controls are the other 38 characteristics, including the job’s occupation, industry and hours. Each characteristic is a categorical, which makes 1,971 indicator columns. Controlling for the job measures the gap among people in the same kind of job; without the job’s characteristics the gap would include differences in which jobs women and men hold.

The raw gap and post-double-selection

feols_stream("log_wage ~ female", acs, vcov="hetero")
pds = double_selection_stream("log_wage ~ female", acs, controls=controls)
no controls                                           -0.1514  (se 0.0042)
post-double-selection                                 -0.1253  (se 0.0064)
post-double-selection: 497 of 1971 controls selected (penalty: rigorous)

Women’s hourly wages are 15 log points below men’s. Among people with the same selected characteristics, they are 12.5 log points below. Post-double-selection (Belloni, Chernozhukov and Hansen 2014) runs a lasso of the wage on the controls and a lasso of female on the controls, then fits OLS of the wage on female and every control either lasso kept. The lassos use the plug-in penalty, whose theory makes the final standard error valid, and that standard error is robust to heteroskedasticity.

Clustered standard errors

cl = double_selection_stream("log_wage ~ female", acs, controls=controls,
                             vcov={"CRV1": "puma_id"})
post-double-selection, clustered by PUMA              -0.1246  (se 0.0067)

With a clustered vcov, the plug-in penalty’s loadings are clustered too, so the lassos can select different controls, and the estimate moves slightly. The standard error grows a little: people in the same PUMA (an area of about 100,000 people) share some shocks, but not many.

Double machine learning and the debiased lasso

dml = double_ml_stream("log_wage ~ female", acs, controls=controls, n_repeats=3)
deb = debiased_lasso_stream(f"log_wage ~ female + {controls}", acs,
                            coefficients=["female"], vcov="hetero")
double machine learning (3 repeats)                   -0.1262  (se 0.0064)
debiased lasso                                        -0.1267  (se 0.0063)

Double machine learning (Chernozhukov et al. 2018) fits the wage and female on the controls by cross-validated lassos, on four fifths of the data at a time. It takes each fit’s residuals on the other fifth, then regresses the wage’s residuals on female’s. The median over three random splits into folds removes most of the dependence on any one split. The folds’ fits all come from the one pass over the data.

The debiased lasso (van de Geer, Bühlmann, Ritov and Dezeure 2014) starts from one lasso of the wage on female and every control and corrects the coefficients you name for the lasso’s shrinkage. It gives intervals for several coefficients at once from the same model.

The three methods agree to within 0.15 log points, well inside one standard error. They rest on different assumptions, so their agreement is evidence that the estimate does not depend on how the controls were chosen.

Why it takes two lassos

ds = pds.double_selection
only_female = [c for c in ds.selected["female"] if c not in ds.selected["log_wage"]]
┌──────────────┬──────────┐
│ selected for ┆ controls │
╞══════════════╪══════════╡
│ log_wage     ┆ 323      │
│ female       ┆ 311      │
└──────────────┴──────────┘
174 controls are in the union only through the lasso of female, for example C(age)[T.33], C(age)[T.34], C(age)[T.35], C(age)[T.36]

A lasso of the wage alone keeps the controls that predict wages well. It can leave out a control that predicts wages only weakly, even when that control is strongly related to female, and leaving such a control out biases the gap. The second lasso keeps the controls related to female. Here, 174 of the 497 controls in the regression come only from that second lasso, among them single years of age.