*! version 30aug2024

Interactive model - Basic example with pystacked

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 use 5 cross-fit folds and 2 resamplings
(more resamplings would be advisable; we use 2 in this example so the code runs faster).
We specify two supervised learners: linear regression and gradient boosted
trees, stacked using pystacked.
We use pystacked's 2nd syntax and stack using the single-best learner
(rather than the default constrained least squares).
Note that we use gradient boosted regression trees for E[Y|X,D],
but gradient boosted classification trees for E[D|X].

. webuse cattaneo2, clear

. global Y bweight

. global D mbsmoke

. global X prenatal1 mmarried fbaby mage medu

. set seed 42

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

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

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

. ddml crossfit

ddml estimate reports the ATE (average treatment effect) by default:

. ddml estimate

Request the ATET (average treatment effect on the treated) instead:

. ddml estimate, atet