*! version 1.0.0 09jun2026

Title

xttestpanel het -- Heteroskedasticity tests for panel-data models

Syntax

xttestpanel het [depvar indepvars] [if] [in]
[, model(string) z(varlist) robust graph]

Postestimation form (no varlist) reuses the last xtreg/reghdfe;
see the overview.

Description

xttestpanel het tests the null of homoskedastic idiosyncratic disturbances
in a panel regression. It fits the requested model, takes the residuals, and runs a
battery of artificial-regression LM tests of squared residuals on auxiliary
regressors z (the model regressors by default).

The variants reported depend on model():

fe (default) within (FE) residuals; reports the Breusch-Pagan and
Koenker statistics plus the Juhl & Sosa-Escudero (2014) F form, which is valid
for fixed-effects models with large N.

re random-effects residuals; the Breusch-Pagan/Koenker LM corresponds to
the Holly-Gardiol / Baltagi-Jung-Song test of homoskedastic individual effects.

tw two-way fixed effects (uses reghdfe if installed, else an
internal two-way within transform); reports the conditional-moment test of
Feng, Li, Tong & Luo (2020).

Options

model(fe|re|tw) working model; default fe.

z(varlist) auxiliary regressors used in the variance equation; default
is the model's own regressors.

robust emphasises the Koenker (studentized) statistic, which is robust to
non-normal errors. Both BP and Koenker are always printed.

graph scatter of squared residuals against the first z with a lowess
fit; an upward/curved fit signals heteroskedasticity.

Statistics

Let e be the residuals, s2 = mean(e^2), and W = (1, z).

o Breusch-Pagan: BP = 0.5 x ESS from regressing e^2/s2 on W;
~ chi2(p).

o Koenker (robust): K = n x R^2 from regressing e^2 on W;
~ chi2(p). Robust to non-normality.

o Juhl-Sosa-Escudero / Feng et al.: F (or CM) form of the same auxiliary
regression on the appropriate (FE or two-way) residuals.

Stored results

r(bp) Breusch-Pagan statistic

r(p_bp) its p-value

r(koenker) Koenker statistic

r(p_koenker) its p-value

r(df) degrees of freedom

r(model) model used

Examples

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

. xttestpanel het ln_wage age tenure hours, model(tw)

. xtreg ln_wage age tenure hours, re

. xttestpanel het

References

Juhl, T., and W. Sosa-Escudero. 2014. Journal of Econometrics 178: 484-494.

Feng, S., G. Li, T. Tong, and S. Luo. 2020. Journal of Applied Statistics 47: 91-116.

Holly, A., and L. Gardiol. 2000. In Panel Data Econometrics (Krishnakumar & Ronchetti, eds).

Author

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