*! version 30aug2024

Partially-linear IV model - Basic example with various learners

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

. use https://statalasso.github.io/dta/AJR.dta, clear

. global Y logpgp95

. global D avexpr

. global Z logem4

. global X lat_abst edes1975 avelf temp* humid* steplow-oilres

. set seed 42

Preparation: we load the data, define global macros and set the seed. Since the
data set is very small, we consider 30 cross-fitting folds.

. ddml init iv, kfolds(30)

The partially linear IV model has three conditional expectations:
E[Y|X], E[D|X] and E[Z|X]. For each reduced form equation, we use two learners:
OLS and random forest.
To illustrate how ddml works with other packages,
instead of a single call to pystacked specifying two base learners
we specify Stata's regress and rforest by Zou and Schonlau as the two learners.
We need to add the option vtype(none) for rforest to
work with ddml since rforest's predict command doesn't
support variable types.

. ddml E[Y|X]: reg $Y $X

. ddml E[Y|X], vtype(none): rforest $Y $X, type(reg)

. ddml E[D|X]: reg $D $X

. ddml E[D|X], vtype(none): rforest $D $X, type(reg)

. ddml E[Z|X]: reg $Z $X

. ddml E[Z|X], vtype(none): rforest $Z $X, type(reg)

Cross-fitting and estimation; report all combinations of estimated conditional expectations.

. ddml crossfit, shortstack

. ddml estimate, robust allcombos