help xtcd2 v. 4.2 - May 2023
SJ18-3: st0536

Title

xtcd2 - testing for weak cross sectional dependence.

Syntax

xtcd2 [varlist] [if] [,pesaran cdw pea cdstar
rho
pca(integer)
reps(integer)
kdensity name(string)
heatplot[(absolute options_heatplot)] contour[(absolute options_contour) noadjust]
seed(integer)
]

varlist is the name of residuals or variables to be tested for weak cross sectional dependence.
varlist may contain time-series operators, see tsvarlist.
varlist is optional if the command is performed after an estimation (postestimation).

Contents

Description

Options

Saved Values

Examples

References

About

Description

xtcd2 tests residuals or a variables for weak cross sectional dependence in a panel data model.
It implements the tests by Pesaran (2015, 2021),
the weighted CD test (CDw) by
Juodis & Reese (2022) including the power enhancement (Fang et al., 2015).
It also implements the CD* from Pesaran & Xie (2021).
As a default all four test statistics are calculated and presented next to each other.
p-values are displayed in parenthesis.

Cross sectional dependence in the error term occurs if dependence between cross sectional units in a regression is not accounted for.
The dependence between units violates the basic OLS assumption of an independent and identically distributed error term.
In the worst case cross sectional dependence in the error term can lead to omitted variable bias or endogeneity and therefore to inconsistent estimates.
Cross sectional dependence can be measured as the correlation between units.
For example the correlation of the errors of unit i and unit j can be calculated.
Obviously, if the correlation is large, cross sectional dependence is present.

The "original" CD Test (Pesaran, 2015)

Pesaran (2015)
develops a test for weak cross sectional dependence based on this principle.
Weak cross sectional dependence means that the correlation between units at each point in time converges to zero as the number of cross section goes to infinity.
Under strong dependence the correlation converges to a constant.
The null hypothesis of the test is, that the error term (or variable) is weakly cross sectional dependent.
This means that correlation between an observation of unit i in time t and unit j in time t is zero.
The hypothesis is:

H0: errors are weakly cross sectional dependent.

Pesaran (2015) derives a test statistic, which sums the correlation coefficients of the different units.
The test statistic for a balanced panel is:

CD = [2*T / (N*(N-1))]^(1/2) * sum(i=1,N-1) sum(j=i+1,N) rho(ij),

and for an unbalanced panel (see Chudik, Pesaran, 2015):

CD = [2 / (N*(N-1))]^(1/2) * sum(i=1,N-1) sum(j=i+1,N) [T(ij)^(1/2) * rho(ij)],

where rho(ij) is the correlation coefficient of unit i and j and T(ij) the number of common observations between i and j.
Under the null hypothesis the statistic is asymptotically

CD ~ N(0,1)

distributed.

Weighted CD test (Juodis and Reese, 2022)

xtcd2 further implements three alternatives to test for weak cross-sectional dependence.
It includes the weighted CD (CDw) test proposed by Juodis and Reese (2022).
Juodis and Reese (2022) show that the CD test diverges if the time dimension grows and
the test is applied to residuals after a CCE or FE regression. The CDw test weights each observation by cross-section specific Rademacher weights.
The pair wise correlations are calculated as:

rho(ij) = sum(t=1,T) w(i)eps(i,t)eps(j,t)w(j)

where w(i) and w(j) are the Rademacher weights
which take on the values 1 or -1 with equal probability.
To reduce the dependence on the random Rademacher weights,
the draw can be repeated using the reps() option.

Power Enhanced CD test (Juodis and Reese, 2022 and Fan et al., 2015)

A second alternative proposed by Juodis and Reese (2022) is the
Power Enhancement Approach (PEA) by Fan et al. (2015).
The power of the CD test is improved by calculating the CD test as:

