Macro loop

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Macro loop

Postby lah89 » Thu Mar 06, 2014 6:04 pm

Hey all: what I want to do is to (loop over) trigger the estimation command for a model where in each iteration I change a model equation (i.e. I have different cases of a model and I want to estimate them right after each other). I created seperate files, 1 for each case labelled "1.mod", "2.mod" ..., that only contain the one model specific equation.

Here is what I tried in my main file:

Code: Select all
@#define cases = [ "1", "2",...]

VARIABLES BLOCK
PARAMETERS BLOCK

model(linear);
EQUATIONS THAT ARE THE SAME FOR ALL CASES
[b]@#include "{case}.mod" [/b] // to include the case specific equations
end;

VAROBS

ESTIMATED_PARAMS BLOCK

ESTIMATED_PARAMS_INIT BLOCK

@#for case in cases
ESTIMATION CMD
@#endfor


it tells me: ERROR in macro-processor: mainfile.mod:36.1: Could not open {case}.mod


the same happens if I try to loop over the whole code and not only the estimation cmd.

is this simply a syntax mistake or is my thinking wrong here?
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

Re: Macro loop

Postby jpfeifer » Thu Mar 06, 2014 7:41 pm

I am not sure what you are trying to achieve, but note that you are not looping over different models here, i.e. different runs of the preprocessor. Rather you loop within one model. This won't work.
For me it seems more promising to loop over calls to Dynare from Matlab, where the mod-file includes on include directive and you use matlab to change that included file before each call to Dynare.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Macro loop

Postby lah89 » Sun Mar 09, 2014 1:24 pm

thank you so much for the fast answer!

I am not so sure I understood how this would look thought, could you post a small rough example in pseudo-code?

What I want to achieve is: to estimate the model many times after each other, where in each iteration I slightly change one equation in the model block (different case of the model), with just one command.
(I simply want to have one main file because I find it more appealing than copy+pasting the mod file 10 times and then running each mod-case on its own, does that make sense?)
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

Re: Macro loop

Postby jpfeifer » Sun Mar 09, 2014 7:42 pm

I was thinking about including one file in the mod-file and then wrapping it with something like:
Code: Select all
equations={'k=0.9*k(-1)+invest;'
'k=0.8*k(-1)+invest;'};

for ii=1:size(equations,1)
%write equation to file
fid=fopen('my_equation.mod','w');
fprintf(fid,'%s \n',equations{ii,1});
fclose(fid);
%run file
dynare my_modfile noclearall
%save results
save(['results_',num2str(ii)])
end
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests