*! version 1.0.0 09jun2026

Title

xttestpanel postestimation -- Postestimation diagnostics after xtreg

Description

xttestpanel is designed to be used the way most applied researchers work:
fit your panel model once with xtreg, then run the diagnostics on
the model in memory. When you call any subcommand without a varlist, it reads
the dependent variable, the regressors, the model type (FE/RE/pooled) and the
estimation sample e(sample) directly from the last estimation results and runs
the test on exactly that specification.

Each subcommand also preserves and restores your e(): it saves your
estimation results on entry and puts them back on exit (even if an error occurs).
You can therefore run as many tests as you like, in any order, after a single
xtreg -- without refitting and without losing your estimates.

Syntax

xtreg depvar indepvars [if] [in], fe|re

xttestpanel subcommand [, options]

where subcommand is het, serial,
csd, func,
hausman, vif, or all.

Supported estimators in memory

Last command Detected model

xtreg ..., fe one-way fixed effects

xtreg ..., re one-way random effects

regress ... pooled OLS (for csd)

reghdfe ... two-way fixed effects

If the test you request requires a different or additional model than the one in
memory (for example the FE-only functional-form test, the RE heteroskedasticity
variant, or the Hausman test that needs both FE and RE), xttestpanel refits
that model internally and prints a note; your own e() is restored afterwards.

What is reused from e()

o depvar - from e(depvar).

o regressors - the column names of e(b) (the constant is dropped).

o model type - from e(model) / e(cmd) (overridable with model()).

o estimation sample - from e(sample), so the tests use exactly the observations your model used.

Which model each test uses

Subcommand Model used

het the model in memory (or model(fe|re|tw))

serial the model in memory (FE or RE)

csd the model in memory (FE, RE or pooled)

func always FE (Lin-Li-Sun is an FE test; refits FE if needed)

hausman both FE and RE (fit internally; model in memory irrelevant)

vif the within design (FE) of the regressors

Recommended workflow

Fit once, then test:

. xtset id year

. xtreg y x1 x2 x3, fe

. xttestpanel all // whole battery + decision summary

or run individual tests with their graphs:

. xttestpanel het, graph

. xttestpanel serial, lags(2) graph

. xttestpanel csd, graph

. xttestpanel vif, graph

. xttestpanel hausman, graph

. xttestpanel func, reps(299)

You can also get the whole battery plus a single combined diagnostic figure:

. xttestpanel all, dashboard

Worked example

. webuse nlswork, clear

. xtset idcode year

. xtreg ln_wage age tenure hours, fe

. xttestpanel all

. xttestpanel het, graph

. xttestpanel serial, lags(2)

Switching the model in memory switches what the tests run on:

. xtreg ln_wage age tenure hours, re

. xttestpanel het // now the RE heteroskedasticity variant

Collecting results for a table

Every subcommand returns its statistics in r(); all returns the headline
p-values. This makes it easy to build your own results table:

. xtreg y x1 x2 x3, fe

. xttestpanel all

. scalar p_csd = r(p_csd)

. scalar p_ser = r(p_serial)

. scalar p_het = r(p_het)

or, test by test:

. xttestpanel csd

. di "Pesaran CD = " r(cd) " p = " r(p_cd)

Notes and cautions

o The data must be xtset (panel and time variables).

o Time-series operators in the underlying tests assume reasonably regular
spacing; large gaps are skipped pair-by-pair.

o func is O(n^2) and is capped at n = 5000 observations.

o If you give a varlist explicitly, the command runs standalone and
ignores whatever is in e(); this is handy for ad-hoc checks but the
postestimation form is the recommended workflow.

o If no estimation results are in memory and you give no varlist,
xttestpanel stops with an informative error telling you to fit a model first
or to supply variables.

Also see

Overview: xttestpanel

Subcommands: het,
serial,
csd,
func,
hausman,
vif

Author

Merwan Roudane - merwanroudane920@gmail.com -
github.com/merwanroudane