Moments calc by different methods do not match?

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Moments calc by different methods do not match?

Postby dynare_usr » Fri Apr 07, 2017 5:32 am

Hello,

I am running Dynare 4.4.3 stoch_simul with option periods.
Then I compare correlation between two variables calculated with data in oo_.var
and compare the corr coef with that calculated with oo_.endo_simul.

For example:
Code: Select all
oo_.var(2,1)/(sqrt(oo_.var(2,2)) * sqrt(oo_.var(1,1)))

and
Code: Select all
corrcoef(oo_.endo_simul(2,:),oo_.endo_simul(1,:))


Since I am using periods option, both oo_.var & oo_.endo_simul contain simulated data but I obtain significantly different results (for some series the difference is about 0.2).

Am I missing anything?
dynare_usr
 
Posts: 21
Joined: Tue Dec 29, 2015 8:21 pm

Re: Moments calc by different methods do not match?

Postby jpfeifer » Fri Apr 07, 2017 8:37 am

Please provide the full codes.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Moments calc by different methods do not match?

Postby dynare_usr » Fri Apr 07, 2017 5:06 pm

I think I figured out what went wrong.

I used stoch_simul with option periods AND option hp_filter.
oo_.var saves filtered statistics, while
oo_.endo_simul saves simulated series before the HP filter.

Can you confirm, please?

A corollary question, after I run
Code: Select all
stoch_simul(hp_filter = 100, order = 1, irf = 1000, periods=10000)

the moments I obtain via
Code: Select all
oo_.var
are the same regardless of the number of periods, whereas the moments obtained via
Code: Select all
corrcoef(oo_.endo_simul(2,:),oo_.endo_simul(1,:))
vary with the number of periods. I tried from the range from 100 to 10^4. The difference can be as high as 0.04

Does it mean that oo_.var gives theoretical moments? I thought the manual says to the contrary:
oo_.var Contains theoretical variance if the periods option is not present (or an approximation thereof for
order=2), and empirical variance otherwise.
dynare_usr
 
Posts: 21
Joined: Tue Dec 29, 2015 8:21 pm

Re: Moments calc by different methods do not match?

Postby jpfeifer » Sun Apr 09, 2017 10:59 am

1. Yes, if you specify a filter, the moments will be filtered, while the simulated series will be unfiltered
2. No, this should not be the case. Please provide the file to replicate the issue.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Moments calc by different methods do not match?

Postby dynare_usr » Wed Apr 12, 2017 5:10 am

I attached the files with minimal working examples
Code: Select all
stoch_simul(order=1, periods=1000);

and
Code: Select all
stoch_simul(order=1, periods=1000, hp_filter=100);

In this version, the difference between the correlations of C & Y are around 0.006 but it decreases with the length of the simulated series.

Also, for the HP-filtered version, I was wondering how Dynare filters the simulated series (with hp_filter option) so fast. If I conduct HP filtering of endo_simul by hand with periods=10000, it takes my computer to filter the series and to calculate the moments significantly longer than if I use Dynare's hp_filter option.
With periods = 100000, my PC runs into the curse of dimensionality.
I attached the HP filter code I use as well.

Thanks.
Attachments
hpfilter.m
HP filter
(914 Bytes) Downloaded 49 times
StochSimul_HP_empir.mod
(1.51 KiB) Downloaded 48 times
StochSimul_empir.mod
(1.05 KiB) Downloaded 47 times
dynare_usr
 
Posts: 21
Joined: Tue Dec 29, 2015 8:21 pm

Re: Moments calc by different methods do not match?

Postby jpfeifer » Wed Apr 12, 2017 8:51 am

When switching from 10000 to 1000 periods,
Code: Select all
oo_.var

goes from
Code: Select all
ans =

   0.000326615664192   0.000035416548315   0.000224502764851   0.000139894628857   0.000075319264576   0.000071830808337
   0.000035416548315   0.000021236903551   0.000049779041118   0.000027336117315   0.000001851174164  -0.000020538216304
   0.000224502764851   0.000049779041118   0.001170764900180   0.000081945259818   0.000042536905984   0.000075228986918
   0.000139894628857   0.000027336117315   0.000081945259818   0.000069473878539   0.000027843140250   0.000008756607555
   0.000075319264576   0.000001851174164   0.000042536905984   0.000027843140250   0.000019662155193   0.000026849167137
   0.000071830808337  -0.000020538216304   0.000075228986918   0.000008756607555   0.000026849167137   0.000066544587358
   

to
Code: Select all
ans =

   0.000334544718752   0.000039518537012   0.000239060495493   0.000145415558713   0.000075970615395   0.000068595256611
   0.000039518537012   0.000021475606432   0.000061794114533   0.000028638576743   0.000002871940263  -0.000018648095685
   0.000239060495493   0.000061794114533   0.001217896764845   0.000094765000760   0.000042104863384   0.000062938707817
   0.000145415558713   0.000028638576743   0.000094765000760   0.000072069499163   0.000028860770924   0.000009374071833
   0.000075970615395   0.000002871940263   0.000042104863384   0.000028860770924   0.000019467398574   0.000025289415214
   0.000068595256611  -0.000018648095685   0.000062938707817   0.000009374071833   0.000025289415214   0.000061267383943

showing that the simulation correctly works.

Regarding your second question: you are using the most inefficient version of the HP-filter you can program. It does not make use of the sparsity of HP-filter matrix and uses an explicit inverse. You might want to use Dynare's
Code: Select all
sample_hp_filter.m
instead
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Moments calc by different methods do not match?

Postby dynare_usr » Wed Apr 12, 2017 10:33 pm

Thank your for pointing my attention to sample_hp_filter.m, Johannes.

Per oo_.var. Please correct me if I am wrong but I think the comparison of oo_.var from simulations with different # of periods shows that empirical moments vary with the length of the series. Which is fine.

However, I am trying to understand why, given a certain number of periods, the values correlations calculated from oo_.var and oo_.endo_simul do not coincide.
for example, after
Code: Select all
stoch_simul(order=1, periods=1000);

I obtain the following correlations between the first two variables:
Code: Select all
OOVar =
    0.8910
CorrCoef =
    1.0000    0.8847
    0.8847    1.0000
difference between oo_.var & oo_.endo_simul:
ans =
    0.0063
dynare_usr
 
Posts: 21
Joined: Tue Dec 29, 2015 8:21 pm

Re: Moments calc by different methods do not match?

Postby jpfeifer » Fri Apr 14, 2017 9:58 am

That's because Dynare drops
Code: Select all
options_.drop

periods of burnin when computing the moments
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Moments calc by different methods do not match?

Postby dynare_usr » Mon Apr 17, 2017 6:52 pm

Great, thanks.
dynare_usr
 
Posts: 21
Joined: Tue Dec 29, 2015 8:21 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 8 guests