*! 1.0.0 JDeutsch/MJacobus/AVigil 06feb2017

Title

rmpw -- Implement the RMPW method of causal mediation analysis to decompose treatment effects into "direct" and "indirect" effects.

Syntax

rmpw
(ovar
[covarsout])
(tvar)
(mvar
covarsprop)
[if] [in]
[weight]
[, options]

ovar is the outcome variable of interest.

covarsout is the (optional) covariate list for the outcome model.

tvar is a binary variable (only 0, 1, or missing) that represents the treatment (1) and control (0) groups.

mvar is a binary variable representing the mediator.

covarsprop is the covariate list for the propensity score model. Users are required to specify at least one (numeric) variable.

Main
psmodel(strings:string) Type of estimation for propensity score model (logit or probit; logit is default)

winitial(iwtype[, independent]) Specify initial weight matrix (winitial(unadjusted, independent) is default)

vce(vcetype) vcetype may be robust, cluster clustvar, bootstrap, or jackknife

quickderivatives Use alternative method of computing numerical derivatives for VCE

covarsout and covarsprop may contain factor variables; see fvvarlist.

aweights and pweights are allowed; see weight.

Description

This module implements the ratio-of-mediator-probability weighting (RMPW) method for causal mediation analysis to decompose
the treatment effect into "direct" and "indirect" effects. The indirect effect operates through a "mediator," which is a variable
that is affected by the treatment and in turn also has an effect on the outcome. The direct effect operates directly from the
treatment to the outcome, or operates through other unmeasured mediators.

RMPW is an approach for mediation analysis introduced by Hong (2010) and further developed by Hong and Nomi (2012) Tchetgen Tchetgen
and Shipster (2012), Hong (2015) Hong, Deutsch, and Hill (2015), and Bein et al. (2016). Huber (2014) and
Tchetgen Tchetgen (2013) proposed related strategies employing weights that are mathematically equivalent to RMPW. RMPW departs from
the SEM approach of mediation analysis of Baron and Kenny (1986) in that it does not involve modeling the outcome as a function
of the treatment and mediator, and thus avoids the assumptions necessary for identification of such models. It also allows for
treatment-by-mediator interaction effects.

The RMPW methodology is constructed for cases where treatment is randomized.
In its current incarnation, it is also designed for scenarios where treatment is binary AND the mediator is binary. Finally, causal
mediation analysis presumes that the treatment has an effect on the mediator; this module conducts a basic test of whether this condition
is met and issues a warning if it is not. However, it may be appropriate for the user to implement their own test of this conditon.

Direct and indirect effects from a potential outcomes framework.
Rather than the familiar formulation of potential outcomes that depend on (binary) treatment, Y(1) and Y(0), we can instead denote the potential
outcomes as a function of both the treatment and the mediator, which is in turn a function of the treatment:

Y(1,M(1)) and Y(0,M(0))

Note that these are the same two familiar potential outcomes, but written using different notation that will become useful.
Y(1,M(1)) is no different from the usual Y(1): the outcome if assigned to treatment. Likewise, Y(0,M(0)) is the same as Y(0).

We can imagine a third potential outcome: the outcome if assigned to the treatment group but counterfactually possessing the mediator
value that one would have under the control condition:

Y(1,M(0))

The direct effect is the effect of changing the treatment but leaving the mediator the same as what it would have been under the control condition:

Y(1,M(0))-Y(0,M(0))

Whereas the indirect effect operates only through the treatment-induced change in the mediator:

Y(1,M(1))-Y(1,M(0))

The total effect can be decomposed as the sum of the direct and indirect effects:

Y(1,M(1))-Y(0,M(0))=[Y(1,M(1))-Y(1,M(0))]+[Y(1,M(0))-Y(0,M(0))]

With random assignment of treatment, it is trivial to identify E[Y(1,M(1))] and E[Y(0,M(0))]. These are simply the treatment and control group means.
Additional assumptions and analytical methods are required to identify and estimate E[Y(1,M(0))].

The entire methodological challenge reduces to estimating E[Y(1,M(0))]. With the sequential ignorability assumption along with assumptions
that are trivially satisfied so long as treatment is randomized, we can show that:

E[WY|T=1] is an unbiased estimate of E[Y(1,M(0))] where:

W=pr(M=1|T=0,X)/pr(M=1|T=1,X) if T=1 and M=1;

W=pr(M=0|T=0,X)/pr(M=0|T=1,X) if T=1 and M=0

Note that pr(M=m|T=t,X) is a propensity score (or 1 minus a propensity score, in the case of pr(M=0|T=t,X)).
For example, the numerator of the first equation is the predicted probability from a propensity score model
where the outcome is the mediator (M), and predictors are covariates (X), and the model is fit using only the treatment group.

As an extension, the pure indirect effect can also be decomposed into the "pure" indirect effect:

Y(0,M(1))-Y(0,M(0))

And the treatment-by-mediator interaction effect:

[Y(1,M(1))-Y(1,M(0))] - [Y(0,M(1))-Y(0,M(0))]=

Y(1,M(1))+Y(0,M(0))-Y(1,M(0))-Y(0,M(1))

Notice that the sum of the "pure" indirect effect and the treatment-by-mediator interaction effect is equal to the indirect effect.

