# Loop over parameters - human capital model

Dear Dynare Users,

As I am a truly beginner, I have a basic problem: loop over parameters. I know that this problem was discussed many times since I found some topics connected with it, but I didn’t find any solution for my problem.
I combined two model: DSGE and human capital model. The model’s most important parameter is named by „x”: x=private investment into human capital/total investment into human capital, 1-x=government investment into human capital/ total investment into human capital. I would like to let that „x” parameter vary.
I’ve already tried the given .m code, but it does not work properly (for example it could not recognise „var_list_”, or I get the following error: „Index exceeds matrix dimensions”). What should I write after stoc_simul (or how should I write my variables after stoch_simul)? Or has my Dynare or my Matlab file another problem?
I would be thankful for any help.
Dora
dsge_humancapital.m (417 Bytes)
dsge_humancapital.mod (1.1 KB)

1. Do not use the same name for the Matlab file and the mod-file. Dynare will overwrite your original Matlab-file
2. See Running a loop on a parameter. You cannot set x before the first run of Dynare.

Dear Prof. Pfeifer,

Many thanks for your help and reply. I am still experiencing further problems. I saw Running a loop on a parameter, and I transformed the given codes in order to solve my problem:

dynare dsge_humancapital nostrict
phi = 0.1:0.1:1;
first_time = 1;
for i=1:length(phi)
if first_time
set_param_value(‘x’,phi(i));
dynare dsge_humancapital nostrict;
first_time = 0;
else
set_param_value(‘x’,phi(i));
perfect_foresight_setup;
perfect_foresight_solver;
if oo_.deterministic_simulation.status ~= 1;
disp([‘Computation fails for x =’ num2str(x)]);
end;
end
end

However, when I run the code, I get the following error:

Attempted to access phi(2); index out of bounds because numel(phi)=1.

Error in ==> proba1 at 10
set_param_value(‘x’,phi(i));

What is the difference between my code/my problem and the problem in Running a loop on a parameter ? What should I change in my code?

Dóra

dsge_humancapital.mod (1.1 KB)
forum loop.m (455 Bytes)

Meantime I found an other/alternative way to solve my problem, but I can not save the steady state results, because I always overwrite the last value in oo_.steady_state. So I tried the following code: results_cell{i}=oo_.steady_state within the loop. But it does not work (I don’t get error, but the results are still overwritten).

mod2.mod (1.4 KB)
forum loop2.m (350 Bytes)

Sorry, but when I run your codes, I get an error that the steady state cannot be computed

It would be possible, that if x=0.5, the steady state results are:
Y=0.511295;
C=0.26954;
IK=0.12748;
IHP=0.00600798;
H=0.200266;
R=1.02041;
rk=0.0924082;
L=0.306103;
K=1.77056;
w=1.13583;
IH=0.012016;
IHG=0.00600798;

Maybe you can try these results in initval…end.

You should use the attached codes. You want to loop over `steady`, so it should be

``````x_vec = 0.1:0.1:1;
first_time = 1;
for i=1:length(x_vec)
if first_time
dynare dsge_humancapital nostrict noclearall;
first_time = 0;
else
set_param_value('x',x_vec(i));
try
catch
end
end
end

``````

You cannot name your run variable phi, because that is the name of a parameter in your model.

dsge_humancapital.m (8.0 KB)
forumloop.m (382 Bytes)

Thank you very much, it’s perfect!

Dóra