Page 1 of 1
		
			
				loop over certain antizipation horizons
				
Posted: 
Thu Apr 14, 2016 9:01 am 
				by anmeer
				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.
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Mon Apr 18, 2016 8:11 pm 
				by jpfeifer
				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.
 
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Mon Apr 25, 2016 5:51 pm 
				by timjackson
				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
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Thu Apr 28, 2016 9:07 am 
				by jpfeifer
				Please provide the files. Details are crucial here.
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Thu Apr 28, 2016 3:40 pm 
				by timjackson
				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
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Sun May 01, 2016 4:32 pm 
				by jpfeifer
				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
 
			 
			
		
			
				Re: loop over certain antizipation horizons
				
Posted: 
Tue May 03, 2016 3:34 pm 
				by timjackson
				That's fantastic, thank you very much.
Best,
Tim Jackson