I find a example about changing parameters values to get different irf in the same picture.so i try to use it to a simple rbc model with collateral constraint. but it seems something went wrong .
Subscript indices must either be
real positive integers or logicals.

Error in rbc_loop (line 205)
M_.params( 4 ) =
phy_values(oo_.steady_state(3));

Error in dynare (line 223)
evalin(‘base’,fname) ;
can you please help check the code? thanks for your time rbc_loop.mod (1.9 KB)

hi!
thanks for your reply~
i follow your suggestion and make a m-file for the loop.however, i am really new about coding. it still gets wrong. the aims to do the loop is generating irfs . i don’t know how to save the result to plot irfs. can you help me ? thanks a lot!rbc.mod (990 Bytes) rbc_loop.m (372 Bytes)

The loop should not have a set_param_value in the first execution, because you cannot call that function before Dynare has been run the first time. The mod-file should execute the IRF creation for the first parameter value. Use

phys = [0 2 4];
first_time = 1;
for i=1:length(phys)
if first_time
dynare rbc noclearall;
first_time = 0;
else
set_param_value('phy',phys(i));
info = stoch_simul(var_list_);
if info;
disp(['Computation fails for phy = ' num2str(phy)]);
end
end
irf_cell{i,1}=oo_.irfs;
end

What is also missing is code for generating IRFs in your mod-file. It does not have a stoch_simul and no shocks-block:

var c k i w n mu kesai q lamda r A y kn;
varexo ea ek;
parameters alp bet del phy the x rhoa rhok kesaibar ;
alp=1/3;
bet=0.99;
del=0.02;
phy=0;
the=7.71;
x=1;
rhoa=0.98;
rhok=0.9;
kesaibar=0.05;
model;
kn=k/n;
c*lamda=1;
the*(n^x)=w*lamda;
(1+mu)*w=(1-alp)*A*k(-1)^alp*n^(-alp);
lamda=bet*lamda(+1)*(1+r);
1=q*(1-phy*((i/k)-del));
y=A*k(-1)^alp*n^(1-alp);
k=i-phy/2*(i/k(-1)-del)^2*k(-1)+(1-del)*k(-1);
w*n=kesai*q*k(-1);
ln(A)=rhoa*ln(A(-1))+ea;
ln(kesai)=rhok*ln(kesai(-1))+(1-rhok)*ln(kesaibar)+ek;
q=bet*(lamda(+1)/lamda)*(alp*A(+1)*k^(alp-1)*n(+1)^(1-alp)+q(+1)*((1-del)+mu(+1)*kesai(+1)-phy/2*(i(+1)/k-del)^2+phy*(i(+1)/k-del)*(i(+1)/k)));
y=c+i;
end;
steady_state_model;
kesai=0.05;
mu=(1-alp)/kesai*(1/bet-1+del)-alp;
kn=(alp/(1/bet-1+del-mu*kesai))^(1/(1-alp));
w=kesai*kn;
n=(1/(the*(1+mu))*(1-alp)*kn^alp/(kn^alp-kn*del))^(1/(1+x));
c=n*(kn^alp-del*kn);
k=n*kn;
i=del*k;
y=c+i;
q=1;
A=1;
lamda=1/c;
r=1/bet-1;
end;
steady;
check;
shocks;
var ea=1;
var ek=1;
end;
stoch_simul(order=1,irf=20);