*! version 1.0.2 26aug2016

xtcdf

xtcdf -- CD-test for cross-sectional dependence, see Pesaran (2004/2015).

Syntax

xtcdf
varlist

Description

xtcdf calculates the CD-test for cross-sectional dependence described in Pesaran (2004) and Pesaran (2015) for a varlist of any length.

The test can best be seen as an investigation of the mean correlation between panel units. The main insight of Pesaran (2004) is that a transformation of the sum of pairwise correlations
between panel units is standardnormally distrubuted. The null hypothesis is either strict cross-sectional independence (Pesaran, 2004) or weak cross-sectional dependence (Pesaran, 2015).

The test is suited for both balanced and unbalanced panels. In unbalanced panels, the command ignores combinations of panel units which have fewer than three joint observations
as correlations are not meaningful with two or fewer observations. A warning will be shown in the results table.

Assume we have a variable x, present in N panel units and up to T time periods (t). Then the statistic is calculated as follows:

Standard deviation s_i = sqrt(1/(T_i-1) * sum(over t)(x_it - mean(x_it))^2)
Correlation coeff r_ij = 1 / (T_i-1) * sum(over t)[(x_it - mean(x_it))/s_i * (x_jt - mean(x_jt))/s_j]
Test statistic CD = sqrt(2/(N*(N-1)) * sum(over i and j)[sqrt(T_ij) * r_ij]

Under the null hypothesis of cross sectional independence / weak cross sectional dependence, the CD-statistic is distributed ~ N(0,1). Extreme values indicate there is some
(strong) correlation between panel units.

Remarks

There are several other commands calculating this test. The first was xtcsd, which was only usable as a post-estimation command. xtcd generalised this to allowing any variable (list) to be analysed. xtcd2 added
some useful features, e.g. histograms of the correlations and more postestimation possibilities. Initially, I did not publish this command on ssc, given that there were already so many other options. I decided to do so in the end because
this version is considerably faster than xtcd and xtcd2 produced strange results (differing from xtcd) at the time of writing. Moreover, xtcd2 can only test one variable at a time.

The f-suffix stands for fast. This command is largely based on pwcorrf, which is a faster way to calculate pairwise correlations than Stata's pwcorr. It also has options to calculate correlations across panel units instead of
across variables.

Any mistakes are my own.

Examples

. sysuse xtline1.dta, clear

. gen x = rnormal()

. xtreg calories x, fe

. predict res, r

. xtcdf calories res

. sum day

. replace calories = . if day < r(mean) & person == 1

. replace calories = . if day >= r(mean) & person == 2

. xtcdf calories

Stored results

xtcdf stores the following in r():

Matrices

r(p) p values

r(CD) values of the CD statistics

Scalars

r(pvaluei) The p-values are also stored as scalars (often more convenient)

r(qpi) Same for the cd-statistics

References

General diagnostic tests for cross section dependence in panels, Pesaran, M. H., CESifo Working Paper No. 1229, 2004

Testing Weak Cross-Sectional Dependence in Large Panels, Pesaran, M. H., Econometric Reviews, 2015

Author

Jesse Wursten
Faculty of Economics and Business
KU Leuven
jesse.wursten@kuleuven.be