Title

xtitsa -- Interrupted time-series analysis for panel data

Syntax

xtitsa depvar [indepvars] [if] [in] [weight],
trperiod(datelist)
[options]

indepvars may contain factor variables; see fvvarlist.
depvar and indepvars may contain time-series operators; see
tsvarlist. iweight, fweight, and pweights are allowed; see weight.

The panel data must be strongly balanced and be declared to be time-series data by using either tsset panelvar timevar or xtset panelvar timevar. See tsset or xtset.

* trperiod(datelist) specify the time period(s) when the intervention begins (e.g. trperiod(2020) or trperiod(2001q2) or trperiod(21jan2020; 08feb2020))

single indicate that xtitsa will be used for a single-group analysis

treat(varname) specify the binary treatment group variable. Not required when only the treatment group is in the data
and single is specified

posttrend produce post-intervention trend estimates using lincom, for the specified model

prefix(string) add a prefix to the names of variables created by xtitsa. Short prefixes are recommended

replace replace variables created by xtitsa if they already exist

figure[(twoway_options)] plot the average actual and predicted depvar variable over time. Specifying figure without options uses the default graph settings

lowess plots a lowess smoothed line of depvar on timevar

ci plots the confidence interval(s) on the figure

shade(date1 ; date2) plot a shaded area on the figure between two dates, separated by a semicolon (e.g. shade(21jan2020 ; 08feb2020))

[model_options] specify all available options for xtgee

Description

xtitsa performs an interrupted times series analysis (ITSA) when individual-level
data are available for analysis (panel data). Conversely, itsa should be used
when only aggregated (pooled) data are available for analysis.

xtitsa estimates the effect of an intervention when the outcome variable
is ordered as an evenly-spaced time series and a number of observations are available
in both preintervention and postintervention periods. The study design is
referred to as an interrupted time-series analysis because the
intervention is expected to interrupt the level or trend subsequent to its
introduction (Campbell and Stanley 1966; Glass, Willson, and Gottman 1975;
Shadish, Cook, and Campbell 2002).

xtitsa estimates treatment effects for either a single-group
(i.e., the treatment group with preintervention and postintervention observations)
or a multiple-group comparison (that is, the treatment group is compared with a
control group). Additionally, xtitsa can estimate treatment effects for
multiple treatment periods. xtitsa is a wrapper for xtgee so
all available options are allowed except "eform".

Options

trperiod(datelist) specifies the time period when the
intervention begins. The value(s) entered for time period(s) must be in the same
units as the panel time variable specified in tsset timevar; see
tsset. Dates should be specified as human readible dates using the respective
pseudofunction (see datetime), such as trperiod(2020)
for a four-digit year, or trperiod(2019m11) for quarterly data.
Multiple periods may be specified, separated by a semicolon, as follows
trperiod(2019m6; 2019m11); trperiod() is required.

single indicates that xtitsa will be used for a single-group
analysis. Conversely, omitting single indicates that xtitsa is for
a multiple-group comparison.

treat(varname) indicates the binary treatment variable (where the control group
is equal to 0 and the treatment group is equal to 1). When the dataset contains data for
only the treatment group, treat() must be omitted.

posttrend produces posttreatment trend estimates using lincom,
for the specified model. In the case of a single-group ITSA, one estimate is
produced. In the case of a multiple-group ITSA, an estimate is produced for
the treatment group, the control group, and the difference. In the case of
multiple treatment periods, a separate table is produced for each treatment
period.

prefix(string) adds a prefix to the names of variables
created by xtitsa. Short prefixes are recommended.

replace replaces variables created by xtitsa if they already exist.
If prefix() is specified, only variables created by xtitsa with the
same prefix will be replaced.

figure[(twoway_options)] produces
a line plot of the average predicted depvar variable combined with a scatterplot
of the average actual values of depvar over time. Specifying figure
without options uses the default graph settings.