Since the direct and indirect effects are functions of weights which are themselves functions of estimated propensity scores, standard error
estimation requires accounting for the uncertainty in the estimation of the coefficients from the propensity score models. RMPW accomplishes
this by using generalized method of moments (Hansen, 1982), via the gmm command. In this way it is analogous to the teffects ipw command.

The outcome variable may be continuous or binary. If no independent variables are specified for the outcome model, the method resolves to estimating weighted
means and differences between those means. If independent variables are specified for the outcome model, they are assumed to be linearly related to the outcome.

Options

Main

psmodel(string) sets the type of estimation for the propensity score model. Users can choose either logit or probit. The default is logit if
this option is not specified.

winitial(iwtype[, independent]) specifies an initial weight matrix; iwtype may be unadjusted, identity,
xt xtspec, or the name of a Stata matrix. If users do not specify this option, the default is winitial(unadjusted, independent).
See gmm for more information on this option.

vce(vcetype) specifies the type of standard error reported, which
includes types that are robust to some kinds of misspecification (robust; the default), that allow
for intragroup correlation (cluster clustvar), and that use
bootstrap or jackknife methods (bootstrap, jackknife); see
[R] vce_option.

quickderivatives requests that an alternative method be used to compute
the numerical derivatives for the VCE. See gmm for more information on this option.

Remarks

Note that this command uses generalized method of moments estimation via the gmm command to estimate the standard error of the direct/indirect effects.
See gmm for more information on this type of estimation in Stata.

Examples

. rmpw (y) (treat) (med x1-x3)

. rmpw (y x1-x3) (treat) (med x1-x3)

. rmpw (y x1-x3) (treat) (med x1-x3), psmodel(probit)

. rmpw (y) (treat) (med x*), vce(cluster cid)

Stored results

rmpw retains all gmm stored results and adds the following results to e():

Scalars

e(itt_b) Intent-to-treat (ITT) effect, estimate

e(itt_se) Intent-to-treat (ITT) effect, standard error

e(de_b) Direct effect, estimate

e(de_se) Direct effect, standard error

e(ie_b) Indirect effect, estimate

e(ie_se) Indirect effect, standard error

e(pie_b) Pure indirect effect, estimate

e(pie_se) Pure indirect effect, standard error

e(txm_b) Treatment-by-mediator interaction effect, estimate

e(txm_se) Treatment-by-mediator interaction effect, standard error

Citation

Please cite this module as follows:

Mathematica Policy Research, Inc. under subcontract to MDRC and project sponsored by Grant #201500035 from the Spencer Foundation,
"RMPW: Stata module for causal mediation analysis using ratio-of-mediator-probability weights."
This version INSERT_VERSION_HERE.

Note that you can check your version using which:

. which rmpw

Acknowledgements

This program was supported by a subcontract to MDRC under Grant #201500035 from the Spencer Foundation entitled
"Using emerging methods with existing data from multi-site trials to learn about and from variation in education program effects."

Disclaimer

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

IN NO EVENT WILL THE COPYRIGHT HOLDERS, THEIR AGENTS, SUBCONTRACTORS OR EMPLOYEES, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
THIS SOFTWARE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.

Background Reading

Baron, R. M., & Kenny, D. A. (1986). "The moderator-mediator variable distinction in social psychological research: Conceptual, strategic, and statistical
considerations." Journal of Personality and Social Psychology, 51, 1173-1182.

Bein, E., Deutsch, J., Hong, G., Porter, K., Qin, X., and Yang, C. (2016). "Technical report on two-step estimation in RMPW analysis." Oakland, CA: MDRC.

Hansen, L. P. (1982). "Large sample properties of generalized method of moments estimators." Econometrica, 1029-1054.

Hong, G. (2010). "Ratio of mediator probability weighting for estimating natural direct and indirect effects." JSM Proceedings, Biometrics Section.
Alexandria, VA: American Statistical Association, pp. 2401-2415.

Hong, G., Deutsch, J., and Hill, H. D. (2015). "Ratio-of-mediator-probability weighting for causal mediation analysis in the presence of treatment-by-mediator
interaction." Journal of Educational and Behavioral Statistics, 40(3), 307-340.

Hong, G., and Nomi, T. (2012). "Weighting methods for assessing policy effects mediated by peer change." Journal of Research on Educational Effectiveness,
5(3), 261-289.

Hong, G. (2015). Causality in a social world: Moderation, mediation and spill-over. West Sussex, UK: John Wiley & Sons, Ltd.

Huber, M. (2014). "Identifying causal mechanisms (primarily) based on inverse probability weighting." Journal of Applied Econometrics, 29(6), 920-943.

Tchetgen Tchetgen, E. J. (2013). "Inverse odds ratio weighted estimation for causal mediation analysis." Statistics in Medicine, 32, 4567-4580.

Tchetgen Tchetgen, E. J., & Shpitser, I. (2012). "Semiparametric theory for causal mediation analysis: Efficiency bounds, multiple robustness and
sensitivity analysis." The Annals of Statistics, 40, 1816-1845.

Author

Jonah Deutsch

Mathematica Policy Research, Inc.

JDeutsch@mathematica-mpr.com

Matthew Jacobus (corresponding author)

Mathematica Policy Research, Inc.

MJacobus@mathematica-mpr.com

Alma Vigil

Mathematica Policy Research, Inc.

AVigil@mathematica-mpr.com