help xtrec version 1.0.0

Title

xtrec — Panel unit root test based on recursive detrending (Westerlund 2015).

Version

Version 1.0.0, 3 March 2026

Author: Dr Merwan Roudane (merwanroudane920@gmail.com)

Syntax

xtrec varname [if] [in], [trend(integer)
maxlag(integer)
robust
nograph
notable
level(integer)]

varname is the panel variable to test for a unit root.

Data must be xtset before using xtrec; see xtset.

The panel must be strongly balanced. The data are automatically first-differenced
and recursively detrended within the command.

Contents

Description

Econometric Model

Methodology

Options

Table 1: Asymptotic Coefficients

Power Properties

Interpretation Guide

Diagnostics and Graphs

Saved Values

Examples

References

Citation

Also see

About

Description

xtrec performs a panel unit root test based on recursively detrended
data as proposed by Westerlund (2015, Journal of Econometrics). Two test statistics
are available:

t-REC: the baseline test assuming iid errors. Asymptotically
distributed as N(0,1) under the null hypothesis of a unit root, regardless
of the degree of the fitted trend polynomial. This invariance property is unique
among all panel unit root tests and eliminates the need for any mean or variance
correction factors.

t-RREC: the robust version (invoked with the robust option)
that accommodates serial correlation, cross-section dependence (via a common factor
structure), and cross-section heteroskedasticity. Its null distribution is also
N(0,1), and the invariance property extends to general trend functions beyond
polynomials (including smooth transition shifts and trigonometric functions).

Key advantages over existing panel unit root tests:

- The null distribution is invariant to both the true and fitted trend degree.

- No mean/variance correction factors are needed (unlike IPS, LLC, etc.).

- Critical values are simply from the standard Normal distribution.

