Estimation of pre- and posttreatment average treatment effects with binary time-varying treatment using Stata

In this article, we describe tvdiff, a community-contributed command that implements a generalization of the difference-in-differences estimator to the case of binary time-varying treatment with pre- and postintervention periods. tvdiff is flexible and can accommodate many actual situations, enabling the user to specify the number of pre- and postintervention periods and a graphical representation of the estimated coefficients. In addition, tvdiff provides two distinct tests for the necessary condition of the identification of causal effects, namely, two tests for the so-called parallel-trend assumption. tvdiff is intended to simplify applied works on program evaluation and causal inference when longitudinal data are available.