lowess plots a lowess smoothed line of depvar on timevar.

ci plots the confidence interval(s) on the figure. By default,
95% CIs are presented but can be changed by specifying level() as
a model option.

shade(date1 ; date2) plots a shaded area on the figure
between two dates, specified by the user and separated by a semicolon. The values
entered for time periods must be in the same units as the panel time variable
specified in tsset. Dates should be specified using the respective
pseudofunction (see datetime), such as shade(2020 ; 2021)
for a four-digit year, shade(2019m11 ; 2020m3) for quarterly data or
shade(20jan2021 ; 30jan2021) for daily data. Shading may be helpful to
highlight a "washout" period before introduction of the intervention, or
to highlight some other event worthy of note.

model_options specify all available options for xtgee.

Remarks

Regression (with methods to account for autocorrelation) is the most commonly
used modeling technique in interrupted time-series analyses. When there is
only one group under study (no comparison groups), the regression model
assumes the following form (Simonton 1977a, 1977b; Huitema and McKean 2000;
Linden 2015):

Y_t = Beta_0 + Beta_1(T) + Beta_2(X_t) + Beta_3(TX_t) (1)

Here Y_t is the aggregated outcome variable measured at each equally spaced
time point t, T is the time since the start of the study, X_t is a dummy
(indicator) variable representing the intervention (preintervention periods 0,
otherwise 1), and TX_t is an interaction term.

In the case of a single-group study, Beta_0 represents the intercept or
starting level of the outcome variable. Beta_1 is the slope or trajectory of
the outcome variable until the introduction of the intervention. Beta_2
represents the change in the level of the outcome that occurs in the period
immediately following the introduction of the intervention (compared with the
counterfactual). Beta_3 represents the difference between preintervention and
postintervention slopes of the outcome. Thus we look for significant p-values
in Beta_2 to indicate an immediate treatment effect, or in Beta_3 to indicate
a treatment effect over time (Linden 2015). However, single-group
ITSA models may provide misleading results, so multiple-group ITSA models
should be implemented whenever possible (Linden 2017b and 2017c).

When a control group is available for comparison, the regression
model in (1) is expanded to include four additional terms (Beta_4 to Beta_7)
(Simonton 1977a, 1977b; Linden 2015):

Y_t = Beta_0 + Beta_1(T) + Beta_2(X_t) + Beta_3(TX_t) +
Beta_4(Z) + Beta_5(ZT) + Beta_6(ZX_t) + Beta_7(ZTX_t) (2)

Here Z is a dummy variable to denote the cohort assignment (treatment or
control), and ZT, ZX_t, and ZTX_t are all interaction terms among previously
described variables. Now the coefficients Beta_0 to Beta_3 represent the
control group, and the coefficients Beta_4 to Beta_7 represent values of the
treatment group. More specifically, Beta_4 represents the difference in the
level (intercept) of the dependent variable between treatment and controls
prior to the intervention, Beta_5 represents the difference in the slope
(trend) of the dependent variable between treatment and controls prior to the
intervention, Beta_6 indicates the difference between treatment and control
groups in the level of the dependent variable immediately following
introduction of the intervention, and Beta_7 represents the difference between
treatment and control groups in the slope (trend) of the dependent variable
after initiation of the intervention compared with preintervention (akin to a
difference-in-differences of slopes).

The two parameters Beta_4 and Beta_5 play a particularly important role in
establishing whether the treatment and control groups are balanced on both the
level and the trajectory of the dependent variable in the preintervention
period. If these data were from a randomized controlled trial, we would
expect similar levels and slopes prior to the intervention. However, in an
observational study where equivalence between groups cannot be ensured, any
observed differences will likely raise concerns about the ability to draw
causal inferences about the relationship between the intervention and the
outcomes (Linden 2015). See Linden (2017a) for many
additional ITSA postestimation measures.

Examples

