Computing autocorrelations

Hi,

I’m wondering how dynare computes autocorrelations and how to replicate the results with matlab formulas. I have been trying to replicate the autocorrelations from simulated data using the matlab function autocorr, but I still find a discrepancy with the dynare autocorrelations that I would like to understand. I’m using dynare version 4.2.2 with Matlab version 7.13.0.564. I have a rather simple linear model that I have calibrated. I simulate the model over 160 periods with the following command line:

set_dynare_seed(1); stoch_simul(periods=160,drop=0,order=1);

To compute the autocorrelations I use autocorr (mathworks.com/help/toolbox/e … ocorr.html). For instance, for the first variable—which I call var1—I would write:

acfvar1=autocorr(oo_.endo_simul(1,options_.drop+1:end)’,5)

and I would obtain:

acfvar1 =
0.9489 0.9026 0.8481 0.8029 0.7634

Now compare those numbers to the autocorrelation results that dynare provides for the same variable:

0.9436 0.8979 0.8446 0.8005 0.7612

with differences equal to:

-0.0053 -0.0047 -0.0035 -0.0024 -0.0022

These are not large discrepancies, but I’m not sure why they do occur and I’m concerned I am missing something important. Can anyone help me figure out why autocorr is giving me slightly different results and suggest how to correct for it in order to match the output that dynare reports?

Thanks so much!

I guess Dynare is not using the same normalizing constant for the empirical autocorrelation: Dynare divides by N-ar where ar is the maximum number of lags.

You can see what Dynare does exactly by looking at the “disp_moments.m” file in the “matlab” subdir.

Best,