Convergence (Diagnostics) ~ preprocessor output

Hi Everyone,

These questions are mostly directed to Dynare Team, but I would appreciate any input.

  1. Can I run a .mod and make the Dynare preprocessor to produce C or JSON output?
  • If Yes can give me some pointers on how to do it?
  • Also, does this mean that I can I run Dynare in other software besides Matlab/Octave, like Python or R?
  • Is that how Dynare/Julia works?
  1. From McMCDiagnostics(options_, estim_params_, M_, oo_) , the case when mh_nblocks > 1, do you store Multivariate Diagnostics (MDIAG) and Univariate Diagnostics (UDIAG) for Brooks and Gelman test somewhere, or you just produce the graphs in “fname/metropolis/Output”? I am asking because I need them for custom plotting.

  2. For trace plots, when you have more than one block.

  • Do you combine the draws from the chains, and after removing the mh_drop sample, you add an MA(200)?
  • Is 200 random, or is there a rule to it?
  • Do you think that it makes a difference if you plot the chains independently when the number of replication is too big?
  1. Is there a routine that can calculate recursively the first four moments of the marginal posterior distribution of each parameter to see how fast it reaches the posterior mean, sd, etc? Or alternatively a cusum test? Of course, I can do it myself I am just asking if there is such a thing?

Thanks a lot!

  1. Yes, in the unstable version you can do that. @HoutanBastani may have info on this. See the manual on the json preprocessor option. What this does is create the Matlab-files created by the preprocessor with the respective model derivatives as JSON code. What this does not provide is an alternative to the Matlab routines used to work on those files, like solving the model or estimating it.
  2. No, that output is not stored. You would need to hack McMCDiagnostics.m to output those.
  3. No, draws from chains are not combined. You need to provide the number of the chain to the command. The MA(200) is just a number someone found convenient in the past. These trace plots are not a formal test, but just for visual inspection. Unfortunately, I do not understand the third part of your question
  4. No, that is not available. recursive_moments.m is a first step in this direction.
1 Like

Thanks a lot, Johannes. I appreciate your taking the time to answer all my question.

My questions have been answered for 2,3 and 4.

Just quick follow up question on the first one. So basically, the macroprocessor is parsing all the expressions in the var, var_exo, model etc, and create Matlab-output. The routines are using this info for stoch_simul, estimation or whatever. In other words, the macroprocessor is creating all the input for all the Matlab subroutines? So even If I get the output in json I would have to reconstruct almost everything. Am I right?

Thanks Again!


The macro processor only does textual manipulation using the Dynare Macro Processing language. The macro processing step is the first step in the preprocessor. After this step, the preprocessor reads the macro-expanded model written in the Dynare language and processes it, producing Matlab/Octave output.

As @jpfeifer mentioned, in the unstable version of Dynare (future 4.6) we have introduced several options to allow for the preprocessor to produce output in JSON. Those are:


These options are explained in the unstable manual.

As you remarked in your original post, having the JSON output of the preprocessor allows you to use the Dynare language to specify your model and then combine it with your code in whatever language you may so desire. This freed us from producing a separate output for every potential use and, as you say, allows you to easily specify a model and use it in Matlab/Octave/Python/R/Julia/… with your own code. As you know, the preprocessor produces specific code for Matlab/Octave. As you may not know, you can also pass the julia option to the preprocessor to produce Julia-specific output, which is used in (a version of Dynare for Julia that is in development).

I wrote a blog post a while ago that was never published showing how to use the JSON output of the preprocessor. It needs to be updated because I have updated the code that parses the equations from JSON. That said, it’ll walk you through the steps to use the JSON output of the preprocessor.

The blog post was published on Jan 28 2020. It can be found here:

1 Like

Very interesting article. I wish there were more like that to help us understand the process of dynare and the preprocessor. Let us know when you update the article.

Thank you both.

Hi, the only other preprocessor presentations are:

  • This presentation on the macro processor (up to date) macroprocessor.pdf (679.4 KB)
  • This presentation on the preprocessor (which is a bit out of date) preprocessor.pdf (495.3 KB)
1 Like