*! version 3august2023

Interactive IV model (LATE) - Basic example with pystacked

We use pystacked with two base learners for each reduced form equation.

. 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

Drop observations where treatment=1 even though assignment=0.
(Up to the user how to handle such observations;
ddml can handle these cases,
and we drop them here only to illustrate how this is reflected in the stacking weights.)

. tab $D $Z

. drop if $D==1 & $Z==0

Set the seed, initialize, cross-fit and estimate:

. set seed 42

. ddml init interactiveiv

. 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)

. ddml crossfit

. ddml estimate

Report the stacking weights.
Note that the weights for the non-existent case (treatment=1, assignment=0) are missing.

. ddml extract, show(stweights)