Page 1 of 1

Macroprocessor question

PostPosted: Sun Nov 03, 2013 9:47 am
by jonathanb
Dear all,
thank you in advance for your answers.

I have one mod file and inside I have a loop (@#for /@#endfor) framing my estimation and stoch simul commands.
It works very well.

Now, I would like to add another loop, with the same incrementation as my previous loop around estim/simul commands (hereafter I call it "pas"), in the parameter block.
It does not work :-(
How could I do it this ?

Here is the code:

close all;
var y, pi, r, yf, ep, ei, at;
varexo up, ui, ua;

parameters alpha beta teta sigma neta epsilon li1 li2 li3 rhoa rhop rhoi pb yb rb;

@#for pas in 1:49
load nyc1@{pas};
@#endfor

alpha = 0.33;
beta = 0.99;
teta = 0.66;
sigma = 2.0;
neta = 1.0;
epsilon = 6.0;
li1 = 0.50;
li2 = 2.5;
li3 = 0.5;

rhoa = 0.75;
rhop = 0.75;
rhoi = 0.50;
rhom = 0.75;

set_param_value('pb',tr)
yb = 0;
rb = 0;

model;
yf = ((1+neta)/(sigma*(1-alpha)+neta+alpha))*at + ((1-alpha)*(-(log((1+(1/((1/(epsilon-1)))))/((1+(1/((1/(epsilon-1)))))-1))))/(sigma*(1-alpha)+neta+alpha));
pi = beta*pi(+1)+((1-teta)*(1-beta*teta)*(sigma*(1-alpha)+neta+alpha)/(teta*(1-alpha+alpha*(1+(1/((1/(epsilon-1))+ep))))))*(y-yf);
y = y(+1)-(1/sigma)*(r-rb-pi(+1));

r-rb = (1-li1)*(li2*(pi-pb) + li3*(y-yf)) + li1*(r(-1)-rb) + ei;

at = rhoa * at(-1) + ua;
ep = rhop * ep(-1) + up;
ei = rhoi * ei(-1) + ui;
end;

steady;
check;

shocks;
var ua = 0.01;
var ui = 0.01;
var up = 0.01;
end;

estimated_params;
alpha, beta_pdf, 0.33, 0.05;
teta, beta_pdf, 0.66, 0.05;
sigma, normal_pdf, 2.0, 0.05;
neta, normal_pdf, 1.0, 0.1;
epsilon, normal_pdf, 6.0, 0.1;
li1, beta_pdf, 0.5, 0.25;
li2, normal_pdf, 2.5, 0.25;
li3, normal_pdf, 0.5, 0.25;

rhoa, beta_pdf, 0.75, 0.1;
rhop, beta_pdf, 0.75, 0.1;
rhoi, beta_pdf, 0.50, 0.1;

stderr ua, inv_gamma_pdf, 0.01, 2;
stderr ui, inv_gamma_pdf, 0.01, 2;
stderr up, inv_gamma_pdf, 0.01, 2;
end;

varobs pi y r;

@#for pas in 1:49
estimation(nograph,nodisplay,order=1,datafile=nyc1@{pas},filter_step_ahead=[1:12],mode_compute=4,bayesian_irf,forecast=12,mh_jscale=0.6,mh_replic=6000,mh_nblocks=2) pi y r yf;
stoch_simul(nograph,nodisplay,order=2,irf=40,conditional_variance_decomposition=[1 4 40]);
close all;
oobase@{pas}_=oo_;
save base@{pas}_oo oobase@{pas}_
close all;
@#endfor

Best,
Jonathan

Re: Macroprocessor question

PostPosted: Sun Nov 03, 2013 1:58 pm
by jpfeifer
Hi, what do you mean with "Does not work"?

Moreover, have you tried using the
Code: Select all
savemacro
option to see to what your code is translated?

Re: Macroprocessor question

PostPosted: Sun Nov 03, 2013 3:18 pm
by jonathanb
Hi Johannes,
thank you for your answer. No I do not use savemacro option but I will try.
It does not work because when I run my mod file, it runs first
this:
@#for pas in 1:49
load nyc1@{pas};
@#endfor

then, it gives the value of pas=49 for set_param_value('pb',tr)
because it is the last value of the loop.

And after this it runs the other loop at the end. The "pas" parameter that tell us in which point of the loop we are are not the same between the two loop in my mod file.
I want to have, if it is possible, a big loop such as this:

@#for pas in 1:49
var y, pi, r, yf, ep, ei, at;
varexo up, ui, ua;
parameters alpha beta teta sigma neta epsilon li1 li2 li3 rhoa rhop rhoi pb yb rb;
parameter declaration etc..
model
etc...
estimation
stoch_simul
@#endfor

But this also does not work...
Thany you for you help
Best,
Jonathan

Re: Macroprocessor question

PostPosted: Sun Nov 03, 2013 3:32 pm
by jonathanb
Hi,
I just tried savemacro, it gives me exactly what I expect, but this is my problem also.

for the loop
@#for pas in 1:49
load nyc1@{pas};
@#endfor

it loads successively
load nyc11.mat;
load nyc12.mat;
etc..
until load nyc149.mat;

And then the value of set_param_value('pb',tr) after the loop is in fact the value for pas=49, which is fully disconnected with the "pas" in the loop below

Re: Macroprocessor question

PostPosted: Mon Nov 04, 2013 9:21 am
by jpfeifer
I would recommend using a loop over Dynare instead of using the macroprocessor: http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891