Announcement

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

  • Hot to make Autocorrelation Test in STATA for Panel Data

    Dear all,

    I have been strugling with autocorrealtion test for my STATA project.

    My study contains 20 countries and 21 years.

    I have tried variaties of commands I have found on internet such as xtserial or sort id and t however I am not able to complete the test correctly.

    Could you please advice how can I implement and autocorrelation test to my project?

    Thanks in advance,
    Sikinti Yok

  • #2
    You'll need to provide sufficient data (search dataex) to reproduce the result (or lack thereof).

    Comment


    • #3
      Sikinti:
      as George wisely noticed, you provide interested listers with too scant details.
      You do not share any Stata code and the specification of your panel data regression (-fe- or -re-) is also obscure.
      All that said, shamelessly elaborating on a worked out example reported in
      https://www.stata.com/bookstore/microeconometrics-stata, page 252,
      what follows may be of some help:
      Code:
      use "https://www.stata-press.com/data/r17/nlswork.dta"
      quietly xtreg ln_wage c.age##c.age
      predict epsilon, e
      . forvalues i=1/5 {
        2. forvalues j=1(1)5 {
        3. quietly corr epsilon L`j'.epsilon if idcode==`i'
        4. gen delta`j'=r(rho)
        5. sum delta`j', meanonly
        6. bysort idcode: replace epsilon_corr=r(mean) if idcode==`i' & _n==`j'
        7. drop delta`j'
        8.  }
        9. sum epsilon_corr if idcode==`i'
       10.  }
      
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      epsilon_corr |          5    .5729781    .1993669   .3150713   .8134871
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      epsilon_corr |          5    -.388444    .5590177  -.9798838    .275066
      
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      epsilon_corr |          5    .5206494    .1727996   .3151894   .7879882
      
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      epsilon_corr |          5    .7507667    .4060343   .0323193          1
      
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
      epsilon_corr |          5   -.0774237    .4821721  -.5287769   .6038273
      
      .
      The average correlation of -epsilon- residuals seems to deserve attention for -idcode- #4,1 and 3.
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment

      Working...
      X