- Critical region is always the left tail (unlike Breitung's test where it varies).

- Enables testing with higher-order polynomial trends (quadratic, cubic, etc.) which is not possible with existing tests.

- For p < 1 (no trend terms), power lies within N^(-1/2)*T^(-1)-neighborhoods.

- For p >= 1 (at least linear trend), power lies within N^(-1/4)*T^(-1)-neighborhoods.

Econometric Model

The data generating process is given by:

Y_it = beta_i' D_ + U_it

U_it = rho_i * U_ + epsilon_it

rho_i = exp(T^{-1} * alpha_N * c_i)

where:

D_ = (1, t, t^2, ..., t^p)' is a (p+1)-dimensional polynomial
trend vector.

alpha_N = N^{-kappa} governs the rate of shrinking of the local
alternative.

c_i is iid across panels with E(c_i) = mu_1 and E(c_i^2) = mu_2.

The null hypothesis is:

H0: c_1 = c_2 = ... = c_N = 0 (unit root for all panels)

against the double-sided alternative:

H1: c_i != 0 for at least some i (some panels are stationary)

This is equivalently stated as H0: mu_2 = 0 versus H1: mu_2 > 0
(using the local parametrization).

Trend specification examples:

trend(0): Y_it = beta_0 + U_it (constant only)

trend(1): Y_it = beta_0 + beta_1*t + U_it (linear trend)

trend(2): Y_it = beta_0 + beta_1*t + beta_2*t^2 + U_it (quadratic trend)

trend(3): Y_it = beta_0 + beta_1*t + beta_2*t^2 + beta_3*t^3 + U_it (cubic trend)

Methodology

The t-REC statistic is constructed in four steps:

Step 1 — First-difference: y_it = Delta Y_it. This is a restricted
(maximum likelihood) estimation under H0 and ensures the detrending regression is
not spurious.

Step 2 — Recursive detrending: For p >= 1, recursively detrend
y_it using only past and current observations to obtain y_. This preserves
the martingale property of the data (unlike full-sample OLS detrending which
destroys it).

Step 3 — Accumulate: R_ = sum_^t y_. This is
an estimate of U_it under H0.

Step 4 — Compute the pooled t-ratio:

t-REC = A_ / (sigma_hat * sqrt(B_))

where:

A_ = (1/(sqrt(N)*T)) * sum_i sum_t R_ * y_

B_ = (1/(N*T^2)) * sum_i sum_t R^2_

sigma_hat^2 = (NT)^{-1} * sum_i sum_t y^2_

The t-RREC statistic additionally:

(a) Removes the common factor via cross-section averaging
(Pesaran 2007).

(b) Augments with BIC-selected lags for serial correlation.

(c) Scales by individual panel variance for heteroskedasticity.

t-RREC = [sum_i sum_t sigma^{-2}_ R_ r_]
/ sqrt[sum_i sum_t sigma^{-2}_ R^2_]

Options

trend(integer) specifies the degree of the polynomial trend
to fit. The default is trend(0) (constant only, no trend). Set trend(1) for
a linear trend, trend(2) for quadratic, etc. The null distribution remains
N(0,1) regardless of this choice — no lookup tables or correction factors needed.

maxlag(integer) sets the maximum lag augmentation order for
the robust t-RREC test. The default (maxlag(-1)) uses automatic BIC-based
selection with q_max = floor(4*(T/100)^(2/9)). Only relevant when robust
is specified.

robust computes the robust t-RREC statistic instead of t-REC. This
handles:

- Serial correlation (via lag augmentation with BIC selection)

- Cross-section dependence (via cross-section averaging to remove common factor)

- Heteroskedasticity (via individual variance scaling)

nograph suppresses the diagnostic graphs.

notable suppresses the output table.

level(integer) specifies the confidence level in percent.
Default is level(95).

Table 1: Asymptotic Coefficients

From Westerlund (2015, Table 1), the coefficients a_p and b_p of the
asymptotic distribution are:

p a_p b_p kappa Power by

-1 0.50000 0.33333 1/2 mu_1
0 0.50000 0.33333 1/2 mu_1
1 0.00000 -0.03704 1/4 mu_2
2 0.00000 -0.00648 1/4 mu_2
3 0.00000 -0.00238 1/4 mu_2
4 0.00000 -0.00115 1/4 mu_2

Key insight: a_p = 0 for all p >= 1. This is a fundamental
mathematical property of the recursive detrending, not a numerical error.
When trend terms are fitted (p >= 1), the first-order bias term vanishes
entirely, and power is driven solely by the second-order term through mu_2
(the second moment of c_i). This shifts the rate of shrinking from
N^{-1/2}*T^{-1} to N^{-1/4}*T^{-1}.

The value of b_p is declining in p, meaning power decreases as
higher-order trends are added. However, the rate of shrinking (kappa = 1/4)
remains constant for all p >= 1, which goes against the common belief that
kappa should continue to decrease with the trend degree.

Power Properties

The local asymptotic distribution under H1 is given by (Westerlund 2015, eq. 5):

t-REC ~ sqrt(2N) * [alpha_N * mu_1 * a_p + alpha_N^2 * mu_2 * b_p]
/ sqrt[1 + (4/3) * mu_1 * alpha_N * a_p + mu_2 * alpha_N^2 * b_p]
+ [1 / sqrt(1 + ...)] * N(0,1)

Power characteristics by trend degree:

p < 1 (no trend terms): a_p = 1/2, power is driven by mu_1 = E(c_i)
within N^{-1/2}*T^{-1}-neighborhoods. This matches the power envelope
(Moon, Perron, and Phillips 2007).

p >= 1 (with trend terms): a_p = 0, power is driven by mu_2 = E(c_i^2)
within N^{-1/4}*T^{-1}-neighborhoods. The test cannot distinguish local
stationarity (c_i < 0) from local explosiveness (c_i > 0). The value of b_p
is declining in p, so power decreases with the trend degree.

Comparison with competing tests (p = 1):

t-REC: drift coefficient = -0.052*mu_2

t+ (Moon-Perron): drift = -0.053*mu_2

lambda_UB (Breitung): drift = 0.068*mu_2 (right-tail)

V_NT (point-optimal): drift = -0.075*mu_2 (power envelope)

While t-REC does not attain the power envelope for p >= 1, it is the
only test that can be used for p > 1, making it uniquely valuable for testing
with higher-order polynomial trends.

Interpretation Guide

How to interpret the results:

1. Look at the p-value in the main results table. Reject the null
hypothesis of a unit root if the p-value is below your significance level.

2. Compare the test statistic with the critical values table. Since
the null distribution is N(0,1), the critical values are always -2.3263 (1%),
-1.6449 (5%), and -1.2816 (10%).

3. The individual panel statistics section shows the distribution of
per-panel t-statistics. High dispersion (large SD) suggests heterogeneity
across panels.

4. The Table 1 section shows where your chosen trend degree falls
in the asymptotic coefficient table. The current p is highlighted.

Choosing the trend degree:

trend(0): Use when the variable has no trend (e.g., growth rates,
inflation rates, interest rate spreads).

trend(1): Use when the variable has a linear trend (e.g., GDP,
industrial production, population).

trend(2): Use when the variable has a quadratic trend (e.g., CO2
emissions with accelerating growth, urbanization rates).

trend(3): Use when the variable has a cubic trend or to robustify
against unknown nonlinear trending behavior.

When to use the robust version:

Use robust when you suspect serial correlation in the errors,
cross-section dependence across panels (e.g., from common shocks or
spatial spillovers), or heteroskedasticity across panels. In empirical
work, the robust version is generally recommended.

Diagnostics and Graphs

By default, xtrec generates a combined diagnostic graph with two panels:

Recursively Detrended Residuals: A density plot of the pooled
recursively detrended residuals overlaid with a kernel density estimate and a
Normal fit. Under H0, these should be approximately Gaussian.

Cumulative Sum Paths: A spaghetti plot of the individual
cumulative sum processes R_ across panels. Under H0 (unit root), these
paths should exhibit random-walk-like behavior. The bold line shows the
cross-section mean.

Use nograph to suppress these plots.

Saved Values

xtrec stores the following in r():

Scalars
r(trec) t-REC test statistic (when robust not used)
r(trrec) t-RREC test statistic (when robust used)
r(pvalue) p-value (from left-tail standard Normal)
r(N) number of panels
r(T) number of time periods
r(T_eff) effective time periods after detrending
r(trend) fitted trend degree p
r(a_p) coefficient a_p from Table 1
r(b_p) coefficient b_p from Table 1
r(sigma2) estimated error variance sigma^2_eps
r(kappa) rate of shrinking (0.5 for p<1, 0.25 for p>=1)
r(maxlag) BIC-selected lag order (robust version only)
r(ps_mean) mean of individual panel t-statistics
r(ps_median) median of individual panel t-statistics
r(ps_sd) std. dev. of individual panel t-statistics
r(ps_min) minimum individual panel t-statistic
r(ps_max) maximum individual panel t-statistic

Macros
r(test) test name ("t-REC" or "t-RREC")
r(varname) variable tested
r(panelvar) panel variable
r(timevar) time variable

Examples

Example 1: Basic t-REC test (constant only):

webuse grunfeld, clear

xtset company year

xtrec invest

Example 2: t-REC with linear trend:

xtrec invest, trend(1)

Example 3: t-REC with quadratic trend:

xtrec invest, trend(2)

Example 4: t-REC with cubic trend:

xtrec invest, trend(3)

Example 5: Robust t-RREC with linear trend:

xtrec invest, trend(1) robust

Example 6: Robust t-RREC with automatic BIC lag selection:

xtrec invest, trend(1) robust maxlag(4) nograph

Example 7: Compare all trend degrees:

forvalues p = 0/3 { xtrec invest, trend(`p') nograph }

Example 8: Test on log-transformed variable:

gen log_invest = ln(invest)

xtrec log_invest, trend(2)

Example 9: Suppress table, show only graphs:

xtrec invest, trend(1) notable

Example 10: Full analysis with all options:

xtrec invest, trend(1) robust level(99)

References

Westerlund, J. (2015). The effect of recursive detrending on panel unit root tests.
Journal of Econometrics 185(2), 453-467.
doi:10.1016/j.jeconom.2014.06.015

Moon, H.R., Perron, B. and Phillips, P.C.B. (2007). Incidental trends and the power
of panel unit root tests. Journal of Econometrics 141, 416-459.

Moon, H.R. and Perron, B. (2008). Asymptotic local power of pooled t-ratio tests
for unit roots in panels with fixed effects. Econometrics Journal 11, 80-104.

Pesaran, M.H. (2007). A simple panel unit root test in presence of cross-section
dependence. Journal of Applied Econometrics 22, 265-312.

Bai, J. and Ng, S. (2004). A PANIC attack on unit roots and cointegration.
Econometrica 72, 1127-1177.

Breitung, J. (2000). The local power of some unit root tests for panel data.
In Baltagi, B. (Ed.), Advances in Econometrics, Vol. 15, pp. 161-178.

Moon, H.R. and Phillips, P.C.B. (2000). Estimation of autoregressive roots near unity
using panel data. Econometric Theory 16, 927-997.

Levin, A., Lin, C.F. and Chu, C.J. (2002). Unit root tests in panel data:
asymptotic and finite-sample properties. Journal of Econometrics 108, 1-24.

Im, K.S., Pesaran, M.H. and Shin, Y. (2003). Testing for unit roots in
heterogeneous panels. Journal of Econometrics 115, 53-74.

Shin, D.W. and So, B.S. (2001). Recursive mean adjustment for unit root tests.
Journal of Time Series Analysis 22, 595-612.

Citation

If you use xtrec in published work, please cite:

Roudane, M. (2026). xtrec: Panel unit root test based on recursive detrending
in Stata. Statistical Software Components, Boston College Department of Economics.

Westerlund, J. (2015). The effect of recursive detrending on panel unit root tests.
Journal of Econometrics 185(2), 453-467.

BibTeX:

@article{westerlund2015,

title={The effect of recursive detrending on panel unit root tests},

author={Westerlund, Joakim},

journal={Journal of Econometrics},

volume={185},

number={2},

pages={453--467},

year={2015}

}

Also see

Related Stata commands:

xtunitroot — Panel unit root tests (LLC, IPS, Fisher, Hadri)

dfuller — Augmented Dickey-Fuller unit root test

pperron — Phillips-Perron unit root test

User-written commands (install via ssc install): pescadf, xtcips, multipurt

About

xtrec implements the recursively detrended panel unit root tests
proposed by Westerlund (2015). The key innovation is that the null distribution
of the test statistic is asymptotically invariant to both the true and
fitted trend polynomial, eliminating the need for trend-degree-specific
correction factors that plague existing panel unit root tests. This makes
the test uniquely suitable for testing with higher-order polynomial trends
(quadratic, cubic, etc.) which were previously intractable.

The command is implemented in Mata for computational speed and provides
comprehensive diagnostic output including per-panel statistics, the full
Table 1 from the paper, power properties, and methodology details.

Dr Merwan Roudane

merwanroudane920@gmail.com