Unfixing the Random seed

Hi,
I use the simulation coming from a .mod file as the DGP.
I need to do a MonteCarlo experiment, where I need to simulate the model M times.
Obviously, each of the M simulations should be different. Since now Dynare fixes automatically the seed for the RNG, I cannot see how to do it.
I have used the command set_dynare_seed(‘clock’) and also I tried to use set_dynare_seed(randi(1000000,1)) (to give as a seed a random integer every time), but I do not obtain simulations that are different.

Techincally, I run a for loop calling each time the .m file associated with the .mod file that solves and simulate the model I am interested in, and for each iteration of the loop I store the simulated variable.

Thanks for your help

Could you post an example? It is hard to track the interaction and which command is called in the mod-file and the wrapping m-file you wrote.

The question is really simple.

Suppose I have a .mod file (model.mod) that at the end produce the stochastic simulation for T periods of one variable of interest (let’s call it Y).
I want M different simulations of Y when running the model file M times. Let’s call YMATRIX the matrix that gathers all the M time series for Y.

In a .m file I write the following loop:

M=1000;
for i = 1: M
model.m
YMATRIX(:,i)=Y.
end

where in the model.m fine I have delete the line that “clear all” the variables.

If I run this simple Loop, the YMATRIX is composed by M columns that are exactly the same, since every time that dynare does the stochastic simulation it fixes (in the new version) the seed for the random generator.

Instead, I would like to have M different time series for Y, which requires unfixing the random seed used by dynare.

Thanks

I see. When you tried to use

where did you put this command? Did you try to put it directly before the stoch_simul-command?

[quote=“jpfeifer”]I see. When you tried to use

where did you put this command? Did you try to put it directly before the stoch_simul-command?[/quote]

yes, I did.

I put it in the model.m file,
before the line options_.periods = 2000 (which is where dynare put it in the .m file created by running the .mod file where set_dynare_seed('clock'); is directly before stock_simul.

The results, when running that are weird:
The simulations are not all equal, but the 2nd and 3rd are the same. The 4th and 5th are the same. The 7th and 8th are the same (but different among each other)…
It seems that ‘clock’ is not random “enough”…

Maybe the the execution is too quick so that the clock-time is identical. Did you try

instead, i.e. you use the exterier loop variable i to change the seed?

[quote=“jpfeifer”]Maybe the the execution is too quick so that the clock-time is identical. Did you try

instead, i.e. you use the exterier loop variable i to change the seed?[/quote]

That indeed works fine.
The funny thing was that I tried initially to assign a random integer in any iteration using [code]set_dynare_seed(randi(20000000,1))\code] and that did not work fine.

Thanks a lot

Short explanation: When Dynare fixes the seed, you cannot use randi to draw different random numbers because the output from randi will always be the same.