*! version 30aug2024

Interactive IV model (LATE) - Detailed example with pystacked

Preparation: we load the data, define global macros and set the seed.

. use http://fmwww.bc.edu/repec/bocode/j/jtpa.dta, clear

. global Y earnings

. global D training

. global Z assignmt

. global X sex age married black hispanic

. set seed 42

We initialize the model.

. ddml init interactiveiv, kfolds(5)

We use pystacked with two base learners for each reduced form equation.
Note that E[Y|X,Z] is a regression problem,
whereas E[D|X,Z] and E[Z|X] are classification problems.

. ddml E[Y|X,Z]: pystacked $Y c.($X)# #c($X), type(reg) m(ols lassocv)

. ddml E[D|X,Z]: pystacked $D c.($X)# #c($X), type(class) m(logit lassocv)

. ddml E[Z|X]: pystacked $Z c.($X)# #c($X), type(class) m(logit lassocv)

Cross-fitting and estimation, with short-stacking implemented via ddml.

. ddml crossfit, shortstack

. ddml estimate, robust

Compare the short-stacking estimation above with standard (within-cross-fit-fold) stacking:

. ddml estimate, spec(st) rep(1) replay notable

Short-stacking is typically considerably faster than standard stacking.
We can estimate using short-stacking only by specifying the nostd option when cross-fitting.
We re-set the seed for comparability.

. set seed 42

. ddml crossfit, shortstack nostdstack

. ddml estimate, robust