If conditional by using loops outside the model

#1

Hello may you help me looking at this code. It is supposed to get the loop @#for pp in 0:1 in line 56, which it is being grabbed for the if conditional in lines 111 to 114.

i need to solve the model for these conditionals, but learning how to implement if condiitonal within model block but by using a loop from outside as in line 56. May you help me to figure it out please? :slight_smile:

The error message is

Starting preprocessing of the model file …
ERROR: There are 104 equations but 52 endogenous variables!

It’s like I’d have the double of equations but not, it is doubling the number of equations because there are two values 0 or 1 which enter into the conditional…what would be the error. How dynare it is not reading the @#for properly.
marola.mod (8.45 KB)

#2

You cannot have two different models in the same MOD file. You should split this into 2 MOD-files (or maybe even 3, where a file contains all the factorized parts, and is @#include’d from the other 2).

#3

Hi, thank you for the nice answer. However, i have a question on this. I think i can have several models in the same MOD file as you said. But do i have to consider separate cases? I mean, if i have three “if cases” w.r.t. the model(for example, one equation of a model changes ), do i have write down all the models three times? In other words, “can i use loop over a model?”

#4

Looping over model variants is feasible, but is a bit tricky.

From a MATLAB script, you would write a loop over the main dynare command. Just before calling Dynare, you would programatically create a small MOD file containing one or several @#define statements corresponding to what changes across loop iterations. This generated MOD file would then be included from the main mod file that Dynare is run on.

A caveat is that the dynare command by default clears all variables in the MATLAB workspace. There are two possible solutions. One is to pass the noclearall flag to dynare, but this is not very well-tested. The other possibility is to save the variables of your workspace to a MAT file just before calling Dynare, and then reloading that MAT file upon exit from Dynare.

#5

Ok. It helped me a lot. Thank you

#6

@aeyton You may want to have a look at the example at https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Born_Pfeifer_2018/Welfare/run_welfare_comparison_inefficient_steady_state.m
with the mod-file
https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Born_Pfeifer_2018/Welfare/Born_Pfeifer_2018_welfare.mod

#7

Thank you, professor. Now i get the difference between those two regarding my question.