Page 1 of 1

Distribution of steady states after Metropolis iterations

PostPosted: Mon Feb 13, 2012 7:31 am
by Vik
Hi!

I need the distribution of steady states after Metropolis iterations. Is it possible to see (or find, or save somehow) the distribution of steady states?

Thank you

Re: Distribution of steady states after Metropolis iteration

PostPosted: Mon Feb 13, 2012 7:05 pm
by jpfeifer
This one is tricky. You need to change two files in Dynare 4.2.4. First, in matlab\random_walk_metropolis_hastings_core.m you need to insert
Code: Select all
oo_.Metropolis_steady_state=NaN(size(oo_.steady_state,1),nblck*nruns(1));

after line 133 (jloop=0;).

Moreover, in DsgeLikelihood.m, you need to insert
Code: Select all
[ST,I] = dbstack;
if strcmp(ST(2).name,'random_walk_metropolis_hastings_core')
    j=evalin('caller','j');
    b=evalin('caller','b');
    nruns=evalin('caller','nruns(1)');
    oo_.Metropolis_steady_state(:,(b-1)*nruns+j)=zeros(size(oo_.steady_state));
end

after line 46 (nobs = size(options_.varobs,1);). Finally, after the line
Code: Select all
[T,R,SteadyState,info] = dynare_resolve('restrict');

in DsgeLikelihood.m you need to add
Code: Select all
if strcmp(ST(2).name,'random_walk_metropolis_hastings_core')
    oo_.Metropolis_steady_state(:,(b-1)*nruns+j)=SteadyState;
end

After running the MCMC the steady states are saved in oo_.Metropolis_steady_state. Steady states from different chains are stacked in column order. Invalid parameter draws have a SS of NaN.

Re: Distribution of steady states after Metropolis iteration

PostPosted: Tue Feb 14, 2012 11:01 am
by Vik
Thanks a lot for helpful instruction. But, I can't find oo_.Metropolis_steady_state after running Metropolis iterations.

Re: Distribution of steady states after Metropolis iteration

PostPosted: Tue Feb 14, 2012 1:12 pm
by jpfeifer
Could you post the mod-file? In the workspace, the structure oo_ should have a corresponding field called Metropolis_steady_state

Re: Distribution of steady states after Metropolis iteration

PostPosted: Wed Feb 15, 2012 8:47 am
by Vik
I find oo_.Metropolis_steady_state if I run the cods in Matlab 7.0.0 version, although steady states from different chains are stacked in one row. But I can't find it in Matlab 7.12.0.635 (R2011a) version. Attached is just slightly changed RBC_est.mod file from User guide example.

Re: Distribution of steady states after Metropolis iteration

PostPosted: Wed Feb 15, 2012 10:39 am
by jpfeifer
Using Matlab 2011b, it works on my machine. I get a 9*4000 matrix that contains the 2000 steady states vectors of size 9 by 1 for the two chains. Attached are the modified file from Dynare 4.2.4

Re: Distribution of steady states after Metropolis iteration

PostPosted: Wed Feb 15, 2012 2:56 pm
by Vik
I suggest it's a problem with my Matlab. After running the program with the modified files from Dynare 4.2.4, I get the following fields of oo-. structure, and still can't find Metropolis_steady_state field: :
    oo_ =

    exo_simul: 0
    endo_simul: [9x1 double]
    dr: [1x1 struct]
    exo_steady_state: 0
    exo_det_steady_state: []
    exo_det_simul: []
    steady_state: [9x1 double]
    posterior_mode: [1x1 struct]
    posterior_std: [1x1 struct]
    MarginalDensity: [1x1 struct]
    posterior_mean: [1x1 struct]
    posterior_hpdinf: [1x1 struct]
    posterior_hpdsup: [1x1 struct]
    posterior_median: [1x1 struct]
    posterior_variance: [1x1 struct]
    posterior_deciles: [1x1 struct]
    posterior_density: [1x1 struct]
    prior_density: [1x1 struct]
    Smoother: [1x1 struct]
    FilteredVariablesKStepAhead: [0x9x101 double]
    SmoothedVariables: [1x1 struct]
    FilteredVariables: [1x1 struct]
    UpdatedVariables: [1x1 struct]
    SmoothedShocks: [1x1 struct]

Re: Distribution of steady states after Metropolis iteration

PostPosted: Wed Feb 15, 2012 6:39 pm
by Vik
For Matlab 7.0.0 it seems to be OK. Should I deinstall all previous Dynare versions or remove the Matlab path to them to get the result?
    oo_ =

    exo_simul: 0
    endo_simul: [9x1 double]
    dr: [1x1 struct]
    exo_steady_state: 0
    exo_det_steady_state: []
    exo_det_simul: []
    steady_state: [9x1 double]
    posterior_mode: [1x1 struct]
    posterior_std: [1x1 struct]
    MarginalDensity: [1x1 struct]
    Metropolis_steady_state: [9x4000 double]
    posterior_mean: [1x1 struct]
    posterior_hpdinf: [1x1 struct]
    posterior_hpdsup: [1x1 struct]
    posterior_median: [1x1 struct]
    posterior_variance: [1x1 struct]
    posterior_deciles: [1x1 struct]
    posterior_density: [1x1 struct]
    prior_density: [1x1 struct]
    Smoother: [1x1 struct]
    SmoothedVariables: [1x1 struct]
    FilteredVariables: [1x1 struct]
    UpdatedVariables: [1x1 struct]
    SmoothedShocks: [1x1 struct]

Re: Distribution of steady states after Metropolis iteration

PostPosted: Wed Feb 15, 2012 8:35 pm
by jpfeifer
Try using the Matlab "which" command to find out if the newer Matlab version actually calls the changed files, i.e. type
Code: Select all
which random_walk_metropolis_hastings_core.m

or alternativey
Code: Select all
edit random_walk_metropolis_hastings_core.m

to directly look into the file that is called.

Re: Distribution of steady states after Metropolis iteration

PostPosted: Thu Feb 16, 2012 7:26 am
by Vik
Yes, that was the problem.
Thank you very much for help!