Announcement

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

  • Testing cross sectional dependency for unbalanced panel data sets

    Dear Statalisters,

    I have an unbalanced panel data set (N=18201 and T=17). It has a hierarchical structure where 18201 firms are nested within 66 countries. I will use Stata's "mixed" command to analyse this data set. First of all, I wanted to test stationarity. In order to decide whether to use the first generation or the second generation of panel unit root tests I tried to test cross sectional dependency using the following command in Stata/SE 14.2:

    Code:
    set maxvar 15000
    
    set matsize 11000
    
    xtreg LTAT profitability tangibility size nondebt currentliq locnum developing corruption inflation correctedadris2005 finsistem creditorrights, re
    
    xtcsd,pesaran
    Stata issued the following error message:

    Code:
    Error: The panel is highly unbalanced.
    Not enough common observations across panel    to    perform    Pesaran's    test.
    insufficient observations
    r(2001);
    As far as I know pesaran (2004) CD test for cross sectional dependence should allow missing observations in the data set. I would appreciate any suggestions about how can I solve this problem and test the existence of cross sectional dependency in my data set.

    An example of my data set can be seen below.

    Thanks in advance.

    Rumeysa




    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long gvkey float date str3 ficnumer float(LTAT profitability tangibility size nondebt currentliq) long    locnum    float(developing    inflation)    byte(corruption    correctedadris2005    creditorrights)    float    finsistem
    1166 2000 "NLD"  .4623583     .2465126  .4124843   6.65665  .07265085  .7163265 79 1 2.317 83 4 3         .
    1166 2001 "NLD" .43914855    .03203292 .52351385  6.629449  .05648524  .6280003 79 1 4.162 83 4 3   .946948
    1166 2002 "NLD"  .4454462  -.009179601 .55429226  6.482864  .06131613  .6301853 79 1 3.287 83 4 3 1.2832673
    1166 2003 "NLD"  .5505272   .021120004    .47063  6.510706  .05601211  .6952347 79 1 2.113 83 4 3  1.288889
    1166 2004 "NLD" .57799387    .10735293   .412554  6.713969  .04454538  .6990122 79 1 1.238 83 4 3  1.376339
    1166 2005 "NLD" .55896163    .07586039  .5050621   6.69988  .04647744  .6903945 79 1 1.674 83 4 3 1.3447064
    1166 2006 "NLD" .52976644    .15556946    .45896  6.724189  .04506324  .7407428 79 1 1.168 83 4 3 1.0678978
    1166 2007 "NLD"  .4769907    .17538166  .4578292  6.733798  .04122294  .7539297 79 1 1.614 83 4 3 1.0048811
    1166 2008 "NLD"  .4229719     .0888059 .56348544  6.643527  .04514208  .7289625 79 1 2.487 83 4 3 2.7049854
    1166 2009 "NLD"  .5468909    .04077844  .4853939  6.747234  .04037689  .7612622 79 1  1.19 83 4 3  1.819896
    1166 2010 "NLD"  .4669155    .27990714  .4458549  7.101772  .02952104  .7694061 79 1 1.276 83 4 3  1.455622
    1166 2011 "NLD"  .3947028    .16976643  .3936384  7.366585 .029688647  .7557598 79 1 2.341 83 4 3 1.7415082
    1166 2012 "NLD"  .2997774    .05945091  .4424851  7.312891  .03795784  .7391627 79 1 2.456 83 4 3  1.505547
    1166 2013 "NLD" .06704275  -.008357781  .1101087  7.346816 .029209366 .33395025 79 1 2.507 83 4 3 1.2206857
    1166 2014 "NLD" .07484292    .03727449 .10746863  7.510394  .02393465  .3382719 79 1  .976 83 4 3  1.296265
    1166 2015 "NLD" .06146407    .04902559 .11388373  7.638187 .026211755  .3227285 79 1    .6 83 4 3 1.1483186
    1166 2016 "NLD" .06163445     .0295448 .12202416  7.672415 .028044984  .3029122 79 1  .317 83 4 3         .
    1491 2000 "ISR" .42846245    .05989408  .8355724  6.881346 .029347925  .3677757 52 1 1.125 64 4 3  1.436591
    1491 2001 "ISR"  .3969705   .019508384  .8622434  6.966996  .02764104  .3451483 52 1 1.116 64 4 3   1.74009
    1491 2002 "ISR"  .3812982    .03464782  .8844622  7.037149 .025402017   .341767 52 1 5.687 64 4 3 2.2952032
    1491 2003 "ISR"  .5098997   .037169844  .7609318  7.133514 .021661663   .429756 52 1   .67 64 4 3   1.38293
    1491 2004 "ISR"   .505059    .04639591  .8383284  7.058231  .02463293  .3429254 52 1 -.414 64 4 3 1.0979493
    1491 2005 "ISR" .54715085    .04134256  .9153395  7.052512 .027344825  .2944094 52 1 1.327 64 4 3  .8977114
    1491 2006 "ISR"  .6327906     .0776809  .9454115  7.067564 .027237155   .332795 52 1 2.114 64 4 3  .7134123
    1491 2007 "ISR"  .4859344    .05713812  .8665708   7.18468  .02643156   .395152 52 1   .51 64 4 3  .5167069
    1491 2008 "ISR"   .629357   .009316108  .8228809   7.62271  .02867089   .419534 52 1 4.597 64 4 3 1.4182013
    1491 2009 "ISR"  .6294004 -.0006808199  .6842667  7.747737  .03391234  .3249043 52 1 3.325 64 4 3  .7359741
    1491 2010 "ISR"  .6561904    .01278359   .919082  7.927914 .031558957   .391724 52 1 2.693 64 4 3  .7049592
    1491 2011 "ISR"  .6928116  -.014045293  .9825891  7.882449  .04288899  .4197466 52 1 3.459 64 4 3 1.1511059
    1491 2012 "ISR"  .6910992   .005317588 1.0011824  7.877648   .0419178   .425989 52 1 1.708 64 4 3  1.079383
    1491 2013 "ISR"  .6896436   -.02061335 1.1146095  7.774942  .04654683  .4042173 52 1 1.526 64 4 3  .9494749
    1491 2014 "ISR"  .7564474  -.020574573 1.0917907  7.797141  .04728934  .4669977 52 1  .476 64 4 3 1.0200945
    1491 2015 "ISR"  .6161085   .005234431  .8866487  7.846706  .03740706  .6106265 52 1 -.633 64 4 3  .8175914
    1491 2016 "ISR"  .5612572    .02682071 1.0020133  7.729914  .03944087 .57355964 52 1 -.545 64 4 3         .
    1932 2000 "GBR"  .6847501    .09796631 .29451862  9.784197  .04377218  .4092727 38 1  .785 29 . 2  .7364442
    1932 2001 "GBR"  .7049913    .12629135  .3095763  9.754407  .04573419  .4190366 38 1 1.236 29 . 2  .9159525
    1932 2002 "GBR"   .665234     .1338573  .3211961  9.698061  .04396414  .4062385 38 1 1.256 29 . 2  1.194582
    1932 2003 "GBR"  .7519364    .11665525 .28225935  9.851089  .04647242   .397492 38 1 1.363 29 . 2 1.0934291
    1932 2004 "GBR"  .6935958    .11597647 .26227653  9.779963   .0478615  .3455533 38 1 1.345 29 . 2 1.1752523
    1932 2005 "GBR"  .6389458    .13624193  .2579409  9.854665 .017063055  .3099701 38 1  2.05 29 . 2 1.1860054
    1932 2006 "GBR"  .6237624    .15751575 .25905716  9.785604 .019858235  .3032741 38 1 2.334 29 . 2 1.0978212
    1932 2007 "GBR"  .6209953      .159387  .2581162  9.837775 .016979923 .28652287 38 1 2.321 29 . 2  1.365892
    1932 2008 "GBR"   .738122    .13175565 .22329497 10.223794 .015244456  .3173025 38 1 3.613 29 . 2 2.9817605
    1932 2009 "GBR"  .7027128      .166078 .23070565 10.189193   .0189374 .30457655 38 1 2.166 29 . 2         .
    1932 2010 "GBR"  .6572864    .17889448  .2362886 10.234947 .018090453 .31073225 38 1 3.286 29 . 2         .
    1932 2011 "GBR"  .6875253    .19266935 .23205133  10.20799 .018621631   .313249 38 1 4.484 29 . 2         .
    1932 2012 "GBR"  .7153365    .20785303   .231822  10.21563 .016430637  .3361511 38 1 2.822 29 . 2         .
    1932 2013 "GBR"  .7420111    .21375693         . 10.199175 .017335664  .3540791 38 1 2.555 29 . 2         .
    1932 2014 "GBR"  .7778118    .19100393         . 10.172255 .017350098  .3489892 38 1  1.46 29 . 2         .
    1932 2015 "GBR"    .84033    .15656036 .18381722  10.35822  .01275583  .3114073 38 1   .05 29 . 2         .
    1932 2016 "GBR"  .7886506    .13338195 .17974505 10.590943 .012420487  .3107384 38 1  .642 29 . 2         .
    2338 2000 "GBR"  .8357384    .05002405    .46152  8.332789 .034872536  .3540164 38 1  .785 29 . 2  .7364442
    2338 2001 "GBR"  .7303801     .0448455   .485644  8.204398  .06316653 .34645885 38 1 1.236 29 . 2  .9159525
    2338 2002 "GBR"  .7332059    .07728017  .4587657  8.205765  .05898416  .3585472 38 1 1.256 29 . 2  1.194582
    2338 2003 "GBR"  .7640643    .07749713 .56285876  8.155936 .069173366  .2749713 38 1 1.363 29 . 2 1.0934291
    2338 2004 "GBR"  .7687555     .0912033 .59076196  8.131236 .074433655   .282436 38 1 1.345 29 . 2 1.1752523
    2338 2005 "GBR"  .7568089     .1021933 .50060254  8.330623  .04145577 .22824778 38 1  2.05 29 . 2 1.1860054
    2338 2006 "GBR"  .7042387     .1108217  .5010656  8.348301  .04286053   .249112 38 1 2.334 29 . 2 1.0978212
    2338 2007 "GBR"  .6446986    .07055631  .4215933  8.548498  .03062609  .2169025 38 1 2.321 29 . 2  1.365892
    2338 2008 "GBR"  .6976938    .05682134  .4529036  8.881558   .0308419  .2245068 38 1 3.613 29 . 2 2.9817605
    2338 2009 "GBR"  .6181549    .05081401  .5104424  8.712924  .04472949  .2049005 38 1 2.166 29 . 2         .
    2338 2010 "GBR"  .6167793    .07779792  .4936542   8.71062  .03774518 .25218394 38 1 3.286 29 . 2         .
    2338 2011 "GBR"  .6213259     .0834422  .5150229  8.719971 .035271063 .26094055 38 1 4.484 29 . 2         .
    2338 2012 "GBR"  .6405783    .07527896  .4358007  8.758255 .027974226  .3715229 38 1 2.822 29 . 2         .
    2338 2013 "GBR"  .6363106    .07919829   .490757  8.544614 .028215606  .3654408 38 1 2.555 29 . 2         .
    2338 2014 "GBR"  .6917375    .08851101  .5705254  8.430982  .03095705  .2882058 38 1  1.46 29 . 2         .
    2338 2015 "GBR"  .6979188    .07706574  .5938595  8.487352 .031939007 .27076036 38 1   .05 29 . 2         .
    2338 2016 "GBR"         .            .         .         .          .         . 38 1  .642 29 . 2         .
    2410 2000 "GBR"  .4858828    .12335867  .9865845 11.877138  .05175145 .27872416 38 1  .785 29 . 2  .7364442
    2410 2001 "GBR"   .468723    .10578217 1.0488602 11.857635  .06198728 .25579846 38 1 1.236 29 . 2  .9159525
    2410 2002 "GBR"  .5597989    .05834407 1.0630761 11.977446 .065363705 .28321132 38 1 1.256 29 . 2  1.194582
    2410 2003 "GBR"  .5660183    .08435451  .9899083 12.087132  .06160881  .3067206 38 1 1.363 29 . 2 1.0934291
    2410 2004 "GBR" .59185904    .10070746  .9849823 12.160594  .06584235  .3342508 38 1 1.345 29 . 2 1.1752523
    2410 2005 "GBR"  .6111911    .14152257  .8376137  12.24006  .04238959   .363871 38 1  2.05 29 . 2 1.1860054
    2410 2006 "GBR"  .6072398    .12815659  .8409153  12.29042  .04194834  .3462254 38 1 2.334 29 . 2 1.0978212
    2410 2007 "GBR"  .5990613     .1169835  .8687499  12.37191  .04481184  .3397296 38 1 2.321 29 . 2  1.365892
    2410 2008 "GBR"  .5964344    .13744862  .9512395 12.338144  .04812958 .29085428 38 1 3.613 29 . 2 2.9817605
    2410 2009 "GBR" .56725913    .09324993  .9800397  12.37145  .05130357 .28670412 38 1 2.166 29 . 2         .
    2410 2010 "GBR"  .6477988    .10034452  .8603441  12.51452  .04100462  .3557346 38 1 3.286 29 . 2         .
    2410 2011 "GBR"  .6161914    .09424434  .8257025  12.58816  .03799459  .3329739 38 1 4.484 29 . 2         .
    2410 2012 "GBR"   .601523    .06122062  .8030001  12.61218  .04157659  .3696988 38 1 2.822 29 . 2         .
    2410 2013 "GBR" .57340115    .05568713  .8796035 12.630327   .0441951  .3167915 38 1 2.555 29 . 2         .
    2410 2014 "GBR"  .6037987   .014699003  .9908408 12.557803  .05333357  .3069309 38 1  1.46 29 . 2         .
    2410 2015 "GBR"  .6242362   .005511167 1.1179038 12.475458  .05812506  .2696462 38 1   .05 29 . 2         .
    2410 2016 "GBR"  .6322176   .012228653 1.0970963  12.48111   .0550859 .25753468 38 1  .642 29 . 2         .
    2597 2000 "GBR"  .5574539    .10780163  .3415482  8.796944  .02509828  .2856063 38 1  .785 29 . 2  .7364442
    2597 2001 "GBR" .57131314     .1119192  .3287542  8.912608  .02801347 .26127946 38 1 1.236 29 . 2  .9159525
    2597 2002 "GBR" .58230585    .11008008   .340028  8.970432  .02923605  .2608364 38 1 1.256 29 . 2  1.194582
    2597 2003 "GBR"  .6932757    .10105667  .2939481  9.250523 .032853026 .23121998 38 1 1.363 29 . 2 1.0934291
    2597 2004 "GBR"  .6828266    .10024651   .314092  9.183585 .036359902  .2365448 38 1 1.345 29 . 2 1.1752523
    2597 2005 "GBR"  .7238901    .09552402 .27128822  9.304923  .01937773 .21706696 38 1  2.05 29 . 2 1.1860054
    2597 2006 "GBR"  .6388156    .10231604   .306264  9.233373 .024821656 .23414443 38 1 2.334 29 . 2 1.0978212
    2597 2007 "GBR"  .6319457    .09163874  .3168989  9.335916 .024431117 .22931734 38 1 2.321 29 . 2  1.365892
    2597 2008 "GBR"  .6026981    .06531759  .3743676  9.093245  .02743114 .29623383 38 1 3.613 29 . 2 2.9817605
    2597 2009 "GBR"  .5667364     .0925083  .4381843  9.003193   .0263255 .26140976 38 1 2.166 29 . 2         .
    2597 2010 "GBR"         .            .         .         .          .         . 38 1 3.286 29 . 2         .
    2597 2011 "GBR"         .            .         .         .          .         . 38 1 4.484 29 . 2         .
    2597 2012 "GBR"         .            .         .         .          .         . 38 1 2.822 29 . 2         .
    2597 2013 "GBR"         .            .         .         .          .         . 38 1 2.555 29 . 2         .
    2597 2014 "GBR"         .            .         .         .          .         . 38 1  1.46 29 . 2         .
    end
    label values locnum ficnumer
    label def ficnumer 38 "GBR", modify
    label def ficnumer 52 "ISR", modify
    label def ficnumer 79 "NLD", modify


  • #2
    Try the xtcd2 command (on ssc).

    EDIT: On some own testing, I'm not sure if the results of the command can be trusted in panels where certain units do not share observations.
    Last edited by Jesse Wursten; 28 Jul 2017, 06:54.

    Comment


    • #3
      Thank Jesse for your quick reply,

      After running the RE model given below I tried xtcd command first.

      Code:
      xtreg LTAT profitability tangibility size nondebt currentliq locnum developing corruption inflation correctedadris2005 finsistem creditorrights, re
      
      . predict u1, u
      (229,246 missing values generated)
      
      . xtcd u1
      Once again Stata issued the same error message:

      Code:
      
      Error: The panel is highly unbalanced.
      Not enough common observations across panel    to    perform    Pesaran's    test.
      insufficient observations
      r(2001);
      Then, I tried xtcd2 command and obtained test results as can be seen below

      Code:
      
      . xtcd2 u1
      Pesaran (2015) test for weak cross sectional dependence
      Unbalanced panel detected, test adjusted.
      H0: errors are weakly cross sectional dependent. 
      CD = 44.941   
      p-value = 0.000
      I hope I can rely on these test result and conclude that there is no cross sectional dependency.

      Comment


      • #4
        What happens when you use the xtcdf command I've attached? I did some testing on the xtcd2 command and it's giving me very strange results.
        Attached Files

        Comment


        • #5
          I used xtcdf command and Stata gave the following output

          Code:
          . xtcdf u1
          
          xtcd test on variables u1
          Panelvar: gvkey
          Timevar: date
          ------------------------------------------------------------------------------+
              Variable    |  CD-test   p-value   average joint T | mean ρ   mean abs(ρ) |
          ----------------+--------------------------------------+----------------------|
                 u1       +  0          1.000          7.24      +  0.00       0.00     | 1.388e+08 combinations of panel units ignored (insufficient
          > joint observations).
          ------------------------------------------------------------------------------+
           Notes: Under the null hypothesis of cross-section independence, CD ~ N(0,1)
                  P-values close to zero indicate data are correlated across panel groups.
          Cross sectional independence hypothesis is rejected.In that case I should use the second generation panel unit root tests.
          Last edited by Rümeysa Bilgin; 28 Jul 2017, 13:47.

          Comment


          • #6
            There's something weird with your data though - 1.4*10^8 combinations were skipped and a CD-value of 0 is very bizarre...

            Comment


            • #7
              I agree with you. Also, I am suspicious about a p-value of 1.000. Probably there are too many missing values to obtain a correct test result. I considered about filling missing observations with cross sectional means and test it once more. But I am not sure. Even if I conclude that there is cross sectional dependency in my data set (which seems a true conclusion because of the nature of the data set), I cannot find any unit root test to handle a data set with so many missing observations.

              Comment


              • #8
                Hi Rümeysa,
                I am the author of the xtcd2 command. First of all xtcd2 assumes that the mean of the error term within each cross section is zero (E(ui,t)= 0, for all i). This follows closely Pesaran (2015, Econometric Reviews; p. 1092). However the xtcd command and (I think, please correct me if I am wrong) xtcdf do not rely on this assumption. Therefore, if E(ui,t) != 0, xtcd2 produces different results than the other two commands.

                Looking at the output and comparing the results from xtcd2 and xtcdf there must be something going on as the results are very different. My thought is that the problem might indeed lie in the unbalanced panel and that there are not enough common observations across units. In this case the expected value of the error term within a cross section might be larger than zero and thus xtcd and xtcdf produce a smaller CD test statistic than xtcd2 (as it misses E(ui,t)E(uj,t) in the calculation of the pairwise correlation).
                I noted that the time dimension is much smaller than the cross sectional dimension. While the CD test does not require a relative speed with which N and T increase, both have to go to infinity. Given that your time dimension is small and the panel is unbalanced, the pairwise correlations will be much more vulnerable to outliers if observations (or estimated errors) are dropped - what is definitely the case! Thus it might be interesting to check the averages of the error terms for each cross section.
                Last edited by JanDitzen; 31 Jul 2017, 08:40.

                Comment


                • #9
                  Hi Jan,
                  Thank you for your help. The residual I obtained from xtreg have so many missing values. You can see some descriptives of crossectional means of error terms (meanu1) below. Some of the averages are greater than zero while some are smaller.

                  Code:
                  . misstable summarize meanu1
                  
                  Obs<.
                  
                  Unique
                  Variable Obs=. Obs>. Obs<. values Min Max
                  
                  meanu1 299,983 9,470 >500 -.5319172 .535708
                  
                  
                  . summarize meanu1
                  
                  Variable Obs Mean Std. Dev. Min Max
                  
                  meanu1 9,470 6.44e-10 .1737716 -.5319172 .535708


                  As I mentioned before, I will use mixed command to make the parameter estimation. As far as I know mixed will handle missing values better than xtreg. So this time I predicted the residual after mixed command and applied xtcdf and xtcd2 commands. You can see the results below. Frankly I do not know how to conclude. Results of xtcd2 are same with the previous case, no crossectional dependency. But xtcdf gives the reverse of the previous result and indicates cross sectional dependence.



                  Code:
                  .  xtcdf u2
                  
                  xtcd test on variables u2
                  Panelvar: gvkey
                  Timevar: datum
                  
                  Variable      CD-test   p-value   average joint T  mean ρ   mean abs(ρ)
                  
                  u2       +  81.816     0.000          7.24      +  0.00       0.08      1.390e    08    combinations    of    panel    units    ignored    (insufficient
                  > joint observations).
                  
                  Notes: Under the null hypothesis of cross-section independence, CD ~ N(0,1)
                  P-values close to zero indicate data are correlated across panel groups.
                  Code:
                  .  xtcd2 u2
                  Pesaran (2015) test for weak cross sectional dependence
                  Unbalanced panel detected, test adjusted.
                  H0: errors are weakly cross sectional dependent.
                  CD = 57.849  
                  p-value = 0.000

                  Comment


                  • #10
                    I think the main problem might be the small sample size. If you look at the summary statistics of error terms (meanu1), you have 9470 from almost 300000 observations. That's about 3%!

                    The variable u2 is the one from the mixed command? I am afraid, I am not experienced with this command, but how many observations does your error term have?

                    Comment


                    • #11



                      u1 is the error term from the xtreg command. u2 is the error term from the mixed command. meanu1 is the cross sectional averages of u1 just as you suggested:


                      Originally posted by JanDitzen View Post
                      Thus it might be interesting to check the averages of the error terms for each cross section.
                      Thus, I did just look at the meanu1 to see whether E(ui,t)= 0, for all i assumption is satisfied or not. My real error terms using which I tested cross sectional dependency are u1 and u2.


                      For the xtreg command error term (u1) has 80171 non-missing observations.

                      For the mixed command error term (u2) has 79974 non-missing observations.

                      Code:
                      . summarize u2
                      
                          Variable |        Obs        Mean    Std. Dev.       Min        Max
                      -------------+---------------------------------------------------------
                                u2 |     79,974    1.10e-11    .1045495   -1.15157    .774568
                      
                      .
                      
                      
                      
                      misstable summarize u2
                                                                                     Obs<.
                                                                      +------------------------------
                                     |                                | Unique
                            Variable |     Obs=.     Obs>.     Obs<.  | values        Min         Max
                        -------------+--------------------------------+------------------------------
                                  u2 |   229,443              79,974  |   >500   -1.15157     .774568
                        -----------------------------------------------------------------------------
                      
                      
                       
                      
                      
                      
                      misstable summarize u1
                                                                                     Obs<.
                                                                      +------------------------------
                                     |                                | Unique
                            Variable |     Obs=.     Obs>.     Obs<.  | values        Min         Max
                        -------------+--------------------------------+------------------------------
                                  u1 |   229,246              80,171  |   >500  -.5319172     .535708
                        -----------------------------------------------------------------------------








                      Comment


                      • #12
                        Jesse Wursten . I have an unbalanced panel data N=119 and T=21. My dependent variable lies between zero and one, so I have applied panel fractional regression models .How to check cross sectional dependence in non-linear panel models?

                        Comment

                        Working...
                        X