Simul_replic broken?

I’m having trouble using the output of stoch_simul with option simul_replic enabled.

When I run rbc.mod (attached below) it does generate a file RBC_simul, which according to the manual is meant to be in binary form (which in other places in the manual indicates a .mat file). But when I then try loading it via:

load -mat rbc_simul

I get the following error:

Error using load
Unable to read MAT-file C:\mydirectory\RBC_simul. Not a binary MAT-file. Try LOAD -ASCII to read as text.

Without using the -mat option I just get a zero, which doesn’t look right either…

I’ve also tried using the get_simul_replications(M,options_);_ to access the simulation results directly from the mod file, as done by Johannes in the Hansen1985.mod (attached) which he linked to in a related topic, but that no longer seems to be supported either (and, consequently, the .mod file crashes)…

I’m on dynare 4.5.4 and have tried using other .mod files but not earlier dynare versions. If it’s a binary file but not a .mat file, info on the structure would also be appreciated…

Many thanks and apologies in advance if I’m doing something silly…

Hansen1985.mod (6.0 KB)
RBC.mod (789 Bytes)

Not sure this is helpful, but for what it’s worth:

  • I thought it may be a Matlab issue, as I’m on 2015a which is getting a bit dated, but just checked on 2017b and I have exactly the same symptoms.
  • I went back in time (-ish), but was unable to find a version of dynare where this worked (as I would expect it to). Specifically, the log mentions simul_replic being broken in 4.3.0 (which I think is when it was introduced?), and sure enough it wasn’t generating the _simul file then, but when I tried 4.3.1 I was already getting a file, which I was unable to read?

All that said, what I’m really after is conditional forecasts from non-linear models, so if there’s some neat way of generating these, then any suggestions would be gratefully received (I know that running stoch_simul in a loop will give me what I’m after, but it’s probably not particularly efficient?).

Thanks again,

I cannot reproduce any problems with your mod-file when using


together with my file you mentioned. What is the error message you get?

Hey Johannes,

Good to read you, thanks for your help and apologies for not being more specific. When I run dynare on Hansen1985 I get the following error:

Undefined function or variable ‘get_simul_replications’.

Error in Hansen1985 (line 176)

Error in dynare (line 223)
evalin(‘base’,fname) ;

So it seems I’m missing get_simul_replications? Which I assumed, perhaps wrongly, was meant to be part of the standard package?

Many thanks and hope this helps,

EDIT: Google is your friend, as they say. I found your get_simul_replications on github at and now Hansen1985 runs smoothly. Thanks and off to play with the code!

To answer my own question in the thread title: simul_replic is NOT broken.

In fact, it generates a _simul file which is not a mat file but a ‘proper’ Matlab binary file. And the instructions in Johannes’s file tell you how you can access simulation results (simulated_series in the code snippet below):


simulations=fread(fid,[DynareModel.endo_nbr*options_.periods options_.simul_replic],‘float64’);
simulated_series=reshape(simulations,[DynareModel.endo_nbr options_.periods options_.simul_replic]);

The simulated_series variable has dimensions: nr_variables x simulation_length x nr_simulations . My understanding is that the variable ordering matches that in oo_.steady_state i.e. the variables are in order of declaration used in var command (which is also used in M_.endo_names).

Thanks again Johannes!