Announcement

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

  • Autocorrelation (ac and pac)

    I'm using the autocorrelation command ac and the partial autocorrelation command pac. I'm running them on over 1,000 different time series with length T=12. May I ask a couple of questions?

    The commands are slow because they generate a plot, which I don't want to see. Is there a way to save time by suppressing the plot? It's no big deal if you have only one time series, but if you have over 1,000, it's a drag.

    The pac command won't calculate the partial autocorrelation for lags beyond 4. Why not? Is this an arbitrary software limit, or is there some mathematical reason you can't calculate the lag-5 autocorrelation from a time series with T=12.

    Many thanks.

  • #2
    The output of help ac tells us about the corrgram command, which produces the same autocorrelations and partial autocorrelations as the ac and pac commands, without the attendant graphs, and saves these in the returned results as r(AC) and r(PAC).

    Code:
    use https://www.stata-press.com/data/r16/air2
    ac air, lags(20) generate(ac)
    pac air, lags(20) generate(pac)
    list ac pac in 1/20, clean
    
    corrgram air, lags(20) noplot
    matrix acpac = r(AC)' , r(PAC)'
    matrix list acpac
    Code:
    . list ac pac in 1/20, clean
    
                  ac          pac  
      1.   .94804734    .95893198  
      2.   .87557484   -.32983096  
      3.   .80668116     .2018249  
      4.   .75262542    .14500798  
      5.   .71376997    .25848232  
      6.    .6817336   -.02690283  
      7.   .66290439    .20433019  
      8.   .65561048    .15607896  
      9.   .67094833    .56860841  
     10.   .70271992    .29256358  
     11.   .74324019     .8402143  
     12.   .76039504    .61268285  
     13.   .71266087   -.66597616  
     14.   .64634228   -.38463943  
     15.   .58592342     .0787466  
     16.   .53795519   -.02663483  
     17.   .49974753   -.05805221  
     18.   .46873401   -.04350748  
     19.   .44987066    .27732556  
     20.    .4416288   -.04046447
    Code:
    . matrix list acpac
    
    acpac[20,2]
                   r1          r1
     lag1   .94804734   .95893198
     lag2   .87557484  -.32983096
     lag3   .80668116    .2018249
     lag4   .75262542   .14500798
     lag5   .71376997   .25848232
     lag6    .6817336  -.02690283
     lag7   .66290439   .20433019
     lag8   .65561048   .15607896
     lag9   .67094833   .56860841
    lag10   .70271992   .29256358
    lag11   .74324019    .8402143
    lag12   .76039504   .61268285
    lag13   .71266087  -.66597616
    lag14   .64634228  -.38463943
    lag15   .58592342    .0787466
    lag16   .53795519  -.02663483
    lag17   .49974753  -.05805221
    lag18   .46873401  -.04350748
    lag19   .44987066   .27732556
    lag20    .4416288  -.04046447

    Comment

    Working...
    X