There are three general scenarios in which xtitsa can be implemented: 1) a
single-group ITSA when the dataset contains data for the treatment group only,
2) a single-group ITSA in a dataset where there are also other data, and
3) a multiple-group ITSA:

1) Single-group ITSA (treatment group only)

Load data and declare the dataset as time series:

. use xtitsa_example_single.dta, clear

. tsset id month

We specify a single-group ITSA with period 2019m11 as the start of the intervention.
We then plot the results and produce a table of the posttreatment trend estimates.

. xtitsa y, single trperiod(2019m11) vce(robust) posttrend figure

We now generate residuals and test them for autocorrelation using actest with the robust option.

. gen resid = y - _s__y_pred

. actest resid, lags(12) robust

We see from the output that there is autocorrelation up to lag 9, so we reestimate the model specifying an autoregressive correlation and add a lowess smoother to the graph.

. xtitsa y, single trperiod(2019m11) vce(robust) posttrend figure replace corr(ar 9) low

We specify two treatment periods and shade the area between them

. xtitsa y, single trperiod(2019m9 ; 2019m11) shade(2019m9 ; 2019m11) vce(robust) fig repl corr(ar 9) low

We specify a single-group ITSA for a fractional response (i.e. 0 to 1.0 scale) with family(binomial) and vce(robust) and add CIs to the graph.

. xtitsa y01, single trperiod(2019m11) family(binomial) vce(robust) figure posttr replace ci

2) Single-group ITSA in dataset with other data

Load multiple-panel data and declare the dataset as panel:

. use xtitsa_example.dta, clear

. tsset id month

We specify a single-group ITSA with the variable z as the treatment group
and period 2019m11 as the start of the intervention, plot
the results, and produce a table of the posttreatment trend estimates.

. xtitsa y, single treat(z) trperiod(2019m11) vce(robust) posttrend figure replace

Same as above, but we add a lowess smoother to the graph.

. xtitsa y, single treat(z) trperiod(2019m11) vce(robust) posttrend figure replace low

Same as above, but we add a confidence interval to the graph.

. xtitsa y, single treat(z) trperiod(2019m11) vce(robust) posttrend figure replace ci

We now specify corr(ar 9) to fit an AR(9) model and add a confidence interval to the graph.

. xtitsa y, single treat(z) trperiod(2019m11) vce(robust) posttrend figure replace corr(ar 9) ci

Here we specify two treatment periods, 2019m6 and 2019m11, shade the area between them on the graph, and add a lowess smoother.

. xtitsa y, single treat(z) trperiod(2019m6; 2019m11) shade(2019m6; 2019m11) vce(robust) posttr repl fig low

We specify a single-group ITSA for a fractional response (i.e. 0 to 1.0 scale) with family(binomial) and vce(robust) and add CIs to the graph.

. xtitsa y01, single treat(z) trperiod(2019m11) family(binomial) vce(robust) figure posttr replace ci

3) Multiple-group ITSA (treatment vs control)

We specify a multiple-group ITSA by omitting single. The variable z includes both treatment and control observations.

. xtitsa y, treat(z) trperiod(2019m11) vce(robust) posttrend figure replace

Same as above, but we add confidence intervals to the graph.

. xtitsa y, treat(z) trperiod(2019m11) vce(robust) posttrend figure replace ci

Here we add another treatment period and shade the area between them on the graph. We also add confidence intervals.

. xtitsa y, treat(z) trperiod(2019m9 ; 2019m11) shade(2019m9 ; 2019m11) vce(robust) posttr fig repl ci

Here we add a covariate x to the model and specify that estimates be computed at the 99% level. We also add CIs to the graph. One can see that, with the addition of covariates, the estimates are no longer linear.

. xtitsa y x, treat(z) trperiod(2019m11) vce(robust) posttrend figure replace ci level(99)

We specify a multiple-group ITSA for a fractional response (i.e. 0 to 1.0 scale) with family(binomial) and vce(robust) and add lowess smoothers to the graph.

