Addpath for m-files in dynare mod-file, need two runs of dynare to work

Hi!

I have a problem regarding the use of matlab code in the dynare file.

I have partitioned the model into several model blocks and put the different partitions in a separate folder, the folder being called “model_files”. Then I use the macro #@includepath to include the folder where I put the model blocks. In the folder, I also put some m-files, especially the model_steadystate.m file.

I realized that the macro #@includepath does not help regarding the m-files, so i also put into the code addpath ‘model_files’.

This works, but for one caveat, which is terribly annoying, and will have to be fixed in the long run when the model is put to work in my organization.

I have to run “dynare model” twice for this to work. In the first run, I get NaN:s from the parameters calculated in model_steadystate.m. The second time I type “dynare model” it does however run properly, since then the addpath command have gone through.

Why is this happening, and is there any way to fix it without putting the model_steadystate.m file in the same folder as the model.mod file?

(the reason I want them in different folders is because I copy and paste the model files when I do experiments, and if they lie in a separate folder it is easy and fast to do this without missing any important files)

Here is the code (the model’s name is SELMA):
addpath(‘SELMA_files’);
@#includepath “SELMA_files”
@#include “SELMA_VarsParams.mod”
@#include “SELMA_calibration.mod”
@#include “SELMA_modelBlock.mod”

Thanks!

  1. Does your steady state file do anything non-standard or can you transform it into a steady_state_model-block? That would solve the problem immediately.
  2. Where exactly do you put the addpath? It sounds as if it comes too late. And which Matlab version are you using? The handling of relative paths has changed recently.

Hi, and thank you for your fast response.

Regarding nr 1, I do not excactly understand what you mean. It is during the command “steady;” that this happens. The code is, from top to the command check:

addpath(‘SELMA_files’);
@#includepath “SELMA_files”
@#include “SELMA_VarsParams.mod”
@#include “SELMA_calibration.mod”
@#include “SELMA_modelBlock.mod”

steady;
model_diagnostics;
check;

When you write that I should turn the steady-state into a model block, do you then mean that I should put the last three lines into its own block and put it into the folder, or what excactly do you mean? (If the answer is a long one, perhaps you could tell me to google it? :slight_smile:

Regarding nr 2, it is the first line of the code, and I am using MATLAB R2018a

  1. There are two ways to use an analytical steady state: the _steady_state.m-file you seem to be using and the steady_state_model-block that uses commands within the mod-file to create a Matlab file. The first one is more flexible as it more readily allows e.g. calling a numerical solver. The second is faster and in your case a possbiel solution, because you don’t need to call a separate m-file here. See e.g. Remark 15 (initval vs. steady_state_model vs. steadystate-file)
    in Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models

  2. Could you please provide me with the m-file generated by the first call to Dynare? I would need to see where the addpath-command is put by Dynare in the context of model execution.