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. nkm1.txt (766 Bytes)
z = z(+1)-1/sigma*(i-pi(+1));
i = delta_pipi+delta_zz;
pi = beta*pi(+1)+(sigma+theta)kappaz+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
[/code]
and call it using
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
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
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.
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.