Skip to content

Panel unit-root tests

Pool many short series for more power, with tests that differ on what they assume about units, what they pool and how they read rejection.

Advanced ~12 min10 steps

What runs in CodeSplash

You will be able to

  • Explain why pooling helps, and what each panel test assumes about the units
  • Read Levin–Lin–Chu, Im–Pesaran–Shin, Maddala–Wu, Choi, Hadri and CIPS results
  • State what a rejection does and doesn't say about individual units

Read first

01

Why pool?

Read

Forty years of data on one country gives a unit-root test little power. Forty years on eight countries gives more, if you can pool them.

Panel unit-root testsPanel unit-root testA unit-root test that pools many short series (countries, stores) to gain the power a single short series lacks. do that, but they ask different questions. Should all units share one ϕ\phi? Can some be stationary while others aren't? Are the units independent?

02

Predict what a rejection means

Predict

Predict first

You run Im–Pesaran–Shin on eight countries, and it rejects the null that all have a unit root.

What does that tell you?

All eight are stationaryAt least some are stationaryAt most one has a unit root
Reveal

At least some are stationary. It doesn't tell you how many, or which. Reporting "the panel is stationary" overstates it, unless you've tested for this directly.

03

The family

Read
TestNullLets units differ?
Levin–Lin–ChuAll have a unit rootNo: one common ϕ\phi under the alternative
Im–Pesaran–ShinAll have a unit rootYes: averages unit-level ADF t
Maddala–Wu, ChoiAll have a unit rootYes: combines unit p-values
HadriAll are stationaryYes: reverses the null, like KPSS
Pesaran CIPSAll have a unit rootYes, and handles shared shocks
04

Read the results

In the app

The simulated panel has 8 units over 40 years, with three versions of the value: all stationary, all unit root, and a mix.

Panel unit-root testsRecorded · Python and R agreeRecorded 2026-11-21 · 9 values compared
R

Im–Pesaran–Shin W_t̄ = -1.46, p = .072

Im–Pesaran–Shin W_t̄
−1.458
p
0.0725
Units
8

Plots

y_mixed by unitHow does the series move over time, and where is an estimated break?
View data
unityeary_mixed
u011,9816.640
u011,9825.576
u011,9833.343
u011,9844.398
u011,9854.602
u011,9865.953
u011,9873.694
u011,9885.993
u011,9895.376
u011,9904.472
u011,9915.255
u011,9927.020
u011,9936.626
u011,9946.489
u011,9956.990
u011,9966.428
u011,9978.473
u011,9986.603
u011,9996.287
u012,0004.507
u012,0014.908
u012,0024.485
u012,0037.569
u012,0047.814
u012,0057.562
u012,0067.882
u012,0077.806
u012,0086.492
u012,0097.177
u012,0105.990
u012,0116.136
u012,0126.259
u012,0135.212
u012,0145.305
u012,0156.431
u012,0165.016
u012,0176.154
u012,0186.156
u012,0197.045
u012,0205.095
u021,9816.617
u021,9826.445
u021,9836.024
u021,9847.787
u021,9857.480
u021,9867.515
u021,9877.025
u021,9886.091
u021,9896.188
u021,9905.754
u021,9915.729
u021,9925.987
u021,9936.922
u021,9945.858
u021,9958.335
u021,9967.975
u021,9976.714
u021,9988.016
u021,9996.086
u022,0005.728

First 60 of 320 rows.

Unit ADF tests

