*! version 30aug2024

Flexible partially-linear IV model - Basic example with pystacked

First load the data, define global macros, set the seed and initialize the model.
We add learners for E[Y|X] in the usual way.
We illustrate with single pystacked estimations,
but the procedure applies to all learners.

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

. global Y share

. global D price

. global X hpwt air mpd space

. global Z sum*

. set seed 42

. ddml init fiv

Adding learners for E[Y|X] is the same as for other ddml linear models:

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

Adding learners for E[D|Z,X] and E[D|X] in the fiv model is different
from how it's done in the partialiv model.
The reason for this is that the estimation of E[D|X]
depends on the estimation of E[D|X,Z].

When adding learners for E[D|Z,X],
we need to provide a name for each learners using learner(name).
Here we use the name "Dhat_pys".

. ddml E[D|Z,X], learner(Dhat_pys): pystacked $D $X $Z, type(reg)

When adding learners for E[D|X], we explicitly refer to the name of the learner from
the previous step (here, "Dhat_pys").
We also provide the name of the treatment variable (vname($D)),
and we use the placeholder in place of the dependent variable.

. ddml E[D|X], learner(Dhat_pys) vname($D): pystacked $X, type(reg)

The crossfit and estimation commands with the fiv model are standard.

. ddml crossfit

. ddml estimate