I’m trying to generate some simulated dataset of New Keynesian model for further estimation, but I got the same simulated values even when I changed the parameter values. I have no clue why it happens. Here attached the .mod file. Thank you in advance.
var pie R x z xi;
varexo eps_z eps_r;
parameters alpha beta kappa phi_x phi_pie rho_r rho_z sigma sigma_z sigma_r theta >omega; // DECLARATION OF THE DEEP PARAMETERS.
// Parameter Values
alpha = 0.6;
beta = 0.99;
phi_x = 0.125;
phi_pie = 1.5;
rho_r = 0.75;
rho_z = 0.9;
sigma = 1;
sigma_z = 0.3;
sigma_r = 0.2;
theta = 6;
omega = 1;
kappa = ((1-alpha)*(1-alpha*beta)*(omega+theta))/(alpha*sigma*(omega+theta));
// DECLARATION OF THE (LINEAR) DSGE MODEL:
model(linear);
pie = kappa*x + beta*pie(+1);
x(+1) - x = sigma*(R - pie(+1) -z);
R = rho_r*R(-1) + (1-rho_r)*phi_pie*pie + (1-rho_r)*phi_x*x + xi;
z = rho_z*z(-1) + sigma_z*eps_z;
xi = sigma_r*eps_r;
end;
shocks;
var eps_z;
stderr 1;
var eps_r;
stderr 1;
end;
stoch_simul(order = 1, periods = 232, simul_replic = 1, nograph);
[sim_array]=get_simul_replications(M_,options_);
y_sim=squeeze(sim_array(strmatch('y',M_.endo_names,'exact'),:,:));
I do not know the routine get_simul_replications, but I suppose it reads data produced by stoch_simul and saved on the disk. You have to be aware that Dynare resets the seeds of the random generator between each run, meaning that it will use the same realisation of the sequence of shocks (eps_z and eps_r) in each run. Are you sure you are changing the values of the parameters? How do you do that?
I’m using the following codes to loop over the alphas
% loop over values of alpha, get irf using dynare
alphas = 0.7:0.01:0.8;
irfs = zeros(length(alphas), 4*(h+1));
first_time = 1;
for i=1:length(alphas)
global p h;
if first_time;
set_param_value('alpha',alphas(i));
dynare dgploopvar noclearall; % degenerate 50 samples with alpha
first_time = 0;
else
set_param_value('alpha',alphas(i));
info = stoch_simul(var_list_);
if info;
disp(['Computation fails for alpha = ' num2str(alpha)]);
end;
end
% rest codes to extract information I want to know
end
But even when I manually change the parameter values, I get the same simulations. It seems I didn’t solve the model correctly.
Thank you Prof. Pfeifer. It seems that though I run the loop and call Dynare to run the .mod file every time, the inside parameter values are not updated. I’m still trying to figure out why.
I debugged it. It’s because I didn’t update the results in sim_arry. It works with following matlab codes.
% loop over values of alpha, get irf using dynare
alphas = 0.7:0.01:0.8;
irfs = zeros(length(alphas), 4*(h+1));
first_time = 1;
for i=1:length(alphas)
global p h;
if first_time;
set_param_value('alpha',alphas(i));
dynare dgploopvar noclearall; % degenerate 50 samples with alpha
first_time = 0;
else
set_param_value('alpha',alphas(i));
info = stoch_simul(var_list_);
[sim_array]=get_simul_replications(M_,options_);
y_sim=squeeze(sim_array(strmatch('y',M_.endo_names,'exact'),:,:));
if info;
disp(['Computation fails for alpha = ' num2str(alpha)]);
end;
end
% rest codes to extract information I want to know
end
Thank you both for the advice. I’ll mark this one as solved.