Announcement

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

  • VAR function not working

    Hello

    I want to perform a Granger-causality test on two variables. But, when I run the VAR function on my two varaibles I get an error message "repeated time values in sample r(451);". Let me point out that one of the varaibles is an index from the principal component analysis which includes many zero values.

    Can someone suggest a solution?

    Thank you

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(pci GDP)
             0   4.400002
             0   .8000006
     -.5745628 -1.2000005
    -.57455605  1.8000023
             0 -2.1000009
     1.7332535  -.8999966
     1.7332516   3.799995
     1.7332542  4.0999985
      1.733341  1.0999999
      1.733264   5.100004
     1.7332528  3.2000015
    -.57455146        3.8
    -.57454926          3
     -.5745495        5.6
     -.5745575        7.2
     -.5745599        4.3
    -.57455844        5.9
    -.57455945        1.7
    -.57455814        3.4
    -.57455796        2.4
    -.57455903        1.6
    -.57456124        3.6
    -.57456315        2.9
     -.5745631        3.4
     -.5745614        2.8
     -.5745629        3.8
    -.57456326        3.7
    -.57456356        3.2
      1.733244  .04162146
     1.7332453  -3.450099
    -.57456213   .9913593
     1.7332442  -5.838281
             0  -23.98342
     1.7332444  1.3393635
    -.57456255         15
     -.5745633   13.54437
    -.57456297   7.274277
     1.7332482  4.6911464
      1.733249  2.1814897
      1.733246   3.054624
     1.7332616  4.2059984
     -.5745624  13.665687
             0    2.98985
             0  10.952862
             0  15.028915
             0  11.547683
             0  14.010018
             0   11.16614
     -.5745637   .8587126
             0    4.85922
             0   3.471981
             0   8.542148
             0    4.95459
             0   4.822626
             0   .9435756
             0  -2.580097
             0 -2.8541605
             0   8.976134
             0  4.2257996
             0   2.957711
             0   5.836172
             0  2.0204005
             0   6.045198
             0   4.324284
             0   5.734688
             0   3.961012
             0   5.341449
             0   5.859992
             0   5.330411
             0    4.64447
             0   3.444045
             0   4.429629
             0  1.7115777
             0   3.947014
             0   5.986516
             0   4.889899
             0   2.329301
             0  2.1101992
             0  2.9627504
             0   4.816478
             0   7.189716
             0   6.351832
             0  2.0958083
             0    3.96486
             0  13.059406
             0   6.772822
             0   7.458709
             0  2.9170704
             0   1.916107
             0   3.627916
             0    7.03041
             0     5.8298
             0   8.325891
             0   .4436635
             0   9.667241
             0  1.9876958
             0  .25057387
             0   6.069531
             0   4.625895
             0   2.705822
    end

  • #2
    The var command (not function) is not for panel data. This may help, but I know about this territory beyond what I say here. m


    SJ-16-3 st0455 . . . . . . Estimation of panel vector autoregression in Stata
    . . . . . . . . . . . . . . . . . . . . . M. R. M. Abrigo and I. Love
    (help pvar, pvarfevd, pvargranger, pvarirf, pvarsoc, pvarstable
    if installed)
    Q3/16 SJ 16(3):778--804
    provides model selection, estimation, and inference of
    homogeneous panel VAR models in a generalized method of
    moments framework

    Comment


    • #3
      Sorry for garbled text. I know no more about this territory beyond what I say here.

      Comment


      • #4
        It's not clear what your time variable is since you didn't include it in your example. It's also not clear if you're using a panel dataset.

        The most I can offer is an example you can follow:

        Code:
        use http://www.stata-press.com/data/r13/lutkepohl2, clear 
        
        tsset
                time variable:  qtr, 1960q1 to 1982q4
                        delta:  1 quarter
        
         var dln_inv dln_inc dln_consump 
        
        Vector autoregression
        
        Sample:  1960q4 - 1982q4                        Number of obs     =         89
        Log likelihood =   742.2131                     AIC               =  -16.20704
        FPE            =   1.84e-11                     HQIC              =  -15.97035
        Det(Sigma_ml)  =   1.15e-11                     SBIC              =  -15.61983
        
        Equation           Parms      RMSE     R-sq      chi2     P>chi2
        ----------------------------------------------------------------
        dln_inv               7     .044295   0.1051   10.45617   0.1067
        dln_inc               7     .011224   0.1514   15.87886   0.0144
        dln_consump           7     .009938   0.2400   28.09971   0.0001
        ----------------------------------------------------------------
        
        ------------------------------------------------------------------------------
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        dln_inv      |
             dln_inv |
                 L1. |  -.2725654   .1093372    -2.49   0.013    -.4868623   -.0582684
                 L2. |  -.1340503   .1089367    -1.23   0.218    -.3475624    .0794617
                     |
             dln_inc |
                 L1. |   .3374819   .4805209     0.70   0.482    -.6043217    1.279286
                 L2. |   .1827302    .466292     0.39   0.695    -.7311852    1.096646
                     |
         dln_consump |
                 L1. |   .6520473   .5450985     1.20   0.232    -.4163261    1.720421
                 L2. |   .5980687   .5434576     1.10   0.271    -.4670886    1.663226
                     |
               _cons |  -.0099191   .0126649    -0.78   0.434    -.0347419    .0149037
        -------------+----------------------------------------------------------------
        dln_inc      |
             dln_inv |
                 L1. |   .0433473   .0277054     1.56   0.118    -.0109542    .0976488
                 L2. |   .0616319   .0276039     2.23   0.026     .0075293    .1157345
                     |
             dln_inc |
                 L1. |  -.1232543    .121761    -1.01   0.311    -.3619015    .1153928
                 L2. |   .0209769   .1181555     0.18   0.859    -.2106036    .2525573
                     |
         dln_consump |
                 L1. |   .3050571   .1381245     2.21   0.027      .034338    .5757762
                 L2. |   .0490208   .1377087     0.36   0.722    -.2208833     .318925
                     |
               _cons |   .0125949   .0032092     3.92   0.000     .0063049    .0188848
        -------------+----------------------------------------------------------------
        dln_consump  |
             dln_inv |
                 L1. |   .0027381     .02453     0.11   0.911    -.0453398     .050816
                 L2. |   .0497402   .0244401     2.04   0.042     .0018384     .097642
                     |
             dln_inc |
                 L1. |   .2893204   .1078057     2.68   0.007     .0780251    .5006157
                 L2. |   .3664341   .1046134     3.50   0.000     .1613955    .5714726
                     |
         dln_consump |
                 L1. |  -.2845172   .1222938    -2.33   0.020    -.5242086   -.0448257
                 L2. |  -.1159776   .1219257    -0.95   0.341    -.3549475    .1229924
                     |
               _cons |   .0123795   .0028414     4.36   0.000     .0068104    .0179485
        ------------------------------------------------------------------------------
        
        vargranger
        
           Granger causality Wald tests
          +------------------------------------------------------------------+
          |          Equation           Excluded |   chi2     df Prob > chi2 |
          |--------------------------------------+---------------------------|
          |           dln_inv            dln_inc |  .55668     2    0.757    |
          |           dln_inv        dln_consump |  1.9443     2    0.378    |
          |           dln_inv                ALL |  7.3184     4    0.120    |
          |--------------------------------------+---------------------------|
          |           dln_inc            dln_inv |  6.2466     2    0.044    |
          |           dln_inc        dln_consump |  5.1029     2    0.078    |
          |           dln_inc                ALL |  13.087     4    0.011    |
          |--------------------------------------+---------------------------|
          |       dln_consump            dln_inv |  4.2446     2    0.120    |
          |       dln_consump            dln_inc |  16.275     2    0.000    |
          |       dln_consump                ALL |  21.717     4    0.000    |
          +------------------------------------------------------------------+

        Comment


        • #5
          I am using annual panel data.
          Thank you for your valuable feedbacks. Indeed, it seems it is not working because I am using panel data.

          Comment


          • #6
            In that case you can install pvar (ssc install pvar) and use pvargranger. See the Stata Journal article:
            https://journals.sagepub.com/doi/pdf...867X1601600314


            Code:
            webuse psidextract , clear 
            
            generate lwks = ln(wks)
            pvar lwks lwage, lags(3)
            
            Panel vector autoregresssion
            
            
            
            GMM Estimation
            
            Final GMM Criterion Q(b) =  1.81e-32
            Initial weight matrix: Identity
            GMM weight matrix:     Robust
                                                               No. of obs      =      1785
                                                               No. of panels   =       595
                                                               Ave. no. of T   =     3.000
            
            
            ------------------------------------------------------------------------------
                         |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
            lwks         |
                    lwks |
                     L1. |   .0715843   .1872692     0.38   0.702    -.2954567    .4386253
                     L2. |  -.1467104   .0968059    -1.52   0.130    -.3364464    .0430256
                     L3. |  -.0469439   .0530438    -0.89   0.376    -.1509079    .0570202
                         |
                   lwage |
                     L1. |  -.0120861   .0249846    -0.48   0.629     -.061055    .0368829
                     L2. |   -.016583   .0128689    -1.29   0.198    -.0418057    .0086397
                     L3. |  -.0270035    .014072    -1.92   0.055    -.0545841    .0005771
            -------------+----------------------------------------------------------------
            lwage        |
                    lwks |
                     L1. |   .3491933   .2671789     1.31   0.191    -.1744677    .8728543
                     L2. |    .121905   .1242265     0.98   0.326    -.1215745    .3653845
                     L3. |   .0680906   .0653433     1.04   0.297      -.05998    .1961611
                         |
                   lwage |
                     L1. |   .5842835   .0769119     7.60   0.000     .4335391     .735028
                     L2. |   .1985492   .0464859     4.27   0.000     .1074384    .2896599
                     L3. |   .1242239   .0369797     3.36   0.001     .0517451    .1967027
            ------------------------------------------------------------------------------
            Instruments : l(1/3).(lwks lwage) 
            
            pvargranger
            
              panel VAR-Granger causality Wald test
                Ho: Excluded variable does not Granger-cause Equation variable
                Ha: Excluded variable Granger-causes Equation variable
            
              +------------------------------------------------------+
              |  Equation \ Excluded |    chi2     df   Prob > chi2  |
              |----------------------+-------------------------------|
              |lwks                  |                               |
              |                lwage |     10.418    3        0.015  |
              |                  ALL |     10.418    3        0.015  |
              |----------------------+-------------------------------|
              |lwage                 |                               |
              |                 lwks |      1.807    3        0.613  |
              |                  ALL |      1.807    3        0.613  |
              +------------------------------------------------------+

            Comment


            • #7
              Thank you for the code. Its really helpful.
              Last edited by Ishto Stanfield; 03 Apr 2020, 20:25.

              Comment


              • #8
                Hi

                I would like a precision on the interpretation of the pvargranger test. Does the sign of the ''chi2" coefficient determine the direction (positive or negative) of the granger-causality?

                Comment


                • #9
                  In general, chi-square is a test statistic that must be positive or zero. It's not a coefficient multiplying a variable.

                  Comment


                  • #10
                    Thank you for this precision. Is there a way to determine the direction of the above Granger-causality test (sign of correlation)?

                    Comment


                    • #11
                      Thank you for this precision. Is there a way to determine the direction of the above Granger-causality test (if the effect on the dependent variable is positive or negative)?

                      I’ve read the article provided by Justin, but there seems to be no clear indication to that.

                      Comment


                      • #12
                        I don't understand the difficulty. Isn't that just obtainable directly from a correlation?

                        Comment

                        Working...
                        X