Hi all;
I use the code below to loop over a parameter. However, in each iteration I end up with the same value in the vector std_y. How can I fix this problem?
I use the Dynare 4.6.3 version.
Best regards,
> std_y=[];
> rho = 0.5:0.05:1;
> first_time = 1;
> for ii=1:length(rho)
> if first_time
> dynare model noclearall;
> set_param_value('rho_a',rho(ii));
> first_time = 0;
> std_y(ii)=sqrt(oo_.var(1));
> else
> set_param_value('rho_a',rho(ii));
> info = stoch_simul(M_, options_, oo_, var_list_);
> std_y(ii)= sqrt(oo_.var(1));
> if info
> disp('Computation fails for rho = ', num2str(rho_a));
> end
> end
> end
As far as I can see there is no issue with your .m-file. test.m (1007 Bytes)
You may like to use the resol command instead of stoch_simul.
The AR(1) parameter is updated in each iteration, but due to the model structure and the very small variance of the innovation the impact on the variance of output seems to be negligible.
You may double check whether your implementation of the TFP shock is correct.
@Max1 Thanks for your reply,
1- Using resol() instead of stoch_simul() doesn’t solve the problem.
2- I disagree, the problem is not coming from the variance of the innovation, you can check the vector y_std and you’ll see that the same value is repeated in each iteration. Everything happen as if the only value reported in y_std in each iteration is the one coming from the first iteration.
3- I think my implementation of the TFP is correct since running the model outside the loop everything seems to work perfectly.
I run the code on Dynare 4.5.7 version, with a slight change of info = stoch_simul(M_, options_, oo_, var_list_)
to info = stoch_simul(var_list_).
And I got the values I expected for std_y (no repeated value anymore).
My question now is why the code doesn’t run properly on 4.6.3 version ? What changes should I make ?
resol does not compute variances. You need to call stoch_simul.
When calling stoch_simul in Dynare 4.6.3. you do not just have to alter the inputs, but also the outputs:
addpath c:\dynare\4.6.3\matlab
clear all
close all
clc
std_y=[];
rho = 0.5:0.05:1;
first_time = 1;
%dynare mymodel
for ii=1:length(rho)
if first_time
dynare mymodel noclearall;
set_param_value('rho_a',rho(ii));
first_time = 0;
std_y(ii)=sqrt(oo_.var(1));
else
set_param_value('rho_a',rho(ii));
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
std_y(ii)= sqrt(oo_.var(1));
if info
disp('Computation fails for rho = ', num2str(rho_a));
end
end
end
plot(rho,std_y)
The reason you are getting the same result all of the time is that you do not request oo_ as an output.
@jpfeifer Thanks for making this clear. resol only updates the decision rule and hence the steady state but not the moments.
@Ecofai Please take into consideration that the (theoretical) variances will not be computed under a unit root (if. rho =1). Hence, the last entry in std_y will be NaN, if you don’t use the periods option.