Title

itsadgp -- Data generating process for interrupted time-series analysis

Syntax

itsadgp,
ntime(integer)
trperiod(integer)
intercept(#)
pretrend(#)
posttrend(#)
step(#)
[ sd(#)
rho(numlist)
seed(#) ]

* ntime(integer) specify the number of time periods in the series

* trperiod(integer) specify the time period when the intervention begins

* intercept(#) specify the starting value (intercept) of the time series

* pretrend(#) specify the trend (slope) of the time series prior to the intervention

* step(#) specify the change in the level of the time series immediately following the introduction of the intervention

* posttrend(#) specify the trend (slope) of the time series after introduction of the intervention

sd(#) specify the standard deviation used to generate the random error term(s); default is sd(1)

rho(numlist) specify the correlation coefficient(s) between adjacent (autoregressive) error terms

seed(#) sets the random-number seed to #

* ntime(), trperiod(), intercept(), pretrend(), posttrend(), step() are required.

Description

itsadgp generates artificial interrupted time series data using the specifications defined by the user -- including autoregressive terms (lags).
In the simplest case, the data generated by itsadgp could be used for simulating a single-group interrupted time series analysis. In a more complex
scenario, itsadgp could be implemented repeatedly using different specifications to generate data for simulating a multiple-group (treatment vs
control) interrupted time series analysis. While the most straightforward approach to analyzing the data generated by itsadgp is via the itsa
package (Linden 2015), other models, such as arima, can also be used for analyzing the generated data.

Note: itsadgp replaces the data in memory, so be sure to save your data!

Options

ntime(integer) specifies the number of time periods to generate in the series; ntime() is required.

trperiod(integer) specifies the time period when the intervention begins; trperiod() is required.

intercept(#) specifies the starting value of the time-series. In an ITSA regression model, this value would
represent the intercept; intercept() is required.

pretrend(#) specifies the pre-intervention trend (slope). In an ITSA regression model, this value would
represent the coefficient for t; pretrend() is required.

step(#) specifies the change in the level of the time-series in the period immediately following introduction
of the intervention. In an ITSA regression model, this value would represent the coefficient for x; step() is required.

posttrend(#) specifies the trend (slope) of the time-series following introduction of the intervention. In an ITSA
regression model, this value would be computed post-estimation as: t + xt
(where xt is an interaction between t and x); posttrend() is required.

sd(#) specifies the standard deviation used to generate the random error term(s): u_t = N(0,sd). A larger
sd will induce greater variability in the time-series; default is sd(1).

rho(numlist) specifies the correlation coefficient(s) between adjacent (autoregressive) error terms. For a first-order
autoregressive [AR(1)] process, the random-error term is computed as: epsilon_t = rho * epsilon_t-1 + u_t (equation 2 in [Linden 2015]).
The number of values specified in rho() indicates the number of lags of autocorrelation in the time-series, so that one value indicates 1 lag, two
values indicate 2 lags, etc. Most time-series follow an AR(1) process.

seed(#) sets the random-number seed.

Examples

In this example, we generate a time-series of 100 time points, with the intervention introduced
at the 50th time point. The starting value (intercept) is set to 10, the pre-intervention trend is
set to increase by 1 point every time period until the intervention starts, the level change (step) in
the first time period immediately following introduction of the intervention is set to 30 points,
and the trend following introduction of the intervention (posttrend) is set to increase by 5 points
every period. We also build in an autoregressive process with one lag (AR1) by setting rho
(the autocorrelation coefficient) to 0.50. We set the standard deviation used to generate the random
error term to 4, and we specify a seed to ensure replication.

. itsadgp, nt(100) trp(50) intercept(10) pre(1) post(5) step(30) sd(4) rho(.50) seed(12345)

We now analyze these data using itsa. The results in the regression table and post-trend table are close
to those used in the data generating process. This will naturally differ depending on how sd() and rho()
are specified.

. itsa y, single trperiod(50) posttrend fig lag(1)

Same as before but we now generate an AR2 (2 lags) process, where the first lag has autocorrelation
of 0.50 and the second lag has autocorrelation of 0.30. We follow up the data generating process with itsa.

. itsadgp, nt(100) trp(50) intercept(10) pre(1) post(5) step(30) sd(4) rho(.50 .30) seed(12345)

. itsa y, single trperiod(50) posttrend fig lag(2)

In this example, we generate a time-series based on the results from the single-group ITSA presented in Linden [2015],
(available in the itsa help file). We then estimate the treatment effects using itsa. The regression table and
posttrend table show similar results using our data generating process.

. itsadgp, ntime(31) intercept(132) pretrend(-1.78) posttrend(-3.27) step(-20) trperiod(19) sd(1) rho(0.5) seed(12345)

. itsa y, single trperiod(19) posttrend fig lag(1)

In this example, we generate data for a multi-group (treament vs control) time-series analysis. This is completed by generating a time series
separately for each group (in this example we'll have one treatment group and one control group), saving and then appending the datasets.
Finally, we estimate a model using itsa

. itsadgp, nt(100) trp(50) intercept(10) pre(1) post(5) step(30) sd(6) rho(.50) seed(12345)

. gen tx = 1

. tempfile tx1

. save `tx1'

. itsadgp, nt(100) trp(50) intercept(8) pre(1.3) post(2.5) step(10) sd(6) rho(.50) seed(12345)

. gen tx = 0

. append using `tx1'

. label define tx 1 "Treatment" 0 "Control", replace

. label values tx tx

. tsset tx t

. itsa y, treatid(1) trperiod(50) posttrend fig lag(1)

References

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

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

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

Citation of itsadgp

itsadgp 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. (2025). ITSADGP: Stata module to generate artificial data for interrupted time-series analysis.

Author

Ariel Linden

Linden Consulting Group, LLC

alinden@lindenconsulting.org

Help: itsa (if installed)