Loop over certain antizipation horizons

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.
nkm1.txt (766 Bytes)

Save the following mod-file

[code]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-omegabeta))/omega;

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

option to not erase the workspace in every call.

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.

Tim Jackson

Please provide the files. Details are crucial here.

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
LoopExample.m (65 Bytes)
Antic_loop.mod (806 Bytes)

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

```for ii=1:10 eval('dynare Antic_loop -Dantic_horizon=',num2str(ii),' noclearall']) end```

That’s fantastic, thank you very much.

Best,

Tim Jackson