Multiple Stochastic Simulations

Hi,

I’m relatively new to dynare and was wondering whether there is a way to get multiple stochastic simulations.
I first thought that the option stoch_simul would do the trick but am not so sure anymore.

Any help is greatly appreciated!

Many thanks in advance!

Best

1 Like

Hi,
the stoch_simul(periods=T,…) simulates T observations from the model. However, it does that only once. What you can do is to create a loop that simulates many times, T periods. The simulated model-generated data is saved in a matrix called “oo_.endo_simul” which is a J-by-T matrix, where J is the number of endogenous variables in your model (in declaration order if I am not mistaken). What I do when I simulate a model many times, I save this matrix into matrices simulation1, simulation2, …simulationI where I (capitl i) is the total number of simulations. Then, I save all these matrices in a .mat file and then I use matlab programms (not dynare anymore) to analyse them - e.g. correlations, variances etc. Here is how I do it:

I = 1000 ; % insert the number of desired simulations
for i = 1:I ; % that simulates the model I times

var
....
varexo
...
parametres
model 
...
... etc etc

stoch_simul(periods=200, irf=0, nocorr, nofunctions, nomoments)  ; % Iuse all these options to run the loop faster

eval('simulation',num2str(i), '=oo_.endo_simul(:,:);']) ; % saves all simulated data in a matrix simulation(i), for simulation attempt i

% these commands save the matrices into a .mat file called filename. Check matlab help for "eval" and "save" and "save ... -append" if you don't know them
if i==1 ;
    eval('save filename simulation', num2str(i), ';']);
else ;
    eval('save filename simulation', num2str(i), ' -append;']);
end;

end; % the loop ends, goes back to "for" and re-runs the model. 

Hope that helps.

Kyriacos

1 Like

Hi Kyriacos,

thank you so much.
Your post is exactly what I was looking for!

Do you also know by any chance how I can simulate with starting values differing from the steady state values?

Many thanks in advance!