>> Home >> Resources & support >> FAQs >> Testing for panel-level heteroskedasticity and autocorrelation

How do I test for panel-level heteroskedasticity and autocorrelation?

Title   Testing for panel-level heteroskedasticity and autocorrelation
Author Vince Wiggins, StataCorp
Brian Poi, StataCorp


I see how one can correct for potential heteroskedasticity across panels using xtgls, but I am unsure of a simple way to test for it.


Since iterated GLS with only heteroskedasticity produces maximum-likelihood parameter estimates, we can easily do an LR test.

We can type

. xtgls ... , igls panels(heteroskedastic) . estimates store hetero

to fit the model with panel-level heteroskedasticity and save the likelihood.

We can fit the model without heteroskedasticity by typing

. xtgls ...

Now there is one trick. Normally, lrtest infers the number of constraints when we fit nested models by looking at the number of parameters estimated. For xtgls, however, the panel-level variances are estimated as nuisance parameters, and their count is NOT included in the parameters estimated. So, we will need to tell lrtest how many constraints we have implied.

The number of panels/groups is stored in e(N_g) and, in the second model, we are constraining all of these to be single value, so our number of constraints can be computed and stored in a local macro by typing

. local df = e(N_g) - 1

The test is then obtained by typing

. lrtest hetero . , df(`df')


Iterated GLS with autocorrelation does not produce the maximum likehood estimates, so we cannot use the likelihood-ratio test procedure, as with heteroskedasticity. However, Wooldridge (2002, 282–283) derives a simple test for autocorrelation in panel-data models. Drukker (2003) provides simulation results showing that the test has good size and power properties in reasonably sized samples.

There is a user-written program, called xtserial, written by David Drukker to perform this test in Stata. To install this user-written program, type

. findit xtserial . net sj 3-2 st0039 (or click on st0039) . net install st0039 (or click on click here to install)

To use xtserial, you simply specify the dependent and independent variables:

. xtserial depvar indepvars

A significant test statistic indicates the presence of serial correlation.


Drukker, D. M. 2003.
Testing for serial correlation in linear panel-data models. Stata Journal  3: 168–177.
Wooldridge, J. M. 2010.
Econometric Analysis of Cross Section and Panel Data. Cambridge, MA: MIT Press.





The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ YouTube
© Copyright 1996–2017 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us