Announcement

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

  • Autocorrelation saving results

    Hi all,

    I'm using user-written xtserial and I'm struggling with saving the information.

    Here is a sample of my data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long Fullid float(time logthpp logprevcpn)
    1 -204  -.07918125         .
    1 -202  -.06382149  2.968016
    1 -200  -.05305674 2.9726655
    1 -199  -.04175473  3.001734
    1 -198  -.04175473 3.0216026
    1 -197   .04270675  3.043755
    1 -196   .09633057  3.062958
    1 -195    .0934217  3.075912
    1 -194  -.03229605 3.0982976
    1 -193   .09108047 3.1169395
    1 -192  -.05142405 3.1332195
    1 -191 -.024568195 3.1504495
    2 -204    .3460734         .
    2 -203    .3656217  1.544068
    2 -202   .59423465  1.832509
    2 -201   .59423465  2.045323
    2 -200    .3767073 2.2479732
    2 -199   .20431383 2.3961995
    2 -198   .20431383 2.5037906
    2 -197    .1045359  2.591065
    2 -196    .1033149  2.668386
    2 -195   .19728057  2.731589
    2 -194   .10648232 2.7916906
    2 -193    .1775365  2.841985
    2 -192   .11750802  2.886491
    2 -191    .1645653  2.926857
    2 -190    .1645653  2.951823
    3 -213    .6373078  .7781513
    3 -212     .456642 1.2787536
    3 -211    .3004374 1.6812413
    3 -210      .20527 1.9822712
    3 -209   .10792907 2.1731863
    3 -208   .10359641 2.4785664
    3 -207   .06773569 2.6294096
    3 -206   .01665353  2.748188
    3 -205 -.001846379  2.848805
    3 -204   .11292981  2.923244
    3 -203   .08005774  3.041393
    3 -202  -.03908259  3.079181
    3 -201  -.03908259  3.113943
    3 -200  -.03908259  3.146128
    3 -199  -.03908259  3.176091
    3 -198  -.03908259   3.20412
    3 -197  -.03908259  3.230449
    4 -220    .6003547 1.3424227
    4 -219   .57465684   1.50515
    4 -218      .55444 1.6434526
    4 -217    .5614237  1.763428
    4 -216   .52935606  1.863323
    4 -215    .5112851  2.089905
    4 -214    .4620432  2.307496
    4 -213    .3269823  2.463893
    4 -212    .2680974  2.563481
    4 -211    .2365903  2.656098
    4 -210    .1932711   2.74351
    4 -209   .19376005 2.8247764
    4 -208   .17513096  2.893207
    4 -207    .1680165 2.9561684
    4 -206   .18208003  3.008174
    4 -205   .17273673  3.056142
    6 -204    .4780352         .
    6 -203    .4665558  2.462398
    6 -202    .4579219  2.518514
    6 -201     .433721   2.60206
    6 -200   .41151395 2.6532125
    6 -199    .3767709   2.69897
    6 -198    .3544976  2.778151
    6 -197    .3320456  2.845098
    6 -196    .2885081   2.90309
    6 -195   .26468587 2.9542425
    6 -194    .2358847         3
    6 -193    .2166431  3.079181
    6 -192   .19993736  3.176091
    6 -191   .18814093 3.2552724
    6 -190   .17562827   3.30103
    6 -189   .15704262   3.39794
    6 -188    .1605366  3.477121
    6 -187   .14149216   3.56134
    6 -186   .14696562  3.582745
    6 -185   .14696562 3.5995555
    6 -184   .14696562 3.6167905
    6 -183   .14696562  3.630428
    6 -182   .10241515  3.641573
    6 -181   .10241515 3.6517625
    6 -180   .11431438  3.660771
    6 -179   .11431438  3.668386
    6 -178   .11431438  3.675045
    6 -177   .11431438  3.682416
    6 -176   .10237654  3.689131
    6 -175   .09010122  3.696007
    7 -233    .9186395         .
    7 -232    .8618895         0
    7 -231    .7921265    .30103
    7 -230    .8579027  .4771213
    7 -229    .7215655    .69897
    7 -228    .7762895  .9542425
    7 -227    .7230359 1.0791812
    7 -226    .7003575 1.3802112
    7 -225    .6690378  1.462398
    7 -224   .56469893  1.544068
    end
    format %tm time
    label values Fullid Fullid
    label def Fullid 1 "Aeronca-Middletown-L-3", modify
    label def Fullid 2 "Aeronca-Middletown-PT-19-23", modify
    label def Fullid 3 "Beech-Witchita-AT-10", modify
    label def Fullid 4 "Beech-Witchita-AT-7-11_UC-45", modify
    label def Fullid 6 "Beech-Witchita-UC-45_Model 18", modify
    label def Fullid 7 "Bell-Buffalo-P-39", modify
    My regression is:
    Code:
     regress logthpp logprevcpn 
    outreg2 using regression_results, replace excel
    I wanted to get the autocorrelation results saved in the above excel doc, so I tried:
    Code:
     regress logthpp logprevcpn 
    outreg2 using regression_results, replace excel
    xtserial logthpp logprevcpn, output 
    outreg2 using regression_results, append excel
    This seems to work, but the results that appear in Stata are different from what appears in my regression_results. My Stata results:

    Linear regression Number of obs = 1,961
    F(1, 76) = 149.52
    Prob > F = 0.0000
    R-squared = 0.0752
    Root MSE = .09181

    (Std. Err. adjusted for 77 clusters in Fullid)
    ------------------------------------------------------------------------------
    | Robust
    D.logthpp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    logprevcpn |
    D1. | -.2014026 .016471 -12.23 0.000 -.2342075 -.1685977
    ------------------------------------------------------------------------------

    Wooldridge test for autocorrelation in panel data
    H0: no first-order autocorrelation
    F( 1, 76) = 47.863
    Prob > F = 0.0000

    My excel results:
    Coefficient: -.1300**
    Observations: 1876
    R-squared 0.017

    Does anyone have any idea why the Stata-results would differ from the saved results in excel?

    Also, I'm confused as to what F(1, 76)= 47.863 indicates. I thought that (1, 76) should represent my N and T but I've got 77 companies represented (N) and about 70 time periods...so I'm not entirely sure what is happening here.


  • #2
    xtserial is from the Stata Journal, as you are asked to explain. The test statistic seems to be what is useful. Do you need to show results from the first-differenced regression? If so, just use regress to run this regression. I do not think that the author intended this regression to be part of the stored output.

    Code:
    xtset Fullid time
    xtserial logthpp logprevcpn, output 
    regress D.logthpp D1.logprevcpn, nocons cluster(Fullid)
    Res.:

    Code:
    . xtset Fullid time
           panel variable:  Fullid (unbalanced)
            time variable:  time, 1940m8 to 1945m6, but with gaps
                    delta:  1 month
    
    . 
    . xtserial logthpp logprevcpn, output 
    
    Linear regression                               Number of obs     =         89
                                                    F(1, 5)           =      16.94
                                                    Prob > F          =     0.0092
                                                    R-squared         =     0.1832
                                                    Root MSE          =     .06278
    
                                     (Std. Err. adjusted for 6 clusters in Fullid)
    ------------------------------------------------------------------------------
                 |               Robust
       D.logthpp |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
      logprevcpn |
             D1. |  -.2192926   .0532832    -4.12   0.009    -.3562614   -.0823238
    ------------------------------------------------------------------------------
    
    Wooldridge test for autocorrelation in panel data
    H0: no first-order autocorrelation
        F(  1,       5) =      8.105
               Prob > F =      0.0360
    
    . 
    . regress D.logthpp D1.logprevcpn, nocons cluster(Fullid)
    
    Linear regression                               Number of obs     =         89
                                                    F(1, 5)           =      16.94
                                                    Prob > F          =     0.0092
                                                    R-squared         =     0.1832
                                                    Root MSE          =     .06278
    
                                     (Std. Err. adjusted for 6 clusters in Fullid)
    ------------------------------------------------------------------------------
                 |               Robust
       D.logthpp |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
      logprevcpn |
             D1. |  -.2192926   .0532832    -4.12   0.009    -.3562614   -.0823238
    ------------------------------------------------------------------------------

    I'm confused as to what F(1, 76)= 47.863 indicates. I thought that (1, 76) should represent my N and T but I've got 77 companies represented (N) and about 70 time periods...so I'm not entirely sure what is happening here.
    This indicates that the test statistic has an F-distribution under the null hypothesis. The first number is the numerator degrees of freedom (dof) and the second is the denominator dof . In this case, the denominator dof = N-1, hence 77-1=76. I would just save the test results in local macros and output these with outreg2(SSC) as scalars. The results are stored in r().


    Code:
    xtset Fullid time
    xtserial logthpp logprevcpn, output 
    return list

    Comment


    • #3
      Hi Andrew,

      Thanks for your help with this.

      I'm confused about the D estimators here:

      Code:
      Code:
       xtset Fullid time
      xtserial logthpp logprevcpn, output  
      regress D.logthpp D1.logprevcpn, nocons cluster(Fullid)
      I don't think I need a diff-in-diff estimator, I was just running an OLS model on my panel data. Is this a problem? Or am I misunderstanding what D. does? When I ran xtserial on the data and then:
      Code:
      regress logthpp logprevcpn, cluster(Fullid)
      I noticed that the number of observations for the xtserial results was smaller than for the regular regression results. I don't understand why that is.

      Comment


      • #4
        Originally posted by Kate Pryce View Post
        Hi Andrew,
        I'm confused about the D estimators here:
        [/CODE] I noticed that the number of observations for the xtserial results was smaller than for the regular regression results. I don't understand why that is.
        D. is the difference operator. Therefore, what it does is to take the first-difference of a variable, for example,

        \( \Delta\text{logthpp}_{t}= \text{logthpp}_{t} - \text{logthpp}_{t-1}\) or the value of logthpp at time \(t\) minus the value at time \(t-1\), also referred to as the lagged value. Therefore, since xtserial is based on the first-differenced regression, you lose an observation for each unit as a result of differencing. In total, you have 7 firms

        Code:
        . sum Fullid
        
            Variable |        Obs        Mean    Std. Dev.       Min        Max
        -------------+---------------------------------------------------------
              Fullid |        100        4.07    1.996234          1          7
        and 96-7= 89, the number of observations in your first-differenced regression.
        Last edited by Andrew Musau; 13 Nov 2020, 23:09.

        Comment


        • #5
          Andrew, Thank you!

          This makes good sense.

          Comment

          Working...
          X