. xtitsa y01, treat(z) trperiod(2019m11) family(binomial) vce(robust) figure replace low

Same as above but we specify that CIs should be presented on the graph

. xtitsa y01, treat(z) trperiod(2019m11) family(binomial) vce(robust) figure replace ci

Output table

xtitsa produces several variables, as defined under Remarks above.
Below is a cross reference to default names for those variables that appear in
the regression output tables (and used when posttrend is specified).
Variables starting with _z are added to the dataset only when a
multiple-group comparison is specified. (trperiod) is a suffix added to
certain variables indicating the start of the intervention period. This is
particularly helpful for differentiating between added variables when multiple
interventions are specified. If the user specifies a prefix(), it will
be applied to all variables generated by xtitsa.

Variable Description

_depvar dependent variable

_t time since start of study

_x(trperiod) dummy variable representing the intervention periods (preintervention periods 0, otherwise 1)

_x_t(trperiod) interaction of _x and _t

_z dummy variable to denote the cohort assignment (treatment or control)

_z_x(trperiod) interaction of _z and _x

_z_x_t(trperiod) interaction of _z, _x, and _t

_s_depvar_pred predicted value generated after running xtitsa for a single group

_m_depvar_pred predicted value generated after running xtitsa for a multiple-group comparison

Acknowledgments

I thank Kit Baum for assisting with the actest specification.

References

Campbell, D. T., and J. C. Stanley. 1966.
Experimental and Quasi-Experimental Designs for Research.
Chicago: Rand McNally.

Glass, G. V., V. L. Willson, and J. M. Gottman. 1975.
Design and Analysis of Time-Series Experiments.
Boulder, CO: Colorado Associated University Press.

Huitema, B. E., and J. W. McKean. 2000.
Design specification issues in time-series intervention models.
Educational and Psychological Measurement
60: 38-58.

Linden, A. 2015.
Conducting interrupted time series analysis for single and multiple group comparisons.
Stata Journal.
15: 480-500.

------. 2017a.
A comprehensive set of postestimation measures to enrich interrupted time-series analysis.
Stata Journal
17: 73-88.

------. 2017b.
Challenges to validity in single-group interrupted time series analysis.
Journal of Evaluation in Clinical Practice.
23: 413-418.

------. 2017c.
Persistent threats to validity in single-group interrupted time series analysis with a crossover design.
Journal of Evaluation in Clinical Practice.
23: 419-425.

------. 2022.
Erratum: A comprehensive set of postestimation measures to enrich interrupted time-series analysis.
Stata Journal
22: 231-233.

Linden, A., and J. L. Adams. 2011.
Applying a propensity-score based weighting model to interrupted time
series data: Improving causal inference in program evaluation.
Journal of Evaluation in Clinical Practice
17: 1231-1238.

Linden, A., and P. R. Yarnold. 2016.
Using machine learning to identify structural breaks in single-group
interrupted time series designs.
Journal of Evaluation in Clinical Practice
22: 855-859.

Shadish, S. R., T. D. Cook, and D. T. Campbell. 2002.
Experimental and Quasi-Experimental Designs for Generalized Causal Inference.
Boston: Houghton Mifflin.

Simonton, D. K. 1977a.
Cross-sectional time-series experiments: Some suggested statistical analyses.
Psychological Bulletin
84: 489-502.

Simonton, D. K. 1977b. Erratum to Simonton. Psychological Bulletin
84: 1097.

Citation of xtitsa

xtitsa is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden A. (2021). XTITSA: Stata module to perform interrupted time-series analysis with panel data.
Statistical Software Components S458903, Boston College Department of Economics.
https://ideas.repec.org/c/boc/bocode/s458903.html

Author

Ariel Linden

Linden Consulting Group, LLC

alinden@lindenconsulting.org

Help: actest (if installed), itsa (if installed), xtgee, lincom