unitPeriodsADF tp (MacKinnon)
u0140−2.603.092
u0240−3.034.032
u0340−3.153.023
u0440−3.710.004
u0540−2.071.256
u0640−1.702.430
u07400.6451.989
u0840−1.023.745
  • Rejecting a panel unit root means at least some units are stationary, not all (except for LLC's common-root alternative).
  • Lags 1 per unit; simulated quantities use seed 42 (identical in Python and R).
The exact R script · R R version 4.5.1 (2025-06-13)
# Panel unit-root tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.panel_unitroot 1.2.0 · spec 85e5b903765d03d0
# Dataset: ts_panel (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ts_panel.parquet", col_select = c("y_mixed", "unit", "year")))
n_input <- nrow(df)
df[["unit"]] <- factor(df[["unit"]], levels = c("u01", "u02", "u03", "u04", "u05", "u06", "u07", "u08"))  # stored level order
df <- df[stats::complete.cases(df[c("y_mixed", "unit", "year")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("y_mixed", "unit", "year"))  # infinite values stop the run (registry/errors.yaml)

# %% Panel
VALUE <- "y_mixed"
UNIT <- "unit"
TIME <- "year"
TEMPORAL <- FALSE
TEST <- "ips"
DET <- "c"
LAGS <- 1
REPS <- 100
SEED <- 42
df <- df[order(df[[UNIT]], df[[TIME]], method = "radix"), , drop = FALSE]
units <- levels(df[[UNIT]])
panel <- lapply(units, function(u) as.numeric(df[[VALUE]][df[[UNIT]] == u]))
lengths <- vapply(panel, length, integer(1))
need <- LAGS + 6
keep <- which(lengths >= need)
if (length(keep) < length(units)) warnings <- c(warnings, sprintf("%d unit(s) with fewer than %d periods were left out.", length(units) - length(keep), need))
if (!length(keep)) {  # no unit is long enough: name the longest one (registry/errors.yaml; the same in Python)
  longest <- which.max(lengths)
  cs_error("CS_E_SMALL_GROUP", min = need, group = units[longest], n = lengths[longest])
}
units <- units[keep]
panel <- panel[keep]
cs_check_not_constant(unlist(panel), VALUE)
LABELS <- list(ips = "Im–Pesaran–Shin W_t̄", llc = "Levin–Lin–Chu t*", maddala_wu = "Maddala–Wu χ²", choi = "Choi Z",
               hadri = "Hadri Z", cips = "Pesaran CIPS")
values <- list(n_units = length(units), n_periods = min(vapply(panel, length, integer(1))), test = TEST, test_label = LABELS[[TEST]])

# %% Test
if (TEST == "ips") {
  r <- cs_ts_ips(panel, DET, LAGS, REPS, SEED)
  values$stat <- r$stat; values$p <- r$p; values$tbar <- r$tbar; values$reps <- REPS
} else if (TEST == "llc") {
  r <- cs_ts_llc(panel, DET, LAGS, REPS, SEED)
  values$stat <- r$stat; values$p <- r$p; values$t_pooled <- r$t_pooled; values$reps <- REPS
} else if (TEST %in% c("maddala_wu", "choi")) {
  r <- cs_ts_fisher_type(panel, DET, LAGS)
  values$mw_stat <- r$mw_stat; values$mw_p <- r$mw_p; values$choi_z <- r$choi_z; values$choi_p <- r$choi_p
  values$choi_pm <- r$choi_pm; values$choi_pm_p <- r$choi_pm_p
  if (TEST == "maddala_wu") { values$stat <- r$mw_stat; values$p <- r$mw_p } else { values$stat <- r$choi_z; values$p <- r$choi_p }
  if (TEST == "choi" && FALSE) values <- c(values, cs_ts_choi_logit(panel, DET, LAGS))  # Choi's inverse-logit L*
} else if (TEST == "hadri") {
  r <- cs_ts_hadri(panel, DET, "unit")
  values$stat <- r$stat; values$p <- r$p; values$lm <- r$lm
} else {
  times <- lapply(units, function(u) df[[TIME]][df[[UNIT]] == u])
  common <- sort(Reduce(intersect, times))
  if (length(common) < max(lengths)) warnings <- c(warnings, sprintf("CIPS needs a balanced panel: %d periods common to every unit were used.", length(common)))
  P <- do.call(rbind, lapply(units, function(u) as.numeric(df[[VALUE]][df[[UNIT]] == u & df[[TIME]] %in% common])))
  r <- cs_ts_cips(P, DET, LAGS, REPS, SEED)
  values$stat <- r$stat; values$p <- r$p; values$reps <- REPS; values$n_periods <- ncol(P)
}
values$reject <- as.integer(values$p < 0.05)
verdict <- if (TEST == "hadri") {
  if (values$p < 0.05) "stationarity is rejected in at least some units." else "no evidence against stationarity in any unit."
} else {
  if (values$p < 0.05) "the unit-root null is rejected — at least some units are stationary." else "the unit-root null is not rejected."
}
summary <- sprintf("%s across %d units (%d+ periods): %.3f, %s — %s", LABELS[[TEST]], length(units), values$n_periods, values$stat, cs_fmt_p(values$p), verdict)
unit_rows <- lapply(seq_along(units), function(i) {
  a <- cs_ts_adf(panel[[i]], DET, lags = LAGS)
  list(unit = units[i], periods = length(panel[[i]]), adf_t = a$stat, p = a$p)
})
shown <- units[seq_len(min(8, length(units)))]
kind <- if (TEMPORAL) "temporal" else "numeric"
sub <- df[df[[UNIT]] %in% shown, , drop = FALSE]
cs_publish(list(
  method = "ts.panel_unitroot",
  methodVersion = "1.2.0",
  title = "Panel unit-root tests",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = sum(vapply(panel, length, integer(1))),
  summary = summary,
  apa = sprintf("%s = %.2f, %s", LABELS[[TEST]], values$stat, cs_fmt_p(values$p)),
  statistics = list(list(key = "stat", label = LABELS[[TEST]], value = values$stat), list(key = "p", label = "p", value = values$p),
                    list(key = "units", label = "Units", value = length(units))),
  tables = list(list(
    key = "units", title = "Unit ADF tests",
    columns = list(list(key = "unit", label = UNIT, type = "string"), list(key = "periods", label = "Periods", type = "integer"),
                   list(key = "adf_t", label = "ADF t", type = "number"), list(key = "p", label = "p (MacKinnon)", type = "pvalue")),
    rows = unit_rows
  )),
  effectSizes = list(),
  assumptions = list(),
  warnings = warnings,
  notes = c(list("Rejecting a panel unit root means at least some units are stationary, not all (except for LLC's common-root alternative).",
               if (TEST %in% c("ips", "llc", "cips")) sprintf("Lags %d per unit; simulated quantities use seed %d (identical in Python and R).", LAGS, SEED) else sprintf("Lags %d per unit.", LAGS)),
            if (!is.null(values$choi_l)) list(sprintf("Choi's inverse-logit L* = %.3f on t(%.0f), %s (lower tail, as plm::purtest test = \"logit\").", values$choi_l, values$choi_l_df, cs_fmt_p(values$choi_l_p)))),
  charts = list(cs_chart("series", "series-line", paste0(sprintf("%s by %s", VALUE, UNIT), if (length(units) > 8) " (first 8 units)" else ""), list(
    x = cs_col(TIME, cs_ts_time_labels(sub[[TIME]], TEMPORAL), kind = kind), y = cs_col(VALUE, as.numeric(sub[[VALUE]])),
    group = cs_col(UNIT, as.character(sub[[UNIT]]), kind = "categorical", levels = shown)))),
  values = values
))
Python

Im–Pesaran–Shin W_t̄ = -1.46, p = .072

Im–Pesaran–Shin W_t̄
−1.458
p
0.0725
Units
8

To keep this page light, the plots are shown once, under the R tab.

Unit ADF tests

unitPeriodsADF tp (MacKinnon)
u0140−2.603.092
u0240−3.034.032
u0340−3.153.023
u0440−3.710.004
u0540−2.071.256
u0640−1.702.430
u07400.6451.989
u0840−1.023.745
  • Rejecting a panel unit root means at least some units are stationary, not all (except for LLC's common-root alternative).
  • Lags 1 per unit; simulated quantities use seed 42 (identical in Python and R).
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Panel unit-root tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.panel_unitroot 1.2.0 · spec 85e5b903765d03d0
# Dataset: ts_panel (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.errors import check_not_constant
from codesplash.stats import ts

# %% Data
df = pd.read_parquet("tests/parity/fixtures/ts_panel.parquet", columns=["y_mixed", "unit", "year"])
n_input = len(df)
df["unit"] = pd.Categorical(df["unit"], categories=["u01", "u02", "u03", "u04", "u05", "u06", "u07", "u08"])  # stored level order
df = df.dropna(subset=["y_mixed", "unit", "year"])  # listwise deletion over the analysis columns
df["unit"] = df["unit"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["y_mixed", "unit", "year"])  # infinite values stop the run (registry/errors.yaml)

# %% Panel
VALUE = "y_mixed"
UNIT = "unit"
TIME = "year"
TEMPORAL = False
TEST = "ips"
DET = "c"
LAGS = 1
REPS = 100
SEED = 42
df = df.sort_values([UNIT, TIME], kind="mergesort")
units = [str(u) for u in df[UNIT].cat.categories]
panel = [df.loc[df[UNIT] == u, VALUE].to_numpy(dtype=float) for u in units]
lengths = [len(y) for y in panel]
need = LAGS + 6
keep = [i for i, y in enumerate(panel) if len(y) >= need]
if len(keep) < len(units):
    warnings.append(f"{len(units) - len(keep)} unit(s) with fewer than {need} periods were left out.")
if not keep:  # no unit is long enough: name the longest one (registry/errors.yaml; the same in R)
    longest = int(np.argmax(lengths))
    cs.cs_error("CS_E_SMALL_GROUP", min=need, group=units[longest], n=lengths[longest])
units = [units[i] for i in keep]
panel = [panel[i] for i in keep]
check_not_constant(np.concatenate(panel), VALUE)
LABELS = {"ips": "Im–Pesaran–Shin W_t̄", "llc": "Levin–Lin–Chu t*", "maddala_wu": "Maddala–Wu χ²", "choi": "Choi Z",
          "hadri": "Hadri Z", "cips": "Pesaran CIPS"}
values = {"n_units": len(units), "n_periods": min(len(y) for y in panel), "test": TEST, "test_label": LABELS[TEST]}

# %% Test
if TEST == "ips":
    r = ts.ips(panel, DET, LAGS, REPS, SEED)
    values.update({"stat": r["stat"], "p": r["p"], "tbar": r["tbar"], "reps": REPS})
elif TEST == "llc":
    r = ts.llc(panel, DET, LAGS, REPS, SEED)
    values.update({"stat": r["stat"], "p": r["p"], "t_pooled": r["t_pooled"], "reps": REPS})
elif TEST in ("maddala_wu", "choi"):
    r = ts.fisher_type(panel, DET, LAGS)
    values.update({"mw_stat": r["mw_stat"], "mw_p": r["mw_p"], "choi_z": r["choi_z"], "choi_p": r["choi_p"], "choi_pm": r["choi_pm"], "choi_pm_p": r["choi_pm_p"]})
    values.update({"stat": r["mw_stat"], "p": r["mw_p"]} if TEST == "maddala_wu" else {"stat": r["choi_z"], "p": r["choi_p"]})
    if TEST == "choi" and False:
        from codesplash.stats import panel_logit as pl  # Choi's inverse-logit L* (twin of R's cs_ts_choi_logit)
        values.update(pl.choi_logit(panel, DET, LAGS))
elif TEST == "hadri":
    r = ts.hadri(panel, DET, "unit")
    values.update({"stat": r["stat"], "p": r["p"], "lm": r["lm"]})
else:
    times = [set(df.loc[df[UNIT] == u, TIME].tolist()) for u in units]
    common = sorted(set.intersection(*times))
    if len(common) < max(lengths):
        warnings.append(f"CIPS needs a balanced panel: {len(common)} periods common to every unit were used.")
    P = np.vstack([df.loc[(df[UNIT] == u) & (df[TIME].isin(common)), VALUE].to_numpy(dtype=float) for u in units])
    r = ts.cips(P, DET, LAGS, REPS, SEED)
    values.update({"stat": r["stat"], "p": r["p"], "reps": REPS, "n_periods": P.shape[1]})
values["reject"] = int(values["p"] < 0.05)
if TEST == "hadri":
    verdict = "stationarity is rejected in at least some units." if values["p"] < 0.05 else "no evidence against stationarity in any unit."
else:
    verdict = "the unit-root null is rejected — at least some units are stationary." if values["p"] < 0.05 else "the unit-root null is not rejected."
summary = f"{LABELS[TEST]} across {len(units)} units ({values['n_periods']}+ periods): {values['stat']:.3f}, {cs.fmt_p(values['p'])} — {verdict}"
unit_rows = []
for u, y in zip(units, panel):
    a = ts.adf(y, DET, lags=LAGS)
    unit_rows.append({"unit": u, "periods": len(y), "adf_t": a["stat"], "p": a["p"]})
shown = units[:8]
kind = "temporal" if TEMPORAL else "numeric"
sub = df[df[UNIT].isin(shown)]
cs.publish({
    "method": "ts.panel_unitroot",
    "methodVersion": "1.2.0",
    "title": "Panel unit-root tests",
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": int(sum(len(y) for y in panel)),
    "summary": summary,
    "apa": f"{LABELS[TEST]} = {values['stat']:.2f}, {cs.fmt_p(values['p'])}",
    "statistics": [{"key": "stat", "label": LABELS[TEST], "value": values["stat"]}, {"key": "p", "label": "p", "value": values["p"]},
                   {"key": "units", "label": "Units", "value": len(units)}],
    "tables": [{
        "key": "units", "title": "Unit ADF tests",
        "columns": [{"key": "unit", "label": UNIT, "type": "string"}, {"key": "periods", "label": "Periods", "type": "integer"},
                    {"key": "adf_t", "label": "ADF t", "type": "number"}, {"key": "p", "label": "p (MacKinnon)", "type": "pvalue"}],
        "rows": unit_rows,
    }],
    "effectSizes": [],
    "assumptions": [],
    "warnings": warnings,
    "notes": ["Rejecting a panel unit root means at least some units are stationary, not all (except for LLC's common-root alternative).",
              f"Lags {LAGS} per unit; simulated quantities use seed {SEED} (identical in Python and R)." if TEST in ("ips", "llc", "cips") else f"Lags {LAGS} per unit."]
    + ([f"Choi's inverse-logit L* = {values['choi_l']:.3f} on t({values['choi_l_df']:.0f}), {cs.fmt_p(values['choi_l_p'])} (lower tail, as plm::purtest test = \"logit\")."] if "choi_l" in values else []),
    "charts": [cs.chart("series", "series-line", f"{VALUE} by {UNIT}" + (" (first 8 units)" if len(units) > 8 else ""), {
        "x": cs.col(TIME, ts.time_labels(sub[TIME].to_numpy(), TEMPORAL), kind=kind), "y": cs.col(VALUE, sub[VALUE].to_numpy(dtype=float)),
        "group": cs.col(UNIT, [str(u) for u in sub[UNIT]], kind="categorical", levels=shown)})],
    "values": values,
})

On the mix, IPS has WtˉW_{\bar t} = −1.46, p = .072. Look at the plot of the units. Would you expect a test of "all unit root" to reject here?

05

Combine p-values

Reflect

Maddala–Wu adds up each unit's ADF p-value, using Fisher's method:

P=−2∑iln⁡pi∼χ2N2P = -2 \sum_i \ln p_i \sim \chi^2_{2N}

On the unit-root series, PP = 21.6, p = .156.

Choi's inverse-normal version on the mixed series, with a trend: Z = −4.33, p < .001.

Choi proposed a third combination, on the logit scale: L∗∝∑iln⁡pi1−piL^* \propto \sum_i \ln\frac{p_i}{1-p_i}, referred to a tt distribution with 5N+45N+4 degrees of freedom. Turn on Also report the inverse-logit L* to see it beside Z and Pm. With an intercept only, the mixed series gives L∗L^* = −2.15, p = .018, against Z = −2.02. The three versions weigh very small and moderate p-values differently, so report the one you chose in advance.

Check yourself

Several units have tiny ADF p-values and the rest are moderate. Why can Choi's Z, Pm and L* disagree?

Show the answer

Answer: b

All three test the same null (a unit root in every unit). The inverse normal, the χ²-based Pm and the logit give extreme p-values different pull, which is why the choice belongs in the analysis plan.

Combination tests allow different lags for each unit, and an unbalanced panel. Would your data need that?

06

Common and reversed

Read

On the stationary series, Levin–Lin–Chu gives t∗t^* = −5.13, p < .001.

Hadri tests the opposite null on the same series, so you'd expect no rejection. Yet it gives Z = 6.74, p < .001.

Hadri's test is known to reject too often when series are persistent or panels are short. Don't let this test alone overturn a conclusion.

07

Shared shocks

Predict

Predict first

Countries share oil-price shocks and global recessions. The first-generation tests assume independent units. What does shared variation do to them?

They become conservativeThey reject too oftenNothing changes
Reveal

They tend to reject too often, since a shared shock counts as many separate pieces of evidence. Pesaran CIPS adds cross-sectional averages to each ADF regression. On the unit-root series, it gives −1.83, p = .361, compatible with a unit root.

08

Check your understanding

Checkpoint

Check yourself

Maddala–Wu with 8 units is compared with a chi-square distribution with how many degrees of freedom?

Show the answer

Answer: 16

2N=162N = 16.

Check yourself

Which test assumes one common autoregressive parameter under the alternative?

Show the answer

Answer: a

That is a strong assumption, and unrealistic for many panels. IPS and the combination tests relax it.

Check yourself

A Pesaran CD test shows strong cross-sectional dependence. Which test should you lean on?

Show the answer

Answer: c

CIPS is built for common shocks. The first-generation tests assume independent units.

09

Do it in CodeSplash

In the app

Set Value, Unit and Time, then the Test. It's also the Panel step in the Series lab.

Python
# No standard Python package; run ADF per unit with arch, then combine.
import numpy as np
import pandas as pd
from arch.unitroot import ADF
from scipy import stats

df = pd.read_csv("panel.csv")
ps = [ADF(g.sort_values("year")["y"]).pvalue for _, g in df.groupby("unit")]
P = -2 * np.log(ps).sum()
print(P, stats.chi2.sf(P, 2 * len(ps)))  # Maddala-Wu
R
# install.packages("plm")
library(plm)
df <- read.csv("panel.csv")
pd <- pdata.frame(df, index = c("unit", "year"))
purtest(y ~ 1, data = pd, test = "ips", lags = "AIC", pmax = 4)
purtest(y ~ 1, data = pd, test = "madwu", lags = "AIC", pmax = 4)
cipstest(pd$y, type = "drift")
10

Recap

Recap
  • Pooling many short series adds power, at the cost of assumptions about the units.
  • Rejecting "all have a unit root" means some don't. It doesn't mean all don't.
  • First-generation tests assume independent units; CIPS allows shared shocks.
  • Hadri reverses the null, and it can over-reject on persistent series.

Concepts in this lesson