CD = [2*T / (N*(N-1))]^(1/2) * sum(i=1,N-1) sum(j=i+1,N) rho(ij) + sum(i=2,N)sum(j=1,N-1}|rho(ij)|*(|rho(ij)>2 log(N)^(1/2)T^(-1)

Fan et al. (2015) show that the PEA works if the number of cross-sectional units (N) is very large.
Therefore it is advisable to use the PEA method only for such datasets.

CD Star (Pesaran & Xie, 2021)

As forth test xtcd2 implements the bias corrected CD* test from
Pesaran & Xie (2021).
The bias corrected test statistic is based on the following:

CD* = (CD + (T/2*Theta)^(1/2))/(1-Theta)

where Theta is the bias correction and a function of the estimated factor loadings.
The factor loadings are estimated using the first p principal components as factors.
Option pca() specifies the number of principal components. Default is 4.
In case of unbalanced panels an Expected Maximisation algorithm taken from
xtnumfac is used.

xtcd2 calculates the CD test statistic for given variables, or if run after an estimation command which supports predict and e(sample).
In the latter case xtcd2 calculates the error term using predict, residuals and then applies the CD test from above.
xtcd2 supports balanced as well as unbalanced panels.
Furthermore by specifying the kdensity option, a kernel density plot with the distribution of the cross correlations is drawn.

If xtcd2 is used after xtreg, then the residuals are calculated using predict, e rather than predict, res.
That is the residuals including the fixed- or random-error component, see xtreg postestimation.
In all other cases predict, residuals is used to calculate the residuals.

xtcd2 can draw heatplots and contour plots
of the cross-correlations.
To draw heatplots Ben Jann's heatplot is required.
Contour plots are drawn using Stata's twoway contour.

Options

pesaran calculates the original CD test by Pesaran (2015),
see Description of Pesaran (2015).

cdw calculates the weighted CD test following Juodis and Reese (2019), see Description of Juodis and Reese (2021).
Results vary if seed not specified.

pea uses the Power Enhancement Approach (PEA) by Fan et al. (2015), see Description of Fan et al. (2015).
This method is designed for large panel panel datasets.

cdstar calculates the bias corrected CD test following Pesaran & Xie (2021),
see Description of Pesaran & Xie (2021).

reps(integer) number of repetitions for the weighted CD test.
Implies option cdw. Default is 30.

pca(integer) number of Principal Components when using the bias corrected CD test.
Requires option cdstar.
Default is 4.

rho saves the matrix with the cross correlations in r(rho).

kdensity plots a kernel density plot of the cross correlations, see twoway kdensity.
The number of observations, the mean, percentiles, minimum and maximum of the cross correlations are reported.
If name(string) is set, then the histogram is saved and not drawn.

name(string) saves the kdensity.

heatplot[(absolute options_heatplot)] draws a heatplot of the cross-correlations.
options_heatplot are options to be passed to heatplot.
absolute uses the absolute values of the cross-correlations.

contour[(absolute options_contour)] draws a contour plot of the cross-correlations.
options_contour are options to be passed to twoway contour.
absolute uses the absolute values of the cross-correlations.

noadjust do not remove cross-section specific means for calculation of cross-correlations.
This was the default in versions prior 2.3.

seed(integer) sets the seed for the weighted CD test.

Saved Values

xtcd2 stores the following in r():

Matrices
r(CD) matrix of CD test statistics
r(p) matrix of p-values of CD test statistic
r(rho) cross correlation matrix, if requested and one variable used.
r(rho_varname) cross correlation matrix, if requested and more than one variable is used.

Examples

An example dataset of the Penn World Tables 8 is available for download here.
The dataset contains yearly observations from 1960 until 2007 and is already tsset.
Estimating a simple panel version of the Solow model and run the CD test afterwards:

reg d.log_rgdpo log_hc log_ck log_ngd

xtcd2

Predicting the error terms after reg, leads to the same result:

reg d.log_rgdpo log_hc log_ck log_ngd

predict res, residuals

xtcd2 res

The test statistic is 36.34 and the p-value is 0,
therefore rejecting the null hypothesis of weak cross sectional dependence.

To draw a density plot with the cross correlations the kdensity option is used:

xtcd2 res, kdensity

The CD test statistic is known to diverge if many periodic
specific parameters are used (Juodis, Reese, 2021).
Unit specific rademacher weights can be applied to prevent this behaviour
by using the option cdw:

xtcd2 res, cdw

To reduce the dependence of the weighted CD test statistic,
the test can be repeatedly performed with different weights using
the reps() option:

xtcd2 res, cdw reps(20)

To improve the power of the weighted CD test, the Power Enhancement
Approach can be applied by using the pea option:

xtcd2 res, pea

Testing the variable log_rgdpo for cross sectional dependence reads:

xtcd2 log_rgdpo, noestimation

References

Chudik, A., Pesaran, M. H. 2015. Large Panel Data Models with Cross-Sectional Dependence A Survey.
Oxford Handbook of Panel Data. Edition 1. Editor Badi H. Baltagi.

Juodis, A., & Reese, S. 2022. The Incidental Parameters Problem in Testing for Remaining Cross-section Correlation. Journal of Business Economics and Statistics. 40(3).

Fan, J., Y. Liao & J. Yao. 2015. Power Enhancement in High-Dimensional Cross-Sectional Tests. Econometrica(83): 1497–1541.

Feenstra, R. C., R. Inklaar, and M. Timmer. 2015. The Next Generation of the Penn World Table.
American Economic Review . www.ggdc.net/pwt

Pesaran, M. H. 2015. Testing Weak Cross-Sectional Dependence in Large Panels.
Econometric Reviews 34(6-10): 1089-1117.

Pesaran, M. H. 2021.
General diagnostic tests for cross-sectional dependence in panels.
Empirical Economics 60: 13-50.

Pesaran, M. H. & Xie, Y. 2021.
A Bias-Corrected CD Test for Error Cross-
Sectional Dependence in Panel Data Models
with Latent Factors.
Cambridge Working Papers in Economics 2158.

Author

Jan Ditzen (Free University of Bozen-Bolzano)

Email: jan.ditzen@unibz.it

Web: www.jan.ditzen.net

Thanks to Achim Ahrens and Simon Reese for providing many helpful comments to the code and an anonymous reviewer for many helpful comments.
The code for the bias corrected CD test was provided by H. Pesaran and Y. Xie.
The code for the EM algorithm is taken from xtnumfac.
Thanks to Simon Reese for his help with it.

Also see

See also: xtdcce2, xtcse2