Announcement

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

  • Error: "Panel needs to be strongly balanced" in xtgrangert Granger Causality Test

    Hello Statalist experts,

    I am running a Granger causality test using the xtgrangert command in Stata by Xiao et al. (2023). My panel dataset includes 182 countries over 32 years and is strongly balanced. Despite this, I received the following error when running the test:
    Panel needs to be strongly balanced
    .

    Here is the code I am using:
    Code:
     xtgrangert E U  Y , maxlags(4) het
    I have checked my data, and it is strongly balanced

    xtset id year, yearly

    Panel variable: id (strongly balanced)
    Time variable: year, 1991 to 2022
    Delta: 1 year
    I am unsure where this error is coming from. Could anyone provide insights or suggest potential solutions to resolve this issue? Please see my dataex

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long id int year float(E  U  Y  P)
    1 1991  -.0004449008  -.002845394   -.8571951           .
    1 1992  -.0007115395  -.003226074   -1.283857           .
    1 1993  -.0003319063 -.0002082535  -1.7019466           .
    1 1994  -.0001479755   .002643151    3.228398           .
    1 1995 1.0486774e-06  .0016637385   1.6829534           .
    1 1996  -.0003171743   -.00075288    2.997763           .
    1 1997   -.000640449 -.0023456034    -2.06918           .
    1 1998   -.000875818  .0015517353    1.966161           .
    1 1999  -.0008457183   .004605954  -3.7369406           .
    1 2000  -.0004506126   .006732562   -.1835596           .
    1 2001  .00049807865   .009294225   -4.213449   -4.087791
    1 2002 -.00009823818   .009342433    2.504549   1.2237757
    1 2003   -.000625715     .0096963   1.0661623   1.5416573
    1 2004   -.000254872   .010971271   -.9094066   1.2571694
    1 2005  .00009526682    .01268352    .8364386   1.0565739
    1 2006   .0008514766     .0138609  -.07830995    .5583869
    1 2007    .001460633    .01164871      .72833    1.683277
    1 2008   .0031077515   .009823537  -.59586203  -.59275806
    1 2009   .0016684416  .0025182765   1.0597724   -3.520938
    1 2010   .0003410176  -.008210819    .6985134   .11358526
    1 2011  -.0001319124   -.02384149  -2.1530068   1.6473176
    1 2012  -.0009199297   -.04664697    .8113115    .9253277
    1 2013   -.000797574  -.074023925    .1885575    .6185573
    1 2014   .0005881425    -.1100479  -.25669006  -1.0273088
    1 2015   .0011315047  -.023128396   -.5080915   .11555885
    1 2016   .0017445403    .04378318   .24774873   -3.034435
    1 2017   .0017749035    .09591997    .8308941   .04679916
    1 2018   .0015970765     .0471509    .6498235  -.19643974
    1 2019  -.0005140785 -.0028551156   2.2945228    .7605554
    1 2020     .00718147  -.013095497   -.7274225    .6655851
    1 2021   -.008288895   -.04750531  -2.1927133   -.3754443
    1 2022   -.005644043    .06484327  -.32426885    .6209888
    2 1991    -.01471916    -.5634318   -2.807951  -1.0141217
    2 1992   -.006567038     .4906767  -2.1275244   1.2052957
    2 1993  -.0010834475     .3111394    2.849116    .9365547
    2 1994   .0019773745    .11836658   2.1395082   .03930292
    2 1995    .001494444    -.2329195   2.1388812   -.8839776
    2 1996    .008589347   -.27673912   1.3858128    .7953224
    2 1997    .012003633    -.0825581     -4.9021  -.10390424
    2 1998    .014438195    .09289832    .8005733   -.3198527
    2 1999    .012051847    .13824913    .9730305  -1.1812496
    2 2000    .009161234     .0584529   .21262456  -.02725871
    2 2001   .0042566485    .04998493   .29667488   -.2403356
    2 2002  .00017803094   .032374274   -.3425387  -.14523777
    2 2003    -.00537797   .003017626  -.15500453    .3115092
    2 2004   -.010902268   -.01360395  -.13220198  -.07853641
    2 2005   -.008263561   -.01035066  -.07773931   .05201499
    2 2006    -.02019592 -.0086250845   .06328843  -.13840997
    2 2007   -.033814956   .033832517    .1740913    .4920941
    2 2008    .005728021   -.14891781    .5130967    .5268165
    2 2009    -.02254525   -.09013978  -.14566992   .13137193
    2 2010    -.04736904   -.05219492   .08253043    .8456615
    2 2011    .029645743   -.09128856  -.14787443    .3453523
    2 2012      .0651124   -.09653462  -.55189025    -.191644
    2 2013    .012445626    .07660814   -.7276924   -.7091404
    2 2014   -.007884014    .21211667   -.2081753    .3044314
    2 2015    .015663914    .17604285  .035474837  -.34273875
    2 2016    .022087824    .08682317    .4427852  -1.4883704
    2 2017    .007744151  -.012120361     .599416   .20940426
    2 2018   -.008704802   -.08471277     .673328   .11011175
    2 2019   -.017602472   -.12521012  .068179905   -.1685949
    2 2020   -.007666497   .013688276   -3.330514   -.7553312
    2 2021   -.006126672   .018949693    1.426118    .3370706
    2 2022  -.0037553606   -.02387402    .7823462   1.1463896
    3 1991    -.02250441    -.1986511  -.57451445    .4681585
    3 1992   -.013043691   -.05888835    1.460112  -.17652376
    3 1993   -.005985303  -.012359177  -1.7038572   -.4039272
    3 1994  -.0006380692     .0215815   -1.354393    .5931182
    3 1995     .00438037    .14461954    1.175415    .8092754
    3 1996    .008632946    .02236528    .9517882    .8579949
    3 1997    .013464594   -.07922859   -.4770637  -.17210717
    3 1998    .022530984  -.007358327    .6811649    -4.52323
    3 1999     .02366567    .08421954    .0483259    .5028408
    3 2000     .02137887    .17168105  .073515326   1.2848614
    3 2001    .031828832    .14630294  -.25424716   .27557904
    3 2002    .008921119    .16971605   .25012603  -1.3649898
    3 2003   -.017013395    .17037603    .4034641    .4084841
    3 2004   -.023271365    -.0278829   .04549503    .6740708
    3 2005    -.03096134   -.07278326    .2538211    .7964533
    3 2006    -.02918606    -.1940093   -.2992765    .7394007
    3 2007    -.02135038   .011861585   -.1783198    .4362577
    3 2008   -.011106118   -.10485894  -.32067806   1.3267367
    3 2009    .007998014   -.14744882   -.8946162  -4.6276884
    3 2010    .018777875   -.11637031    .4146683   1.6460755
    3 2011    .029895935   -.08097234  .016123738   1.8777405
    3 2012    .007908606   .035880033  -.13180977   1.2947183
    3 2013   -.015050652   -.06675972  .012024666  -.51726985
    3 2014   -.011668178  -.032596793   .52909756 -.020479495
    3 2015   -.002454871    .04607386    .3890363  -3.4139044
    3 2016   -.003314571   -.06946745    .6934673  -.31630525
    3 2017    -.00826454    .06407943  -.05760181   1.1594163
    3 2018   -.011204492    .04476469 .0080765905   1.2853923
    3 2019   -.006258583   .022311054   -.2119689   -.5695478
    3 2020    .015918491    .12157857   -3.249188  -3.8018425
    3 2021     .01173083    .05718406   1.1579076     1.68167
    3 2022     .00624287   -.06495981    1.143905    1.789571
    4 1991    -.00558755  -.015981663   1.7869414  -1.8270673
    4 1992  -.0040850844 -.0038850694  -2.0296562    -.358565
    4 1993 -.00045870125    .02598308    -3.93014    .2835472
    4 1994   -.000682764    .03117815    .5332092   1.1735982
    end
    format %ty year
    label values id id
    label def id 1 "Afghanistan", modify
    label def id 2 "Albania", modify
    label def id 3 "Algeria", modify
    label def id 4 "Angola", modify
    Thank you for your assistance in advance.

  • #2
    looks like missing values for P

    Comment


    • #3
      Thank you, George, but I am not using P in the tests.

      Comment


      • #4
        Do:

        Code:
        qui regress E U Y
        list if !e(sample), sepby(id)

        Comment


        • #5
          Thank you very much, Andrew, for this code.

          Running it, I found out my sample now starts from 1976 to 2022 but with missing gaps for all variables from 1976 to 1990. I can't figure out at what point I had such a sample but I probably made some errors when preparing the dataset in Excel. Now, I would like to drop 1976 to 1990 from the sample so as to proceed with the analysis.

          Can you please help me with a code for that. See my new sample dataex:

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input double id float(year E U Y)
          1 1976             .            .          .
          1 1977             .            .          .
          1 1978             .            .          .
          1 1979             .            .          .
          1 1980             .            .          .
          1 1981             .            .          .
          1 1982             .            .          .
          1 1983             .            .          .
          1 1984             .            .          .
          1 1985             .            .          .
          1 1986             .            .          .
          1 1987             .            .          .
          1 1988             .            .          .
          1 1989             .            .          .
          1 1990             .            .          .
          1 1991  -.0004449008  -.002845394  -.8571951
          1 1992  -.0007115395  -.003226074  -1.283857
          1 1993  -.0003319063 -.0002082535 -1.7019466
          1 1994  -.0001479755   .002643151   3.228398
          1 1995 1.0486774e-06  .0016637385  1.6829534
          1 1996  -.0003171743   -.00075288   2.997763
          1 1997   -.000640449 -.0023456034   -2.06918
          1 1998   -.000875818  .0015517353   1.966161
          1 1999  -.0008457183   .004605954 -3.7369406
          1 2000  -.0004506126   .006732562  -.1835596
          1 2001  .00049807865   .009294225  -4.213449
          1 2002 -.00009823818   .009342433   2.504549
          1 2003   -.000625715     .0096963  1.0661623
          1 2004   -.000254872   .010971271  -.9094066
          1 2005  .00009526682    .01268352   .8364386
          1 2006   .0008514766     .0138609 -.07830995
          1 2007    .001460633    .01164871     .72833
          1 2008   .0031077515   .009823537 -.59586203
          1 2009   .0016684416  .0025182765  1.0597724
          1 2010   .0003410176  -.008210819   .6985134
          1 2011  -.0001319124   -.02384149 -2.1530068
          1 2012  -.0009199297   -.04664697   .8113115
          1 2013   -.000797574  -.074023925   .1885575
          1 2014   .0005881425    -.1100479 -.25669006
          1 2015   .0011315047  -.023128396  -.5080915
          1 2016   .0017445403    .04378318  .24774873
          1 2017   .0017749035    .09591997   .8308941
          1 2018   .0015970765     .0471509   .6498235
          1 2019  -.0005140785 -.0028551156  2.2945228
          1 2020     .00718147  -.013095497  -.7274225
          1 2021   -.008288895   -.04750531 -2.1927133
          1 2022   -.005644043    .06484327 -.32426885
          2 1976             .            .          .
          2 1977             .            .          .
          2 1978             .            .          .
          2 1979             .            .          .
          2 1980             .            .          .
          2 1981             .            .          .
          2 1982             .            .          .
          2 1983             .            .          .
          2 1984             .            .          .
          2 1985             .            .          .
          2 1986             .            .          .
          2 1987             .            .          .
          2 1988             .            .          .
          2 1989             .            .          .
          2 1990             .            .          .
          2 1991    -.01471916    -.5634318  -2.807951
          2 1992   -.006567038     .4906767 -2.1275244
          2 1993  -.0010834475     .3111394   2.849116
          2 1994   .0019773745    .11836658  2.1395082
          2 1995    .001494444    -.2329195  2.1388812
          2 1996    .008589347   -.27673912  1.3858128
          2 1997    .012003633    -.0825581    -4.9021
          2 1998    .014438195    .09289832   .8005733
          2 1999    .012051847    .13824913   .9730305
          2 2000    .009161234     .0584529  .21262456
          2 2001   .0042566485    .04998493  .29667488
          2 2002  .00017803094   .032374274  -.3425387
          2 2003    -.00537797   .003017626 -.15500453
          2 2004   -.010902268   -.01360395 -.13220198
          2 2005   -.008263561   -.01035066 -.07773931
          2 2006    -.02019592 -.0086250845  .06328843
          2 2007   -.033814956   .033832517   .1740913
          2 2008    .005728021   -.14891781   .5130967
          2 2009    -.02254525   -.09013978 -.14566992
          2 2010    -.04736904   -.05219492  .08253043
          2 2011    .029645743   -.09128856 -.14787443
          2 2012      .0651124   -.09653462 -.55189025
          2 2013    .012445626    .07660814  -.7276924
          2 2014   -.007884014    .21211667  -.2081753
          2 2015    .015663914    .17604285 .035474837
          2 2016    .022087824    .08682317   .4427852
          2 2017    .007744151  -.012120361    .599416
          2 2018   -.008704802   -.08471277    .673328
          2 2019   -.017602472   -.12521012 .068179905
          2 2020   -.007666497   .013688276  -3.330514
          2 2021   -.006126672   .018949693   1.426118
          2 2022  -.0037553606   -.02387402   .7823462
          3 1976             .            .          .
          3 1977             .            .          .
          3 1978             .            .          .
          3 1979             .            .          .
          3 1980             .            .          .
          3 1981             .            .          .
          end
          format %ty year
          label values id id
          label def id 1 "Afghanistan", modify
          label def id 2 "Albania", modify
          label def id 3 "Algeria", modify

          Comment


          • #6
            Code:
            keep if inrange(year, 1991, 2022)

            Comment


            • #7
              Thank you, Andrew. The code now works for me.
              Code:
              xtgrangert E U Y

              Comment


              • #8
                Dear Andrew, just a follow-up question related to data management. How can I identify the ID (panel) with less observations in my data? The period covers 1991 to 2022.

                I did some modifications to my dataset in Excel and when I run the following code:
                xtdescribe
                , I get the following outcomes:
                Distribution of T_i: min 5% 25% 50% 75% 95% max
                29 32 32 32 32 32 32
                .

                Now, Since I am working with a very large sample, I am not exactly sure which country has fewer years making the panel unbalanced, which I will like to find out and correct.

                Comment


                • #9
                  You can count complete observations tagged by e(sample) in #4.

                  Code:
                  qui regress E U Y
                  gen complete= e(sample)
                  bys id (year): egen count= total(complete)
                  egen tag= tag(id)
                  list id count if count<32 & tag, sep(0)

                  Comment


                  • #10
                    Thank you, Andrew. It worked well.

                    Comment

                    Working...
                    X