*! version 30aug2024

Interactive model - Detailed example with pystacked

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

. webuse cattaneo2, clear

. global Y bweight

. global D mbsmoke

. global X prenatal1 mmarried fbaby mage medu

. set seed 42

We use 5 folds and 5 resamplings; that is,
we estimate the model 5 times using randomly chosen folds.

. ddml init interactive, kfolds(5) reps(5)

We need to estimate the conditional expectations of E[Y|X,D=0],
E[Y|X,D=1] and E[D|X]. The first two conditional expectations
are added jointly.

We consider two supervised learners: linear regression and gradient boosted
trees, stacked using pystacked.
Note that we use gradient boosted regression trees for E[Y|X,D], but
gradient boosted classification trees for E[D|X].

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

. ddml E[D|X]: pystacked $D $X, type(class) methods(logit gradboost)

Cross-fitting and short-stacking:

. ddml crossfit, shortstack

In the final estimation step, we can estimate
the average treatment effect (the default),
the average treatment effect on the treated (atet),
or the average treatment effect on the untreated (ateu).

. ddml estimate

. ddml estimate, atet

. ddml estimate, ateu

Recall that we have specified 5 resampling iterations (reps(5))
By default, the median over short-stacked resampling iterations is shown.
At the bottom, a table of summary statistics over resampling iterations is shown.
To display the mean over standard stacking results, i.e.,
the results where the weights derive from pystacked and vary by cross-fit fold,
we use ddml estimate, replay with spec(st) and rep(mn).

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

Generate an overlap plot using ddml overlap:

. ddml overlap

Report the standard stacking and short-stacking weights:

. ddml extract, show(stweights)

. ddml extract, show(ssweights)