*! version 1.0.0 09jun2026

Title

xttestpanel -- Post-estimation diagnostic test suite for linear panel-data models

Syntax

Standalone form - estimates the model internally:

xttestpanel subcommand depvar indepvars [if] [in]
[, options]

Postestimation form - reuses the last xtreg / reghdfe:

xtreg depvar indepvars, fe

xttestpanel subcommand [, options]

With no varlist, xttestpanel pulls depvar, indepvars, the model
type and the estimation sample e(sample) from the results in memory. Tests
that require a different or additional model (the RE heteroskedasticity variant, the
FE-only functional-form test, or the Hausman test that needs both FE and RE) are
re-fitted automatically; a note is printed when that happens.

where subcommand is one of:

het heteroskedasticity tests

serial serial-correlation tests

csd cross-sectional dependence tests

func functional-form (nonparametric) test

hausman FE-vs-RE specification test (classical + robust)

vif multicollinearity (VIF + robust VIF)

all run the whole suite and print a combined report

The data must be xtset before use. depvar is the dependent variable and
indepvars the regressors of the panel model under scrutiny.

Description

xttestpanel is a unified library of modern post-estimation diagnostic tests for
linear panel-data regressions. Each subcommand estimates the requested model
internally (fixed effects, random effects, two-way, or pooled), extracts the
residuals, computes the relevant battery of tests, prints a clean formatted table,
and -- with the graph option -- produces a publication-quality diagnostic plot.
The all subcommand runs everything and adds a colour-coded decision summary
and an optional combined dashboard.

This is the overview page. Each subcommand has its own detailed help with the exact
statistics, formulas, assumptions and references:

het heteroskedasticity

serial serial correlation

csd cross-sectional dependence

func functional form

hausman FE vs RE specification

vif multicollinearity

Postestimation use (recommended)

xttestpanel is built first and foremost as a postestimation tool: fit your
panel model once with xtreg and then run the diagnostics on the model in
memory, with no need to respecify the variables.

. xtset id year

. xtreg y x1 x2 x3, fe

. xttestpanel all // the whole battery + decision summary

. xttestpanel het, graph // or one test at a time

. xttestpanel serial, lags(2)

With no varlist, each subcommand reads the dependent variable, regressors,
model type and estimation sample e(sample) from the fitted model, and restores
your e() on exit so you can chain any number of tests after a single
xtreg. Supported estimators in memory: xtreg, fe; xtreg, re;
regress (pooled); reghdfe (two-way). See
[help] xttestpanel postestimation for the full
details, the per-test model rules, and worked examples.

Subcommands at a glance

Subcommand Tests implemented

het Breusch-Pagan; Koenker (robust); Juhl & Sosa-Escudero (FE);
Feng, Li, Tong & Luo (two-way)

serial Baltagi & Li LM; Born-Breitung/Wooldridge robust; Bin Chen (2022) portmanteau

csd Pesaran CD; Baltagi-Kao-Peng bias-corrected CD; Breusch-Pagan LM; scaled LM

func Lin, Li & Sun (2014) kernel test with wild bootstrap

hausman classical Mundlak Hausman; Beyaztas et al. robust weighted Hausman

vif within-group VIF; Ismaeel-Midi-Sani robust VIF

Common options

model(string) selects the working model used to obtain residuals:
fe (default), re, tw (two-way FE), or pool.
Not every model is valid for every subcommand; see the subcommand help.

graph draws the diagnostic plot associated with the subcommand.

dashboard (with all) combines the het, func and serial plots into a
single panel.

Subcommand-specific options (z(), lags(), reps(), bw(),
tune()) are documented on each subcommand page.

Examples

Set up the panel:

. webuse nlswork, clear

. xtset idcode year

Postestimation form (reuse the fitted model):

. xtreg ln_wage age tenure hours, fe

. xttestpanel het

. xttestpanel all, dashboard

Run the entire suite standalone with a combined dashboard:

. xttestpanel all ln_wage age tenure hours, model(fe) dashboard

Individual tests:

. xttestpanel het ln_wage age tenure hours, model(fe) graph

. xttestpanel serial ln_wage age tenure hours, lags(2) graph

. xttestpanel csd ln_wage age tenure hours, graph

. xttestpanel func ln_wage age tenure hours, reps(299)

. xttestpanel hausman ln_wage age tenure hours, graph

. xttestpanel vif ln_wage age tenure hours, graph

Stored results

Each subcommand stores its statistics and p-values in r(); see the subcommand
help pages. all stores the headline p-values in
r(p_het), r(p_serial), r(p_csd), r(p_func),
r(p_hausman) and r(mean_vif).

References

Baltagi, B.H., B.C. Jung, and S.H. Song. 2010. Testing for heteroskedasticity
and serial correlation in a random effects panel data model. Journal of Econometrics
154: 122-124.

Baltagi, B.H., C. Kao, and B. Peng. 2016. Testing cross-sectional correlation in
large panel data models with serial correlation. Econometrics 4: 44.

Beyaztas, B.H., S. Bandyopadhyay, and A. Mandal. 2021. A robust specification
test in linear panel data models. arXiv:2104.07723.

Chen, B. 2022. A robust test for serial correlation in panel data models.
Econometric Reviews 41: 1095-1112.

Feng, S., G. Li, T. Tong, and S. Luo. 2020. Testing for heteroskedasticity in
two-way fixed effects panel data models. Journal of Applied Statistics 47: 91-116.

Ismaeel, S.S., H. Midi, and M. Sani. 2021. Robust multicollinearity diagnostic
measure for fixed effect panel data model. Malaysian Journal of Fundamental and
Applied Sciences 17: 636-646.

Juhl, T., and W. Sosa-Escudero. 2014. Testing for heteroskedasticity in fixed
effects models. Journal of Econometrics 178: 484-494.

Lin, Z., Q. Li, and Y. Sun. 2014. A consistent nonparametric test of parametric
regression functional form in fixed effects panel data models. Journal of
Econometrics 178: 167-179.

Pesaran, M.H. 2004/2015. Testing weak cross-sectional dependence in large panels.
Econometric Reviews 34: 1089-1117.

Author

Merwan Roudane

merwanroudane920@gmail.com

https://github.com/merwanroudane