Skip to content

DTime series · ts.panel_unitroot

Panel unit-root tests

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

Levin–Lin–Chu (common root), Im–Pesaran–Shin (heterogeneous roots), Maddala–Wu and Choi (combined unit p-values), Hadri (H₀: all stationary) and Pesaran's CIPS (robust to cross-sectional dependence) on long panel data: one row per unit and time.

Verified in Python and R Python and R agree to 6 decimals Seeded Also called panel unit root, LLC test, Levin-Lin-Chu…

A real result

Example “Ips mixed”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

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).
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).

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Ips mixedts_panel · time: year · unit: unit · value: y_mixed
  • Llc stationaryts_panel · time: year · unit: unit · value: y_stationary
  • Maddala wu unit rootts_panel · time: year · unit: unit · value: y_unit_root
  • Choi logitts_panel · time: year · unit: unit · value: y_mixed
  • Choi mixed trendts_panel · time: year · unit: unit · value: y_mixed
  • Hadri stationaryts_panel · time: year · unit: unit · value: y_stationary
  • Hadri pooled variancets_panel · time: year · unit: unit · value: y_stationary
  • Hadri pooled trendts_panel · time: year · unit: unit · value: y_stationary

In the guides

Tests from the statistics guide this method runs

Where it sits in the decision guides

  • Time series (ARIMA, ETS) · DS & ML Decision Guide · Predict — forecast or classify outcomes

What you need

Valuenumeric · 1 column
The measured value for each unit in each period.
Unitcategorical · 1 column · 2–500 levels
Countries, stores, firms … one series each.
Timetemporal / numeric · 1 column
Orders each unit's rows; evenly spaced periods.

Choices you make

hypothesis

Testdefault ips

Unit-root tests: H₀ every unit has a unit root. Hadri reverses it: H₀ every unit is stationary.

  • Im–Pesaran–Shin W_t̄(default) — Averages unit ADF t's; the alternative lets some units be stationary.
  • Levin–Lin–Chu — Pools a common autoregressive root; the alternative is that all units are stationary with the same root.
  • Maddala–Wu (Fisher χ²) — −2 Σ ln p over the units' ADF p-values; works with unbalanced panels.
  • Choi inverse normal Z and Pm — Σ Φ⁻¹(p_i)/√N; Pm suits many units.
  • Pesaran CIPS — Adds cross-section averages to each unit's ADF to absorb common shocks; needs a balanced panel.
  • Hadri LM — KPSS averaged across units; each unit is scaled by its own variance unless you pick the pooled variance.
Deterministic termsdefault c

Deterministic terms per unit: a constant, or a constant and trend.

  • Constant per unit(default) — Gives each unit its own level; pick it when the series don't trend.
  • Constant and trend per unit — Gives each unit its own level and trend; pick it when the series drift up or down.

options

Also report the inverse-logit L*default off

Adds Choi's L* = scaled Σ ln(p/(1 − p)) on t(5N + 4), the third Choi statistic, as plm::purtest test = "logit".

ADF lags per unitdefault 1

Lagged differences in each unit's regression (not used by Hadri).

Hadri variancedefault unit

Which residual variance scales each unit's partial sums in the Hadri test.

  • Each unit's own variance(default) — Allows the units to have different variances (Hadri's heteroskedasticity-consistent form; plm with Hcons = TRUE).
  • One pooled variance — Assumes one common variance (Hadri's homoskedastic form; plm's default).
Simulationsdefault 300

Random-walk panels simulated to calibrate IPS / LLC moments and the CIPS p-value (shared random stream: identical in Python and R).

What it reports

n_units
How many independent units the analysis used; it sets precision and power.
n_periods
How many independent units the analysis used; it sets precision and power.
stat
A single number that summarizes how far your data are from what H₀ predicts.
p
How surprising your data would be if the null hypothesis were true, as a probability.
reject
A p-value below the chosen α; it says the data are hard to explain by chance alone, not that the effect matters.

Per group, level or term: test, tbar, t_pooled, lm, mw_stat, mw_p, choi_z, choi_p, choi_pm, choi_pm_p, choi_l, choi_l_df, choi_l_p, reps

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-8). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.

Default traps between the two languages

  • Hadri: the default scales each unit by its own residual variance and equals plm::purtest(test = 'hadri', Hcons = TRUE) (Z = 6.7434 on the stationary fixture); the pooled variance equals plm's default Hcons = FALSE (Z = 7.1446; 7.1096 with a trend). Checked against plm 2.6.
  • IPS and LLC standardize by null moments simulated for this panel's lengths and lags (instead of the published large-T tables), and CIPS takes its p-value from simulated random-walk panels — all on the shared Wichmann–Hill stream, so the engines agree; plm uses the published tables and differs at small T.
  • Maddala–Wu, Choi Z, Pm and L* combine each unit's ADF MacKinnon p-value from this method's unit regressions. plm::purtest's unit ADF t-values differ (about 4% larger in magnitude on the y_mixed fixture), so its combined statistics differ too (L* −2.15 here vs −2.49 in plm); applied to plm's own unit p-values, the L* formula used here reproduces plm's logit statistic exactly (crosscheck suite stat-options-211-314).
Python

The exact script CodeSplash ran for example “Ips mixed” · 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,
})
R

The exact script CodeSplash ran for example “Ips mixed” · 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
))

Sources

  • Levin, A., Lin, C.-F., & Chu, C.-S. J. (2002). Unit root tests in panel data. J. Econometrics, 108, 1–24.
  • Im, K. S., Pesaran, M. H., & Shin, Y. (2003). Testing for unit roots in heterogeneous panels. J. Econometrics, 115, 53–74.
  • Maddala, G. S., & Wu, S. (1999). A comparative study of unit root tests with panel data. Oxford Bulletin of Economics and Statistics, 61, 631–652.
  • Choi, I. (2001). Unit root tests for panel data. J. International Money and Finance, 20, 249–272.
  • Hadri, K. (2000). Testing for stationarity in heterogeneous panel data. Econometrics Journal, 3, 148–161.
  • Pesaran, M. H. (2007). A simple panel unit root test in the presence of cross-section dependence. J. Applied Econometrics, 22, 265–312.

From the CodeSplash method registry · ts.panel_unitroot v1.2.0.