Dear all,
I met a problem that there is no the same one on the forum, so I here ask for help
Thanks everyone in advance!
//
I posted a topic on the forum asking about how to loop over parameters to find out the maximized conditional welfare: Loop over parameters to find maximized welfare
Following the suggestion there, I wrote my .m file as below to find out my maximized conditional welfare when I tried to loop over more than one parameter.
clear all
tic
dynare FINAL_HDS.mod nostrict noclearall;
pMHy_grid = 0.02: 0.01: 0.05;
pMHq_grid = 0.01: 0.01: 0.02;
%welfare_pos = strmatch('welfare',var_list_,'exact');
welfare_pos = strmatch('welfare',M_.endo_names,'exact');
Vp_pos = strmatch('V_p',M_.endo_names,'exact');
Vi_pos = strmatch('V_i',M_.endo_names,'exact');
Vr_pos = strmatch('V_r',M_.endo_names,'exact');
Ve_pos = strmatch('V_e',M_.endo_names,'exact');
welfare_cell = -inf*ones(length(pMHy_grid) , length(pMHq_grid));
max_welfare_value = -inf;
l_max = 0;
m_max = 0;
for l = 1:length(pMHy_grid)
set_param_value('pMHy', pMHy_grid(l))
for m = 1:length(pMHq_grid)
set_param_value('pMHq', pMHq_grid(m))
info = stoch_simul(var_list_);
if info == 0
welfare_cell(l,m) = oo_.dr.ys(welfare_pos)+0.5*oo_.dr.ghs2(oo_.dr.inv_order_var(welfare_pos));
if welfare_cell(l,m) > max_welfare_value
max_welfare_value = welfare_cell(l,m);
max_Vp = oo_.dr.ys(Vp_pos)+0.5*oo_.dr.ghs2(oo_.dr.inv_order_var(Vp_pos));
max_Vi = oo_.dr.ys(Vi_pos)+0.5*oo_.dr.ghs2(oo_.dr.inv_order_var(Vi_pos));
max_Vr = oo_.dr.ys(Vr_pos)+0.5*oo_.dr.ghs2(oo_.dr.inv_order_var(Vr_pos));
max_Ve = oo_.dr.ys(Ve_pos)+0.5*oo_.dr.ghs2(oo_.dr.inv_order_var(Ve_pos));
l_max = l;
m_max = m;
end
end
end
end
toc
max_set = [pMHy_grid(l_max), pMHq_grid(m_max)];
save welfare_MA.mat;
Where I generate 4 variables such as Vi_pos in addition to welfare_pos in order to capture the corresponding maximized individual welfare.
//
//
The problems I encountered are as follow:
-
welfare_cell might give a totally identical result for every cell in the lxm matrix in some cases!
This sounds incredible but it really happened!
Does it mean that I in fact didn’t reset parameter in every loop? -
After running the .m file, the max_welfare_value and all max_Vi might gave me a positive and incredibly large number such as 20000 or even bigger one.
Is there any wrong of my .m file for looping over parameters?
Or may there something wrong in my model setting e.g. the definition of welfare? Or a unreasonable grid range? -
This .m file really really takes time!
If I try to set a large grid range with a small gap, which means that there is a lot of value for every parameter to loop, it might take about 48 hours or even longer!
Is there any way to speed up the loop??
//
I have no idea to fix my code…and I would be thankful for any help.
Regards
FINAL_HDS.mod (10.8 KB)
FINAL_HDS_steadystate.m (6.5 KB)
welfare_MA.m (1.6 KB)