*! version 30aug2024

Partially-linear model - Multiple treatments with pystacked

We can also run the partially-linear model with multiple treatments.
In this simple example, we estimate the effect of both 401k elligibility
e401 and education educ.
Note that we remove educ from the set of controls.
We again use pystacked as the single learner provided to ddml;
the two base learners, OLS and random forest, are provided via pystacked.
We use the simplified syntax supported by pystacked.

. use https://github.com/aahrens1/ddml/raw/master/data/sipp1991.dta, clear

. global Y net_tfa

. global D1 e401

. global D2 educ

. global X tw age inc fsize db marr twoearn pira hown

. set seed 42

Initialize the model.

. ddml init partial, kfolds(2)

Add learners. Note that we add learners with both $D1 and
$D2 as the dependent variable.

. ddml E[Y|X]: pystacked $Y $X, type(reg) methods(ols rf)

. ddml E[D|X]: pystacked $D1 $X, type(reg) methods(ols rf)

. ddml E[D|X]: pystacked $D2 $X, type(reg) methods(ols rf)

Cross-fitting.

. ddml crossfit

Estimation.

. ddml estimate, robust

Because we have used pystacked as the single ddml learner,
we can access the saved pystacked information.
Here we use the pystacked option to get the stacking weights and MSEs by cross-fit fold:

. ddml extract, show(pystacked)