*! version 1.0.0 12jul2026

Title

xtmixedroot -- Fraction of nonstationary (unit-root) units
in a mixed panel: the Ng (2008) estimator with Westerlund (2016)
bias-adjusted fixed-T inference

Syntax

xtmixedroot varname [if] [in] [, options]

Ng (2008) estimator
estimator(a|b|c) A: heterogeneous AR(p) dynamics (default);
B: adds control for cross-sectional correlation; C: adds incidental linear
trends

lags(#) fixed AR lag order p for every unit; default is
unit-by-unit BIC selection

maxlags(#) maximum lag order for BIC selection; default
maxlags(4)

factors(#) number of lags of the factor proxy in Estimator B;
default factors(1), i.e. the proxy and its first lag

pc use the first principal component of the differenced panel
as the factor proxy instead of the cross-sectional average

hac(#) truncation lag M of the Bartlett (Newey-West) kernel for
the HAC standard error; default hac(2)

Hypothesis and inference
theta0(#) null value theta_0 in (0,1]; default
theta0(1) (all units nonstationary)

level(#) confidence level for the theta interval; default
level(95)

demean use cross-sectionally demeaned data when estimating the
error variance and kurtosis of the Westerlund statistics (recommended with
common time effects)

Reporting
classify classify individual units as I(1)/I(0) by their
estimated dominant autoregressive root (Ng 2008, Sec. 4)

list(#) number of units displayed by classify; default
list(15) (the full table is always stored in r(units))

graph plot the cross-sectional variance of the raw and
rescaled panel with the implied theta trend line

The panel must be xtset, balanced, and without gaps.

Description

xtmixedroot estimates theta, the fraction of units in a panel
whose autoregressive representation contains a unit root, and tests
H0: theta = theta_0 for any theta_0 in (0,1]. Unlike conventional panel
unit-root tests, which only test the extreme hypotheses that all units
are nonstationary or all are stationary, xtmixedroot quantifies
how many units are nonstationary, which is the quantity Pesaran (2012)
recommends reporting alongside any panel unit-root test.

The method exploits Ng's (2008) observation that in a panel mixing I(1) and
I(0) units the cross-sectional variance V_t grows linearly in t with slope
exactly theta (the "fanning out" of the distribution). Time-averaging the
first difference of V_t therefore estimates theta. Three estimators are
provided:

o Estimator A fits a unit-specific AR(p) by OLS, rescales each
series by D_i/sigma_i so that heterogeneous dynamics and innovation variances
do not contaminate the slope, and averages the change in the cross-sectional
variance of the rescaled panel. Inference uses a HAC t statistic.

o Estimator B equals A but augments each AR regression with a
proxy for a common stationary factor (the cross-sectional average of the
differenced data and its lags, or the first principal component), which
removes the downward bias that cross-sectional correlation induces in
Estimator A.

o Estimator C allows incidental linear trends y_it =
lambda_i*t + u_it: the AR regression includes a trend, and theta is the
intercept of a regression of the change in the cross-sectional variance on
(1, t^2-(t-1)^2). It converges much more slowly and needs very large N and
T.

Because the Ng theta-hat requires a fairly long panel (T >= 100
recommended), xtmixedroot also always reports the Westerlund (2016)
bias-adjusted statistics, which are valid in short panels:
tau*_1,T is correctly sized for any T >= 2 and tests H0: theta = 1;
tau*_1,NT allows heterogeneous intercepts (larger T); tau*_1 is the
large-(N,T) simplification; and tau*_theta0 tests H0: theta = theta_0 < 1
when both N and T are large. When T < 25 the Ng block is skipped
automatically and only these statistics are shown.

Formulas, assumptions, and the full step-by-equation map from the code to
the two papers are documented in help xtmixedroot methods.

Options

Ng (2008) estimator

estimator(a|b|c) selects the Ng estimator. Default a. Use
b whenever cross-sectional correlation is suspected: Ng (2008) shows
that ignoring strong correlation biases theta-hat downward, while
controlling for correlation that is absent costs almost nothing. Use
c only when unit-specific linear trends are plausible and the panel is
very large (Ng recommends T >= 300, N >= 200).

lags(#) fixes the AR order p for every unit (Ng's simulations use
p = 2). By default p is chosen unit-by-unit by the BIC over 1..maxlags,
as in Ng's empirical applications.

maxlags(#) sets the largest p considered by the BIC; default 4.

factors(#) sets q, the number of lags of the factor proxy included in
the Estimator B regression; default 1, matching Ng's use of the current and
first lag of the cross-sectional average of the differenced data.

pc proxies the common factor with the first principal component of the
differenced panel instead of the cross-sectional average. Ng reports that the
two proxies give similar results.

hac(#) sets the Bartlett kernel truncation M for the HAC standard
error of theta-hat; default 2 (Ng's choice; her results for M = 1 and 4 are
similar).

Hypothesis and inference

theta0(#) sets the null value. With theta0(1) (default) the
tests are left-tailed: rejection means some units are stationary. With
theta_0 < 1 the Ng t statistic and the Westerlund tau*_theta0 statistics are
two-sided. theta_0 = 0 is not testable (the limiting distribution collapses);
following Ng, test theta0(.01) instead: rejecting theta = .01 upward
also rejects theta = 0.

demean estimates the Westerlund error variance and kurtosis from
cross-sectionally demeaned data, as Westerlund (2016, footnote 3) recommends
when common time effects are present. theta-hat itself is invariant to
common time effects.

Reporting

classify orders the units by their estimated dominant autoregressive
root |phi_i1| and labels the top [theta-hat x N] units I(1), where [.] is the integer part
(Ng 2008, Sec. 4). This is a heuristic: Ng reports correct-classification rates of
about 60 percent in small samples and gives no formal theory for it. The
full classification is stored in r(units).

graph plots V_t for the raw and the rescaled panel together with the
straight line implied by theta-hat, the visual signature of the method: the
closer the panel is to all-I(1), the steeper the variance trend.

Interpreting the output

theta: point estimate of the fraction of I(1) units, with HAC
standard error and confidence interval. Values near 0 mean the panel is
essentially stationary; near 1, essentially nonstationary; in between, the
panel is mixed and imposing homogeneous dynamics would be inappropriate.

implied number of I(1) units: [theta-hat x N] (integer part).

H0: theta = theta_0: the user's null, tested with the Ng HAC
t statistic (left-tailed at theta_0 = 1, two-sided otherwise).

H0: theta = 0.010 vs >: "are there any I(1) units at all?" -
rejection implies theta > 0.

H0: theta = 1.000 vs <: "are all units I(1)?" - the analogue of
a conventional panel unit-root null.

theta-hat (feasible, raw data): Westerlund's estimator, the
time-average of the change in the cross-sectional variance of the raw
(unrescaled) data. It estimates theta x sigma2_eps, hence the scaling by
s2_eps to obtain theta*.

theta*_BA: bias-adjusted theta* (+ theta_0/T); with T fixed,
theta* is biased by exactly -theta_0/T.

tau*_1,T: the headline short-panel statistic; correctly sized
for any T >= 2 provided intercepts are homogeneous (or the data are
cross-sectionally demeaned). Reject H0: theta = 1 when tau < -1.645 (5
percent).

tau*_1,NT: adds the intercept-variance correction
4*s2_lambda/s2_eps; preferable when T is moderately large and intercepts are
heterogeneous.

tau*_theta0: tests theta = theta_0 < 1; requires both N and T
large (Westerlund requires sqrt(N)/T -> 0) and is conservative in short
panels.

Remarks and practical guidance

Sample-size regimes. T >= 100: trust theta-hat (Estimator A or B)
and all statistics. 25 <= T < 100: theta-hat is reported but is noisy; give
more weight to the Westerlund statistics. T < 25: only the Westerlund
statistics are computed; with T this small only H0: theta = 1 is testable
(tau*_1,T). N matters much less; N >= 30 suffices (Ng 2008).

Which estimator. In practice cross-sectional correlation is
rarely excludable, and Ng shows that controlling for it when it is absent is
nearly free while ignoring it when present biases theta-hat down. Estimator
B is therefore a sensible default in applications; A is the baseline that
matches the theory exactly.

What theta-hat near 1 in a short panel does not mean.
Westerlund (2016) proves that when the stationary units are local-to-unity
(alpha_i = exp(c_i/N^eta)), theta is not identified: theta-hat converges to
1 regardless of the true theta. A theta-hat near 1 is therefore evidence
that units are persistent, not necessarily that all of them have exact
unit roots. Larger T relaxes this: under joint asymptotics the test detects
alternatives as close as eta = gamma + 1/2, where T = N^gamma.

Nonstationary common factors. The method assumes any common
factor is stationary (Ng's A4). If a pervasive I(1) factor drives the
panel, every unit is nonstationary regardless of alpha_i, and theta is not
the object of interest; use the PANIC decomposition of Bai and Ng (2004)
instead.

Variance components that grow like t. If some other component of
the data has variance proportional to t (e.g. a common factor with F_t =
sqrt(t)), theta-hat estimates only an upper bound for theta - but such data
would violate every standard unit-root framework, not just this one (Ng
2008, Sec. 5).

Deterministic time effects. A common additive time effect a_t
leaves theta-hat unchanged. Unit-specific linear trends require Estimator C.
Note that C is far less precise (its rate is sqrt(N/T) rather than sqrt(N))
and Ng's own application found it unreliable at T = 25.

Repeated AR roots. The rescaling constant D_i is a product of
root differences and approaches 0 when the two largest estimated roots
nearly coincide; xtmixedroot floors |D_i| at 1e-6. Units with nearly
repeated dominant roots are rare in practice but can inflate the rescaled
variance; inspect r(units) if theta-hat looks anomalous.

Examples

Baseline: what fraction of the panel variable y is nonstationary?

. xtset id year

. xtmixedroot y

Control for cross-sectional correlation, classify the units, plot the
variance trend:

. xtmixedroot y, estimator(b) classify graph

Test that half the panel is nonstationary:

. xtmixedroot y, theta0(.5)

Short panel (T = 5): only H0: theta = 1 is testable:

. xtmixedroot y

(read the tau*_1,T line; the Ng block is skipped automatically)

Fixed lag order and longer HAC window, as robustness:

. xtmixedroot y, lags(2) hac(4)

A full simulated validation of every code path against the Monte Carlo
designs of both source papers ships with the package:

. net get xtmixedroot

. do xtmixedroot_example.do

Stored results

xtmixedroot stores the following in r():

Scalars

r(N), r(T) panel dimensions

r(theta) Ng theta-hat (Estimator A/B/C)

r(se_theta) HAC standard error of theta-hat

r(t), r(p) t statistic and p-value for H0: theta = theta_0

r(t_low), r(p_low) test of H0: theta = .01 vs > (any I(1) units)

r(t_all), r(p_all) test of H0: theta = 1 vs < (all I(1) units)

r(N1hat) [theta-hat x N] (integer part)

r(p_mean) average selected AR lag order

r(varlambda), r(se_varlambda) variance of the incidental
trends and its s.e. (Estimator C only)

r(theta_w) Westerlund feasible theta-hat (raw data)

r(theta_star), r(theta_ba) scaled and bias-adjusted theta

r(sigma2e), r(kappa), r(sigma2lam) error variance,
error kurtosis, intercept variance

r(tau1T), r(p_tau1T) tau*_1,T and p-value (theta_0 = 1)

r(tau1NT), r(p_tau1NT) tau*_1,NT and p-value (theta_0 = 1)

r(tau1), r(p_tau1) tau*_1 and p-value (theta_0 = 1)

r(tautheta0), r(p_tautheta0) tau*_theta0 and p-value (theta_0 < 1)

r(tautheta0NT), r(p_tautheta0NT) sigma_theta,NT variant (theta_0 < 1)

r(theta0), r(level) null value and confidence level

Macros

r(cmd), r(varname), r(ivar), r(tvar),
r(estimator) command, variable and setting names

Matrices

r(V) T x 3: time, V_t of the raw data, V_t of the rescaled data

r(units) N x 6 (sorted by |phi_i1| descending): unit id,
|phi_i1|, sigma_i, D_i, selected p, I(1) classification

References

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

Ng, S. 2008. A simple test for nonstationarity in mixed panels.
Journal of Business & Economic Statistics 26(1): 113-127.
https://doi.org/10.1198/073500106000000675

Pesaran, M. H. 2012. On the interpretation of panel unit root tests.
Economics Letters 116: 545-546.

Westerlund, J. 2016. A simple test for nonstationarity in mixed
panels: A further investigation. Journal of Statistical Planning and
Inference 173: 1-30.
https://doi.org/10.1016/j.jspi.2016.01.004

Author

Merwan Roudane

Email: merwanroudane920@gmail.com

GitHub: https://github.com/merwanroudane