loop over certain antizipation horizons

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.

loop over certain antizipation horizons

Postby anmeer » Thu Apr 14, 2016 9:01 am

Hello everyone,

I am working on a very basic NK model and currently want to examine the effects of anticipated cost shocks. Running loops over parameters isn’t the problem. But now I would like to know if there is any possibility to run a loop over different anticipation horizons (i.e. 1,2,3,4,8), to simplify programming. The code is attached.

I would appreciate any help and tips.
Attachments
nkm1.txt
(766 Bytes) Downloaded 127 times
anmeer
 
Posts: 1
Joined: Thu Apr 14, 2016 8:44 am

Re: loop over certain antizipation horizons

Postby jpfeifer » Mon Apr 18, 2016 8:11 pm

Save the following mod-file
Code: Select all
var       z pi p i u;
varexo     u_init;

parameters  beta rho sigma delta_pi theta delta_z omega;

beta          = 0.99;
rho           = 0.8;
sigma         = 1;
delta_pi      = 1.5;
theta         = 1.16;
delta_z       = 0.5;
 
 
model(linear);
# kappa= ((1-omega)*(1-omega*beta))/omega;
z = z(+1)-1/sigma*(i-pi(+1));
i = delta_pi*pi+delta_z*z;
pi = beta*pi(+1)+(sigma+theta)*kappa*z+u;
pi = p-p(-1);
 
u = rho*u(-1)+u_init(-@{antic_horizon});   // anticipated cost shock, antic_horizon periods before materialization
end;
 
shocks;
var u_init = 1;
end;
 
@#for omega_val in ["0.8","0.75","0.70"]
omega = @{omega_val};
stoch_simul(irf=100, nograph);
@#endfor

and call it using
Code: Select all
dynare Antic_loop -Dantic_horizon=2

where the -D switch sets the anticipation horizon, which is a macroprocessor variable used within the mod-file (see the macroprocessor.pdf in the Dynare/doc-folder). You can essentially loop over it by calling

Code: Select all
for ii=1:10
eval(['dynare Antic_loop -Dantic_horizon=',num2str(ii),' noclearall'])
end

You still need to do the saving of the results. Depending on what you want to do, you will need the
Code: Select all
noclearall

option to not erase the workspace in every call.
------------
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: loop over certain antizipation horizons

Postby timjackson » Mon Apr 25, 2016 5:51 pm

Thank you for your help with this, the -D switch is very useful but I couldn't get the above code working in the loop as suggested; Dynare fails to parse through the value of ii in the MATLAB for loop, instead taking 'ii' at face-value and producing the following error:


ERROR: Antic_loop.mod: line 22, cols 27-28: Unknown symbol: ii

Error using dynare (line 174)
DYNARE: preprocessing failed

Error in LoopExample (line 2)
dynare Antic_loop -Dantic_horizon=ii


Please let me know if I'm making a stupid mistake! My LoopExample.m file is copied directly from the loop code above and produces the same error with or without the noclearall command.

Thank you for your help,

Tim Jackson
timjackson
 
Posts: 7
Joined: Tue Mar 08, 2016 3:29 pm

Re: loop over certain antizipation horizons

Postby jpfeifer » Thu Apr 28, 2016 9:07 am

Please provide the files. Details are crucial here.
------------
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: loop over certain antizipation horizons

Postby timjackson » Thu Apr 28, 2016 3:40 pm

Please find attached, I simply copy and pasted your code from above, please let me know if I have made a stupid mistake. I tried it both with and without the noclearall option.

Thanks,

Tim
Attachments
LoopExample.m
(65 Bytes) Downloaded 120 times
Antic_loop.mod
(806 Bytes) Downloaded 107 times
timjackson
 
Posts: 7
Joined: Tue Mar 08, 2016 3:29 pm

Re: loop over certain antizipation horizons

Postby jpfeifer » Sun May 01, 2016 4:32 pm

That was my mistake. You have to transform the ii into a number. I updated the code above. It must be

Code: Select all
for ii=1:10
eval(['dynare Antic_loop -Dantic_horizon=',num2str(ii),' noclearall'])
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

Re: loop over certain antizipation horizons

Postby timjackson » Tue May 03, 2016 3:34 pm

That's fantastic, thank you very much.

Best,

Tim Jackson
timjackson
 
Posts: 7
Joined: Tue Mar 08, 2016 3:29 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 14 guests