*! version 1.3.23 17jul2026

help for kypshift

Title

kypshift - Testing shifts between I(1) and I(0) regimes at unknown dates
(Kejriwal-Yu-Perron 2020)

Syntax

kypshift varname [if] [in] [, options]

maxbreaks(#) maximum number of persistence breaks, between 2 and 5;
default is maxbreaks(5)

trim(#) trimming fraction for the minimum regime length; default is
trim(0.15)

eta(#) significance level of the sequential procedure; default is
eta(0.10)

bicmaxlag(#) maximum lag order considered by the BIC; default is
bicmaxlag(8)

reps(#) number of wild bootstrap replications; default is
reps(400)

seed(#) set the Stata random-number seed before drawing the bootstrap
weights

pmseed(#) use the deterministic Park-Miller replication stream with the
given seed instead of Stata draws; see Validation below

nodots suppress the progress dots

asympcv also report the Kejriwal-Perron-Zhou (2013) and Bai-Perron
(1998, 2003) asymptotic critical values with the KPZ hybrid decision; requires
trim(0.15)

The variable must contain the series of interest itself (for example an inflation
rate); kypshift does not transform the data. The data must be tsset
without gaps in the estimation sample.

Description

kypshift detects multiple shifts in the persistence of a univariate time
series, that is, changes between unit root I(1) and stationary I(0) regimes in
either direction, under heteroskedasticity of unknown form.
Both the number of breaks and their dates are treated as unknown. The command
implements the bootstrap procedures of Kejriwal, Yu and Perron (2020) built on the
sup-Wald statistics of Kejriwal, Perron and Zhou (2013); the statistical background
and the division of labor between the two articles are laid out in the next
section.

A single run reports, in order: the full-sample stability tests (the directional
statistics sup F1a(k) and sup F1b(k), their maximum W1(k), the G statistics, and
the Wmax/UDmax hybrid decision with bootstrap p-values); optionally the KPZ
asymptotic critical values (asympcv); the sequential estimation of the number
of breaks with the selected break dates; and the diagnostics of Tables I and II of
the 2020 article (pure mean shift Wald test, largest AR coefficient sum with its
Andrews-Guggenberger band, the selected model label, the Cavaliere-Taylor ratio and
ADF tests, and the regime-wise persistence table when persistence breaks are
found). All displayed quantities are returned in r().

The two articles behind the command

Kejriwal, Perron and Zhou (2013, Econometric Theory) - the statistics:

- proposes the sup-Wald tests used throughout the command: the directional
statistics sup F1a(k) (unit root in odd regimes under the alternative) and
sup F1b(k) (unit root in even regimes), their maximum W1(k) for the case of unknown
direction, and Wmax for an unknown number of breaks [KPZ]

- computes them from the regression of the first difference on a
constant, the lagged level and lagged differences, under the Model 1a and Model 1b
restrictions, using the restricted dynamic programming of Perron and Qu
(2006) [KPZ]

- proves (Theorem 3) that each directional test is inconsistent against
the other direction, so the pair identifies whether the series starts I(1) or
I(0) [KPZ]

- tabulates asymptotic critical values (Table 1; homoskedastic errors,
15 percent trimming) [KPZ]

- proposes, in its Section 4, the hybrid decision rule that gives the W
tests their interpretation: because the W tests reject with probability one in
large samples even when the process is stable I(0), the article pairs them with
the Bai-Perron structural change tests and rejects the null that the process is
stable I(1) or stable I(0) only when both tests reject at the chosen significance
level; the asymptotic size of this rule is bounded by that level and the rule is
consistent against processes that switch between I(1) and I(0) regimes. With the
number of breaks unknown, Wmax is paired with UDmax [KPZ]

- leaves two questions open: inference under heteroskedasticity, and the
estimation of the number of breaks [answered by KYP]

Kejriwal, Yu and Perron (2020, JTSA) - the procedure:

- replaces the asymptotic critical values with a wild bootstrap that
stays valid under heteroskedasticity: I(1) bootstrap samples are
built by cumulating sign-flipped residuals and I(0) samples by sign-flipping
residuals directly, with Rademacher weights, and each family of statistics is
compared with its own bootstrap distribution [KYP]

- pairs the W statistics with the G statistics of the Bai and Perron
(1998, 2003) framework in the hybrid Wmax/UDmax decision: the stability null is
rejected only if both families reject, with joint p-value p* = max(p(Wmax),
p(UDmax)) [KYP]

- estimates the number of breaks sequentially: if p* exceeds
eta(#) the series is judged stable; otherwise, for each candidate number of
breaks i the dates are estimated by minimizing the sum of squared residuals, the
one-break tests are applied within each of the i+1 regimes, and the procedure
stops at the first i whose minimum regime p-value exceeds the Bonferroni-adjusted
threshold [KYP]

- selects the autoregressive lag order by BIC with maximum
bicmaxlag(#), exactly as in the authors' code: a full-sample selection for
the stability tests and a dating-based selection for each candidate partition; all
bootstrap statistics use an AR(1) specification as recommended in the
article [KYP]

- provides the empirical diagnostics of its Tables I and II (mean shift
Wald test, regime AR sums, AG bands, CT tests) [KYP]

What KPZ (2013) concretely adds to kypshift, and why it is useful:

- The sup F1a(k) and sup F1b(k) columns of the full-sample table and the
matrices r(f1a), r(f1b). Always reported, no option needed. Advantage:
the direction of the persistence change is read from the tests themselves, before
any break date is estimated; the KYP output collapses the two into their maximum
and loses this information at the test level.

- The asympcv option, which displays the KPZ Table 1 critical
values (10, 5, 2.5 and 1 percent) next to sup F1a(k), sup F1b(k), W1(k) and Wmax
and returns them in r(cvf1a), r(cvf1b), r(cvw1), r(cvwmax).
Two advantages: it is the only formal inference available for the directional
components, since the KYP bootstrap does not produce p-values for them; and it
gives a fast bootstrap-free assessment when the errors are plausibly homoskedastic.
It requires trim(0.15) and should be read with the homoskedasticity caveat
printed below the table; under heteroskedasticity the bootstrap p-values remain
the primary evidence.

- The asymptotic hybrid decision printed at the bottom of the
asympcv table: Wmax and UDmax are compared with the KPZ and the Bai-Perron
(1998, 2003) critical values and the reported decision is the smallest tabulated
level at which both reject. This is the Section 4 rule of KPZ (2013) in its
original asymptotic form; table [1] of the output applies the same rule with wild
bootstrap p-values through p* = max(p(Wmax), p(UDmax)), which is the KYP (2020)
operationalization of the same idea.

Everything else in the command implements KYP (2020).

Choosing the options

The defaults replicate the empirical configuration of the article (Section 8), which
uses maxbreaks(5), trim(0.15), eta(0.10), bicmaxlag(8) and 400
bootstrap replications on monthly inflation series with T = 581. Larger reps(#)
values sharpen the bootstrap p-values at a proportional cost in time. The trimming
fraction fixes the minimum admissible regime length at round(trim x T) effective
observations; lowering it admits shorter regimes but weakens the within-regime tests.

Runtime grows roughly with the square of the sample size and linearly in
reps(#). As a reference point, a series with T = 581 and reps(400) takes
about five minutes. Progress dots are displayed by default, one per bootstrap
replication.

If a candidate partition produces a regime whose minimum segment length
round(trim x T_regime) falls below the number of regressors (2 plus the selected
lag order), the dynamic programming initializations rely on nearly singular designs.
The original MATLAB code proceeds through such inversions and MATLAB prints its own
console warning; kypshift does the same and prints an equivalent warning once
per run. In that situation consider reducing bicmaxlag(#). The same caution
applies to the bootstrap ADF tests of the regime table when a regime is very short
(roughly below 45 observations): their internal lag selection then operates on
nearly singular designs and the resulting p-values should not be taken at face
value. kypshift sorts the data by the tsset time variable before
estimation, so results do not depend on the current sort order of the dataset.

Datasets used in the examples

All example datasets are hosted at
https://www.eruygurakademi.com/datasets/kypshift/ and can be loaded
directly with use. kyp_oecd.dta contains the empirical data of the
article: monthly CPI inflation rates (1200 times the log difference of the CPI) for
19 OECD countries, 1960m2-2008m6, T = 581, built from the data file distributed with
the authors' replication code; the time variable is mdate. The files
kypsynth_a.dta to kypsynth_f.dta are synthetic series with known
properties, used both below and in the validation of the package: kypsynth_a
has a single I(0)-to-I(1) persistence shift, kypsynth_b has two persistence
shifts, kypsynth_c is I(0) with a pure mean shift, kypsynth_e is stable
white noise with no break, and kypsynth_f is a stable autocorrelated series
whose BIC lag selection is positive. Their time variable is t.

Examples

Example 1: a first run on a series with one persistence shift. The series
switches from a stationary AR(1) to a unit root process at observation 100. With
200 bootstrap replications the run takes a few seconds and the output shows the
full-sample stability tests, the sequential procedure and the Table I diagnostics.

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_a.dta, clear

. kypshift y, bicmaxlag(5) reps(200) seed(1000)

Example 2: replicating the Austria row of Table I of the article. The
configuration below is the one used in Section 8 of the article. The defaults
already set maxbreaks(5), trim(0.15) and eta(0.10), so only the lag bound, the
replications and the seed are given. Expected output: one persistence break dated
1969m7; pure mean shifts not rejected (robust Wald 0.22 against the 10 percent
critical value 2.71, hence "Yes" in column 4); largest AR coefficient sum 0.65 with
BIC lag 11; AG 90 percent band [0.47, 0.87]; selected model "I(0) with 1 mean
shift(s)". These match Table I digit for digit because all of these quantities are
deterministic given the selected break; the runtime is about five minutes. The
bootstrap p-values, in contrast, are expected to match the article only up to
Monte Carlo error (roughly plus or minus 0.02 at 400 replications), since the
authors' own pipeline reseeds from the clock on every run and its exact draws
cannot be reproduced by anyone, including the authors.

. use https://eruygurakademi.com/datasets/kypshift/kyp_oecd.dta, clear

. kypshift austria, bicmaxlag(8) reps(400) seed(12345)

Example 3: a country with a genuine persistence break and the Table II regime
table. For Belgium the article reports one persistence break with regime
sequence I(0)-I(1). Because the mean shift hypothesis is rejected, kypshift
prints the regime-by-regime persistence table (AR sum, AG band, bootstrap ADF
p-value and BIC lag for each regime), the counterpart of Table II of the article.

. use https://eruygurakademi.com/datasets/kypshift/kyp_oecd.dta, clear

. kypshift belgium, bicmaxlag(8) reps(400) seed(12345)

Example 4: controlling the search with maxbreaks(), trim() and eta(). A
smaller maxbreaks(#) restricts the alternative space and shortens the run
roughly in proportion; a larger trim(#) forces longer regimes, which
stabilizes the within-regime tests but rules out breaks close together or close to
the sample ends; a smaller eta(#) makes the sequential procedure stop earlier
and select fewer breaks.

. use https://eruygurakademi.com/datasets/kypshift/kyp_oecd.dta, clear

. kypshift france, maxbreaks(2) bicmaxlag(8) reps(400) seed(2)

. kypshift france, trim(0.20) bicmaxlag(8) reps(400) seed(2)

. kypshift france, eta(0.05) bicmaxlag(8) reps(400) seed(2)

Example 5: reproducibility with seed(). Two runs with the same seed give
identical output to the last digit; without seed(#) the current state of the
Stata random-number generator is used, so results differ across runs. This is a
deliberate improvement over the authors' pipeline, which reseeds from the clock.

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_a.dta, clear

. kypshift y, bicmaxlag(5) reps(200) seed(42)

. kypshift y, bicmaxlag(5) reps(200) seed(42)

Example 6: multiple breaks and deep sequential search. On the two-shift
series the sequential procedure explores partitions with up to five breaks; the
candidate dates for every depth are stored in r(tmpnt) and the full p-value
matrix in r(pvall). A small reps(#) is used here only to keep the demo
fast; use several hundred replications in real work.

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_b.dta, clear

. kypshift y, bicmaxlag(2) reps(100) seed(7)

. matrix list r(tmpnt)

. matrix list r(pvall)

Example 7: the no-break and pure mean shift cases. On the stable series the
procedure selects zero breaks, the AG band on the full-sample AR sum determines the
I(0) or I(1) label in column 7, and the regime table is reported as not applicable.
On the mean shift series one break is found but the robust Wald test does not
reject pure mean shifts, so the model label is "I(0) with 1 mean shift(s)".

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_e.dta, clear

. kypshift y, bicmaxlag(5) reps(200) seed(3)

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_c.dta, clear

. kypshift y, bicmaxlag(5) reps(200) seed(4)

Example 8: the deterministic replication stream pmseed(). With pmseed(#)
the wild bootstrap weights come from a Park-Miller stream that is bit-identical to
the one used by the Octave reference programs in the validation package, so the
entire run is reproducible across software. The seeds below reproduce the shipped
reference outputs for the validation series (see the Validation section).

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_a.dta, clear

. kypshift y, bicmaxlag(5) reps(10) pmseed(20260709)

Example 9: directional components and asymptotic critical values. The
asympcv option compares sup F1a(k), sup F1b(k), W1(k) and Wmax with the KPZ
(2013) asymptotic critical values at the 10, 5, 2.5 and 1 percent levels. On the
kypsynth_a series (I(0) followed by I(1)) sup F1a rejects while sup F1b does not,
identifying the first regime as I(0) in line with KPZ Theorem 3.

. use https://eruygurakademi.com/datasets/kypshift/kypsynth_a.dta, clear

. kypshift y, bicmaxlag(5) reps(200) seed(1000) asympcv

. matrix list r(f1a)

. matrix list r(cvwmax)

Example 10: using the stored results. All displayed quantities are returned in
r(); the break count, the dates, the Table I diagnostics and the regime table
can be picked up programmatically after the run.

. use https://eruygurakademi.com/datasets/kypshift/kyp_oecd.dta, clear

. kypshift austria, bicmaxlag(8) reps(400) seed(12345)

. return list

. display r(nb) " break(s), model: " r(selmodel)

. display "AG band: [" %5.2f r(aglow) ", " %5.2f r(agup) "]"

Remarks on the relation to the published article

kypshift is a port of the authors' MATLAB program detnumbreak.m
distributed with the article. Where the code and the text of the article differ, the
port follows the code, since the code is what generated the published empirical
results. Three such differences were found and are documented here for transparency.

First, the G statistic in the code normalizes the difference in sums of squared
residuals by 2k, the number of restricted parameters with k breaks, while equation (5)
of the article shows k. The bootstrap critical values are computed with the same
formula, so p-values and all decisions are unaffected by the scaling.

Second, when testing the partition with i estimated breaks the code compares the
minimum regime p-value with 1-(1-eta)^(1/i), while Section 5.3 of the article states
the threshold 1-(1-eta)^(1/(l+1)) for the test of l against l+1 breaks. The port
follows the code.

Third, the I(1) bootstrap samples in the code initialize the pre-sample values at
zero, while step (3) of the bootstrap algorithm in the article carries over the
observed values of the series. Because the test regressions include regime intercepts,
the statistics are invariant to this level difference.

A further remark concerns reproducibility of the original program: its bootstrap loop
reseeds the random-number generator on every call and runs under parfor, so two runs
of the authors' pipeline generally give different p-values. kypshift with
seed(#) is exactly reproducible from run to run.

Validation

The port was validated against a deterministic Octave reference built from the
authors' MATLAB code, modified only by removing parallelism and reseeding and by
replacing the Rademacher generator with a Park-Miller stream that is bit-identical
across platforms. Feeding the same stream to both engines makes the entire pipeline
deterministic, so every intermediate and final quantity can be compared digit by
digit. Across four synthetic configurations covering every code branch (all sequential
depths, the persistence, pure mean shift and no-break cases, the CT tests and the
regime table), more than 400 logged quantities (test statistics, every bootstrap
statistic, critical values, p-values, candidate break dates, regression
coefficients, standard errors, confidence bands and the selected number of breaks)
agree between the Octave reference and kypshift with a worst relative
difference of 1.4e-12. The only exclusion is the bootstrap ADF p-value inside
regimes shorter than about 45 observations, where the computation is nearly
singular and engines legitimately differ; this region is flagged by the runtime
warning described above.

The option pmseed(#) activates the same Park-Miller stream in kypshift, so
these comparisons can be reproduced independently. The reference programs, the
synthetic series and the reference outputs are available at
https://eruygurakademi.com/datasets/kypshift/kypshift_octave_validation.zip.

Stored results

kypshift stores the following in r():

Scalars

r(nb) selected number of persistence breaks

r(T) sample size

r(wmax) Wmax statistic

r(udmax) UDmax statistic

r(pvw) bootstrap p-value of Wmax

r(pvbp) bootstrap p-value of UDmax

r(pv) joint p-value, max of the two

r(cvw) bootstrap critical value of Wmax at level eta

r(cvbp) bootstrap critical value of UDmax at level eta

r(hstat) hybrid Hmax statistic

r(optlag0) BIC lag order selected on the full sample

r(reps) number of bootstrap replications

r(eta) significance level

r(trim) trimming fraction

r(maxlag) maximum BIC lag order

r(maxbreaks) maximum number of breaks

r(meanwald) robust Wald test of pure mean shifts

r(meanwaldcv) its chi-squared 10 percent critical value

r(meanshift) 1 if pure mean shifts are not rejected, 0 otherwise

r(arsum) largest regime-wise AR coefficient sum

r(aglow) lower end of the AG 90 percent band

r(agup) upper end of the AG 90 percent band

r(adfp) CT bootstrap ADF p-value, demeaned

r(adfptrend) CT bootstrap ADF p-value, detrended

r(ctk1) CT ratio statistic K1

r(ctk1p) CT ratio statistic K1-prime

r(ctk4) CT ratio statistic K4

r(ctpv1) bootstrap p-value of K1

r(ctpv2) bootstrap p-value of K1-prime

r(ctpv3) bootstrap p-value of K4

Macros

r(selmodel) selected model label, column 7 of Table I

r(ctmodel) CT selection label, column 8 of Table I

Matrices

r(table2) regime-wise AR sums, AG bands, ADF p-values and lags

r(regmodel) regime-wise I(0)/I(1) indicators

r(wstats) W statistics for 1 to maxbreaks breaks

r(bpstats) G statistics for 1 to maxbreaks breaks

r(f1a) sup F1a statistics for 1 to maxbreaks breaks

r(f1b) sup F1b statistics for 1 to maxbreaks breaks

r(cvf1a) KPZ asymptotic critical values for sup F1a (with asympcv)

r(cvf1b) KPZ asymptotic critical values for sup F1b (with asympcv)

r(cvw1) KPZ asymptotic critical values for W1(k) (with asympcv)

r(cvwmax) KPZ asymptotic critical values for Wmax (with asympcv)

r(cvg1) Bai-Perron critical values for G1(k) (with asympcv)

r(cvudmax) Bai-Perron critical values for UDmax (with asympcv)

r(pvall) full matrix of bootstrap p-values of the sequential
procedure

r(tmpnt) estimated break dates (observation indices) for each candidate
number of breaks

References

Bai, J., and P. Perron. 1998. Estimating and testing linear models with multiple
structural changes. Econometrica 66: 47-78.

Bai, J., and P. Perron. 2003. Computation and analysis of multiple structural change
models. Journal of Applied Econometrics 18: 1-22.

Andrews, D. W. K., and P. Guggenberger. 2014. A conditional-heteroskedasticity-robust
confidence interval for the autoregressive parameter. Review of Economics and
Statistics 96: 376-381.

Cavaliere, G., and A. M. R. Taylor. 2008. Testing for a change in persistence in the
presence of non-stationary volatility. Journal of Econometrics 147: 84-98.

Cavaliere, G., and A. M. R. Taylor. 2009. Bootstrap M unit root tests. Econometric
Reviews 28: 393-421.

Kejriwal, M. 2020. A robust sequential procedure for estimating the number of
structural changes in persistence. Oxford Bulletin of Economics and Statistics
82: 669-685.

Kejriwal, M., P. Perron, and J. Zhou. 2013. Wald tests for detecting multiple
structural changes in persistence. Econometric Theory 29: 289-323.

Kejriwal, M., X. Yu, and P. Perron. 2020. Bootstrap procedures for detecting multiple
persistence shifts in heteroskedastic time series. Journal of Time Series
Analysis 41: 676-690. DOI: 10.1111/jtsa.12528.

Liu, R. Y. 1988. Bootstrap procedures under some non-iid models. Annals of
Statistics 16: 1696-1708.

Perron, P., and Z. Qu. 2006. Estimating restricted structural change models.
Journal of Econometrics 134: 373-399.

Author

H. Ozan Eruygur

AHBV University, Ankara, Turkiye.

Department of Economics

https://www.ozaneruygur.com

eruygur@gmail.com

Eruygur Academy and Consulting

https://www.eruygurakademi.com

eruygurakademi@gmail.com

kypshift v1.3.23 - July 2026

The tests implemented here were proposed by Mohitosh Kejriwal (Krannert School of
Management, Purdue University), Xuewen Yu (Krannert School of Management, Purdue
University) and Pierre Perron (Department of Economics, Boston University). The Stata
implementation is a port of the authors' MATLAB replication code for the article.

Please cite as: Eruygur, H. O. 2026. kypshift: Stata module for bootstrap detection of
multiple persistence shifts in heteroskedastic time series. Statistical Software
Components, Boston College Department of Economics.