DPredict · Guide test 225
Wooldridge test for panel serial correlation
Tests serial correlation of idiosyncratic errors in suitable panel regression models.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Panel data models (fixed effects, random effects, first differences) — When the same units are measured repeatedly, how does the outcome change when a unit's own treatment changes?
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 · Wooldridge test for panel serial correlation
Not 0: random effects are inconsistent, fixed effects are not.
A shock shared by every unit each period: cross-sectional dependence.
Errors carry φ × last period's error.
Your data
Simulated with known truth15 units over 6 periods. Lines offset from each other are unit effects (SD of the unit means 1.01); lines that rise and fall together share a common shock; smooth runs within a line are serial correlation.
If H₀ were true
- The reference: how F varies across samples when H₀ is true (cluster-robust F).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .096).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- within (fixed-effects) residuals
- their correlation under no serial correlation: demeaning induces it
- unit-clustered standard error
The verdict
F(1, 73) = 2.84, p = .096
p > α = .050: compatible with H₀
Serial correlation leaves the FE estimate unbiased but its usual SEs too small; cluster by unit.
- Statistic
- 2.843
- p-value
- 0.0961
Wooldridge test for panel serial correlation on a balanced panel of 15 units × 6 periods: F(1, 73) = 2.84, p = .096. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: no serial correlation in the idiosyncratic panel errors.
Assumptions
Independent clusters with enough clusters for cluster-robust inference; correctly specified panel mean and exogeneity assumptions.
Formula
Parameters and notation
The displayed Wooldridge first-difference version exploits Corr(Δuit,Δui,t−1)=−1/2 under serially uncorrelated homoskedastic level errors. A within-residual version instead tests coefficient −1/(T−1) in a balanced panel.
Structure of the method
Fit the stated panel model, form the appropriate transformed residuals, regress residuals on their lags, and test the transformation-specific null coefficient with cluster-robust inference. First-difference and within-residual versions share a motivation but use different null restrictions and input model types.
Estimated and nuisance parameters
Estimate the panel mean coefficients, residuals, auxiliary autoregressive coefficient, and cluster-robust covariance. The within transformation induces correlation even when level errors are serially uncorrelated; its null coefficient is therefore not zero. In balanced first-difference reasoning, the familiar adjacent-error correlation is minus one half under the required variance conditions.
Settings and design choices
Choose first-difference versus within version, level-error versus differenced-error null, panel/time indexes, and robust covariance settings. The supplied pwartest code is the within-residual version; pwfdtest with h0="fe" targets no serial correlation in levels through the minus-one-half restriction.
Fitting and adaptation
Refit the mean model and regenerate residuals after changes in regressors or sample. Maintain panel lag alignment rather than treating rows as a single continuous series. There is no neural adaptation; the relevant adaptation is selecting a valid auxiliary regression and covariance for the panel design and cluster count.
Sensitivity and robustness
Inspect missing periods, unequal time lengths, few clusters, time-varying variance, exogeneity violations, and common cross-sectional shocks. Robust standard errors do not fix a wrongly specified auxiliary null. Report the implementation/version and restriction so readers can distinguish the within and first-difference calculations.
How to use and calibrate
Use the version’s cluster-robust Wald/F test; specify first-difference versus within-residual construction.
Example application
Check residual serial correlation in a fixed-effects panel model.
Interpretation and pitfalls
Watch out
Testing the transformed residual coefficient against zero is wrong for these procedures. Unequal T and heteroskedasticity require the appropriate version.
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.
Python and R
Wooldridge test using fixed-effects residuals. This is the pwartest variant; pwfdtest is a distinct first-difference formulation.
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)
N<-20;TT<-25;d<-expand.grid(time=1:TT,id=1:N);d$x<-rnorm(nrow(d));a<-rnorm(N);d$y<-.5*d$x+a[d$id]+rnorm(nrow(d));pd<-plm::pdata.frame(d,index=c("id","time"))
fit<-plm::plm(y~x,pd,model="within");print(plm::pwartest(fit))
"""
# 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()
Validated — Executed successfully in the validation environment · needs plm
set.seed(2026)
N<-20;TT<-25;d<-expand.grid(time=1:TT,id=1:N);d$x<-rnorm(nrow(d));a<-rnorm(N);d$y<-.5*d$x+a[d$id]+rnorm(nrow(d));pd<-plm::pdata.frame(d,index=c("id","time"))
fit<-plm::plm(y~x,pd,model="within");print(plm::pwartest(fit))
Output
Wooldridge's test for serial correlation in FE panels data: fit F = 0.12516, df1 = 1, df2 = 478, p-value = 0.7237 alternative hypothesis: serial correlation
Sources
- plm — plm · pwfdtestAuthor documentation/source reviewed: plm 2.6-7.search.r-project.org
- plm — plm · pwartestAuthor documentation/source reviewed: plm 2.6-7.search.r-project.org
- pwfdtestsearch.r-project.org
- pwartestsearch.r-project.org
- pdata.framesearch.r-project.org
- plmsearch.r-project.org
- 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 225, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT225.