Skip to content

DPredict · Guide test 221

Hadri panel stationarity test

Tests stationarity of panel series as the null using an LM statistic.

Runs in CodeSplashPython (calls R) example not runR example validated Corrected in edition 2

Do it in CodeSplash

In the app, set it up in Analyze with this method:

  • Panel unit-root tests — Across many units (countries, stores, firms), do the series have unit roots — or are some or all of them stationary?

In Panel unit-root tests, choose Test = Hadri LM.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Hadri panel stationarity test

8
40
0.30
1.00

0: every unit has a unit root (H₀ of the unit-root tests).

0.050

Your data

Simulated with known truth

8 series of length 40: 8 stationary (solid) and 0 with a unit root (dashed). Stationary units keep returning to their own level; random walks drift away.

If H₀ were true

Z = −0.15
  1. The reference: how Z varies across samples when H₀ is true (normal approximation).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .560).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Z=N (LM‾−16)1/45,LMi=T−2∑tSit2σ^i2Z = \dfrac{\sqrt N\,(\overline{LM} - \tfrac16)}{\sqrt{1/45}},\qquad LM_i = \dfrac{T^{-2}\sum_t S_{it}^2}{\hat\sigma_i^2}

With your numbers

LM‾=0.16,Z=(−0.15),N=8\overline{LM} = 0.16,\qquad Z = (-0.15),\qquad N = 8
SitS_{it}
partial sums of unit i's demeaned series
16,145\tfrac16, \tfrac1{45}
mean and variance of LM under H₀

The verdict

Z = −0.15, p = .560

p > α = .050: compatible with H₀

A panel KPSS. It over-rejects badly with serial correlation and small T: here every stationary unit is AR(φ).

Statistic
−0.152
p-value
0.5605
Hadri panel stationarity test on 8 series of length 40, 8 stationary: Z = −0.15, p = .560. The p-value is above α = .050, so the data are compatible with H0.

Hadri panel stationarity test on 8 series of length 40, 8 stationary: Z = −0.15, p = .560. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: every panel unit is level/trend stationary; H1: some unit-root behavior exists.

Assumptions

A panel with explicitly modeled individual deterministic terms and sufficient time observations. First-generation panel unit-root tests generally assume cross-sectional independence; lag lengths and balance conventions matter.

Formula

LM=N−1∑i∑tSit2Ti2ω^i2Z=N(LM−μ0)σ0\begin{gathered}LM=N^{-1}\sum_i\frac{\sum_tS_{it}^2}{T_i^2\widehat\omega_i^2}\\[5pt] Z=\frac{\sqrt N(LM-\mu_0)}{\sigma_0}\end{gathered}

Parameters and notation

Sit sums residuals after unit-specific deterministic fits. For a balanced independent panel, (μ0,σ0²)=(1/6,1/45) for level stationarity or (1/15,11/6300) for trend stationarity under standard normalization.

Structure of the method

Regress each series on its allowed deterministic component, accumulate residuals over time, measure the integrated squared partial-sum process relative to an appropriate innovation variance, average across units, and standardize with stationarity-null moments. This is a stationarity-null panel diagnostic rather than an ADF-style unit-root-null regression.

Estimated and nuisance parameters

Estimate unit-specific level/trend coefficients and variance quantities required by the chosen Hadri version. A heteroskedasticity-consistent cross-unit scale treatment is distinct from a serial-correlation-robust long-run variance estimator. Do not assume an implementation supplies both merely because the displayed general formula contains a long-run variance symbol.

Settings and design choices

Choose level versus trend stationarity, variance version, balanced-panel requirements, and any documented dependence extension. In plm::purtest, lags and pmax are irrelevant for Hadri, and q is documented for Levin–Lin–Chu only. Therefore changing lags=1 in the supplied Hadri code does not add serial-correlation correction.

Fitting and adaptation

Refit deterministic components and recompute residual processes when changing the trend model or panel. Use a method explicitly designed for serial/common-factor dependence if those are present. There is no neural fine-tuning, and an arbitrary smoothing of residuals changes the null problem rather than tuning an otherwise unchanged test.

Sensitivity and robustness

Persistent stationary errors, common shocks, breaks, and short panels can lead to overrejection. Interpret alongside unit-root-null tests with their different nulls rather than claiming either pair proves stationarity. Inspect unit contributions and distinguish deterministic misspecification from stochastic nonstationarity.

How to use and calibrate

Use the upper normal tail with the appropriate long-run variance and null moments.

Example application

Complement unit-root-null panel tests with a stationarity-null procedure.

Interpretation and pitfalls

Watch out

Cross-sectional dependence can cause severe overrejection. It reverses the null used by LLC/IPS.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
  • Rewritten in the review: interpretation and pitfalls.
  • Interpretation and pitfallssearch.r-project.org

    Official purtest argument documentation identifies which settings apply to Hadri; the displayed general long-run-variance formula should not be assumed identical to every implementation.

    Corrected text

    Cross-sectional dependence can cause severe overrejection. It reverses the null used by LLC/IPS. In the supplied plm::purtest Hadri example, lags and pmax are ignored; q is documented only for LLC. Hcons is a heteroskedasticity-consistent option, not a blanket serial-correlation/HAC correction.

Python and R

Columns are panel units and rows time. Cross-sectional independence and the chosen common/heterogeneous dynamics matter; Hadri reverses the null to stationarity. Choi is represented by the inverse-normal member.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: plm

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
X<-replicate(15,cumsum(rnorm(60)));print(plm::purtest(X,test="hadri",exo="intercept",lags=1))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Validated — Executed successfully in the validation environment · needs plm

set.seed(2026)
X<-replicate(15,cumsum(rnorm(60)));print(plm::purtest(X,test="hadri",exo="intercept",lags=1))
Output
	Hadri Test (ex. var.: Individual Intercepts) (Heterosked. Consistent)

data:  X
z = 72.079, p-value < 2.2e-16
alternative hypothesis: at least one series has a unit root

Sources

Statistics guide v4 (historical):
Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 221, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT221.