Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • - xtcdf - now on SSC: Pesaran (2004, 2013) CD-test for cross sectional dependence

    Dear all

    xtcdf is now available on ssc, with thanks as always going out to Kit Baum. It performs the Pesaran (2004) CD-test for cross sectional dependence, which can be used to test whether your variables or residuals are correlated between groups in a panel setting. E.g. does employment in the different US states follow similar trends or do they move independently? Being aware of such correlations might have an impact on your estimates (see the cross sectional dependence literature), but it's also just good to know these things about your data. The program also reports the mean correlation coefficient.

    In the end, the CD test is based on a transformation of the sum of all pairwise correlations. The code is heavily based on -pwcorrf- (also on ssc), which calculates all these pairwise correlations in a more convenient and usually faster way than the official pwcorr command.

    You can specify as many variables as you want (it loops internally).

    Example usage (output at bottom of post)
    Code:
    sysuse xtline1.dta, clear
    xtcdf calories
    pwcorrf calories, reshape
    This is not the only command out there to calculate cd-tests.
    xtcsd was the first, but can only be used as a postestimation command
    xtcd is very slow in large datasets and reports the wrong average number of joint observations
    xtcd2 does not allow for multiple variables and assumes zero-mean variables (residuals)

    Moreover, xtcdf is built to handle panels where some groups do not share (at least 3) observations and hence lead to meaningless correlations. At the time of writing, the other commands behave erratically in this context. On the other hand, xtcd2 can produce kernel densities and a histogram of the pairwise correlations, which can be very useful.

    References
    Pesaran, M. Hashem. 2004. “General Diagnostic Tests for Cross Section Dependence in Panels.” CESifo Group Munich CESifo Working Paper Series 1229

    Click image for larger version

Name:	xtcdf.PNG
Views:	1
Size:	18.9 KB
ID:	1405949


  • #2
    Hi Jesse, what if 'xtcd' and 'xtcd2, noestimation' gives you contradicting results?

    Comment


    • #3
      Can you provide the output from the three commands?

      Comment


      • #4
        @Jesse Wursten can you explain the result ? is it acceptable to test one by one variable (each variable ) separately ? Many thanks

        Comment


        • #5
          Yes no problem to test variables separately

          Comment


          • #6
            hi Jesse Wursten thanks for this command.
            this commad says that
            Code:
            time variable not set, use tsset varname ...
            r(111);
            but then when i try to set time variable using
            Code:
            xtset panvar year, yearly
            i get the error of "repeated time values within panel". I know the problem for this error lies with tha panvar. then when i try to set a panvar that uniquely identifies the data set using
            Code:
            egen panvar = group (year exporter importer sector_code
            , the dataset gets xtset perfectly with the results
            Code:
            panel variable:  panvar (weakly balanced)
                    time variable:  year, 2008 to 2022
                            delta:  1 year
            but the problem arises using xtcdf command as the error "in-sufficient observations" pops up. again the problem lies with panvar as this panvar has frequency (1) less than the required frequency (3). so in all cases i am unable to use the xtcdf command. any solution.

            Comment

            Working...
            X