# Problems with simulation in deterministic model

I want to simulate in a deterministic model, but the result is nan or constant numbers, I just simplify the model of Iacoviello(2005) removing housing sector, and I check the model many times, could anyone help me, many thanks!

[code]Var y, ce, cp, i, rd, pi, w, n, rl, x, k, l;
varexo a;
parameters gamma betap betae alpha delta theta xbar ybar cebar cpbar ibar rdbar pibar wbar nbar rlbar lbar kbar abar ikratio wnyratio kyratio iyratio nyratio lyratio;

betap=0.995;
betae=0.97;
alpha=0.5;
delta=0.025;
theta=0.75;
gamma=1.75;

rdbar=1/betap-1;
rlbar=rdbar;
nbar=0.24;
xbar=1.05;
ikratio=delta;
wnyratio=(1-alpha)/xbar;
kyratio=alpha*(delta-1+1/betae)/xbar;
iyratio=kyratioikratio;
nyratio=kyratio^((-alpha)/(1-alpha));
wbar=(1-alpha)/(xbar
nyratio);
cpbar=wbar*(1-nbar)/gamma;
ybar=nbar/nyratio;
lyratio=(1/xbar-1+cpbar/ybar-wnyratio)/rlbar;
lbar=lyratioybar;
ibar=iyratio
ybar;
cebar=ybar-cpbar-ibar;
kbar=ibar/delta;
cebar=ybar-cpbar-ibar;

abar=1;
pibar=1;

Model;
w/cp=gamma/(1-n);
cp(+1)/(1+rd)=betapcp/pi(+1);
w=(1-alpha)y/(xn);
pi(+1)ce(+1)=(1+rl)betaece;
1/ce=betae
(1-delta+alpha
y(+1)/(x(+1)k))/ce(+1);
ce+w
n+(1+rl(-1))l(-1)/pi+i=y/x+l;
k=(1-delta)k(-1)+i;
y=a
(k(-1)^alpha)
(n^(1-alpha));
y=ce+cp+i;
log(pi/pibar)=betaplog(pi(+1)/pibar)+(1-betaptheta)(1-theta)(log(x/xbar))/theta;

rl=rd;
log(rd/rdbar)=0.27*(1.27log(pi(-1)/pibar)+0.13log(y(-1)/ybar))+0.73*log(rd(-1)/rdbar);

end;

Initval;
y=ybar;
ce=cebar;
cp=cpbar;
i=ibar;
rd=rdbar;
pi=pibar;
w=wbar;
n=nbar;
rl=rlbar;
x=xbar;
l=lbar;
k=kbar;

end;

//check;

shocks;
var a;
periods 1 2:1000;
values 2 1;
end;

simul(periods=1000);[/code]

Please use the most recent snapshot. There has been a fix to simul. If you run

you get

[code]SOLVE1: during the resolution of the non-linear system, the evaluation of the following equation(s) resulted in a non-finite number:
12

model diagnostic can’t obtain the steady state[/code]
Moreover, if you use `resid(1);`
you can see that your steady state values do not solve the model equations.

I use dynare 4.3.3 to simulate, I change the code a little as below, and the results show that all variables are constant, I wonder why there is no dynamics, many thanks!

[code]Var y, ce, cp, i, rd, pi, w, n, rl, x, k,l,lamda;
varexo a;
parameters gamma betap betae alpha delta theta xbar ybar cebar cpbar ibar rdbar pibar wbar nbar rlbar lbar kbar abar ikratio wnyratio kyratio iyratio nyratio lyratio cl m lamdabar;

betap=0.99;
betae=0.97;
alpha=0.5;
delta=0.025;
theta=0.75;
gamma=1.75;

rdbar=1/betap-1;
rlbar=1/betae-1;
nbar=0.3;
xbar=1.1;
ikratio=delta;
wnyratio=(1-alpha)/xbar;
kyratio=alpha*(delta-1+1/betae)/xbar;
iyratio=kyratioikratio;
nyratio=kyratio^((-alpha)/(1-alpha));
wbar=(1-alpha)/(xbar
nyratio);
cpbar=wbar*(1-nbar)/gamma;
ybar=nbar/nyratio;
lyratio=(1/xbar-1+cpbar/ybar-wnyratio)/rlbar;
lbar=lyratioybar;
ibar=iyratio
ybar;
cebar=ybar-cpbar-ibar;
kbar=ibar/delta;
cebar=ybar-cpbar-ibar;
abar=1;
pibar=1;
cl=lbar/(rlbar-rdbar);
lamdabar=(betap-betae)/cebar;
m=0.8;

Model;
w/cp=gamma/(1-n);
cp(+1)/(1+rd)=betapcp/pi(+1);
w=(1-alpha)y/(xn);
pi(+1)ce(+1)=(1+rl)betaece+lamdarl;
1/ce=betae
(1-delta+alphay(+1)/(x(+1)k))/ce(+1)+lamdapi(+1)(1-delta)m;
ce+w
n+(1+rl(-1))l(-1)/pi+i=y/x+l;
k=(1-delta)k(-1)+i;
y=a
(k(-1)^alpha)
(n^(1-alpha));
y=ce+cp+i;
log(pi/pibar)=betaplog(pi(+1)/pibar)+(1-betaptheta)(1-theta)(log(x/xbar))/theta;
rl-rd=cll;
(1+rd)=(1+rdbar)^0.25
(1+rd(-1))^0.75*(pi/pibar)^0.5*(y/y(-1))^0.025;
rll=mpi(+1)k(1-delta);
end;

Initval;
y=ybar;
ce=cebar;
cp=cpbar;
i=ibar;
rd=rdbar;
pi=pibar;
w=wbar;
n=nbar;
rl=rlbar;
x=xbar;
l=lbar;
k=kbar;
lamda=lamdabar;
end;

//check;

shocks;
var a;
periods 1 2:1000;
values 2 1;
end;
simul(periods=1000);
[/code]

I said you should use the most recent snapshot dynare.org/download/dynare-unstable, not the most recent stable version.

Many thanks. I have tried the most recent snapshot, and I modified the code as below into a linerized version, so the steady states are zero. I think there is no problem of steady state, but the simulation results show that all variables are constant without dynamics. I wonder what are the possible problems. Is the specification of the model the main reason? Thanks very much for your help!

[code]Var y, ce, cp, i, rd, pi, w, n, rl, x, k,l;
varexo a;
parameters gamma betap betae alpha delta theta xbar ybar cebar cpbar ibar rdbar pibar wbar nbar rlbar lbar kbar abar ikratio wnyratio kyratio iyratio nyratio lyratio cl;

betap=0.99;
betae=0.95;
alpha=0.5;
delta=0.025;
theta=0.75;
gamma=1.75;

rdbar=1/betap-1;
rlbar=1/betae-1;
nbar=0.24;
xbar=1.02;
ikratio=delta;
wnyratio=(1-alpha)/xbar;
kyratio=alpha*(delta-1+1/betae)/xbar;
iyratio=kyratioikratio;
nyratio=kyratio^((-alpha)/(1-alpha));
wbar=(1-alpha)/(xbar
nyratio);
cpbar=wbar*(1-nbar)/gamma;
ybar=nbar/nyratio;
lyratio=(1/xbar-1+cpbar/ybar-wnyratio)/rlbar;
lbar=lyratioybar;
ibar=iyratio
ybar;
cebar=ybar-cpbar-ibar;
kbar=ibar/delta;
cebar=ybar-cpbar-ibar;
abar=1;
pibar=1;
cl=lbar/(rlbar-rdbar);

Model(linear);
cp-w=-nbarn/(1-nbar);
pi(+1)+cp(+1)-cp=rdbar
(log(rd)-log(rdbar))/(1+rdbar);
w+x+n=y;
pi(+1)+ce(+1)-ce=rlbar*(log(rl)-log(rlbar))/(1+rlbar);
ce(+1)-ce=(alphaybar/(xbarkbar))(y(+1)-x(+1)-k)/(1-delta+(alphaybar/(xbarkbar)));
y-x=cebar
xbarce/ybar+wbarnbarxbar(w+n)/ybar+(1+rlbar)lbarxbar*(rlbar*(log(rl(-1))-log(rlbar))/(1+rlbar)+l(-1)-pi)/ybar+ibarxbari/ybar-lbarxbarl/ybar;
k=(1-delta)k(-1)+deltai;
y=a+alphak(-1)+(1-alpha)n;
y=cebar
ce/ybar+cpbar
cp/ybar+ibari/ybar;
pi=betap
pi(+1)+(1-betaptheta)(1-theta)x/theta;
rlbar
(log(rl)-log(rlbar))/(rlbar-rdbar)-rdbar*(log(rd)-log(rdbar))/(rlbar-rdbar)=l;
rdbar*(log(rd)-log(rdbar))/(1+rdbar)=0.75rdbar(log(rd(-1))-log(rdbar))/(1+rdbar)+0.5pi+0.025(y-y(-1));
end;

Initval;
y=0;
ce=0;
cp=0;
i=0;
rd=rdbar;
pi=0;
w=0;
n=0;
rl=rlbar;
x=0;
l=0;
k=0;
end;

//check;

shocks;
var a;
periods 1 2:1000;
values 1 0;
end;

simul(periods=1000);[/code]

Simulations terminate without convergence. Your model does not satisfy the BK-conditions (use check;). This might be the source of trouble.

Many thanks. I have solved this problem, and I want to ask if dynare can handle a stochastic model with ZLB condition, as I input function min( , ) and end with stoch_simul, the results come out, but I saw somewhere else that dynare can only perform analyses of ZLB in a deterministic setup. I wonder if the new version can do it, and what method does it use. Thanks very much!

You cannot do it using stoch_simul as it requires differentiability. You could use the extended path method in Dynare.

Many thanks. I tried the command extended_path as below, but all the simulation results are complex number,and when I use simul in a deterministic setting, the results are also complex number. I don’t know if I can use these results and where is the problem. Thanks for your help.

[code]Var y, ce, cp, i, rd, pi, w, n, rl, x, k,l,rrd;
varexo a;
parameters gamma betap betae alpha delta theta xbar ybar cebar cpbar ibar rdbar pibar wbar nbar rlbar lbar kbar abar ikratio wnyratio kyratio iyratio nyratio lyratio cl rrdbar;

betap=0.99;
betae=0.96;
alpha=0.5;
delta=0.025;
theta=0.75;
gamma=1.75;

rdbar=1/betap-1;
rlbar=1/betae-1;
nbar=0.24;
xbar=1.02;
ikratio=delta;
wnyratio=(1-alpha)/xbar;
kyratio=alpha/(xbar*(delta-1+1/betae));
iyratio=kyratioikratio;
nyratio=kyratio^((-alpha)/(1-alpha));
wbar=(1-alpha)/(xbar
nyratio);
cpbar=wbar*(1-nbar)/gamma;
ybar=nbar/nyratio;
lyratio=(1/xbar-1+cpbar/ybar-wnyratio)/rlbar;
lbar=lyratioybar;
ibar=iyratio
ybar;
cebar=ybar-cpbar-ibar;
kbar=ibar/delta;
cebar=ybar-cpbar-ibar;
abar=1;
pibar=1;
cl=lbar/(rlbar-rdbar);
rrdbar=rdbar;

Model(linear);
cp-w=-nbarn/(1-nbar);
pi(+1)+cp(+1)-cp=rdbar
(log(rd)-log(rdbar))/(1+rdbar);
w+x+n=y;
pi(+1)+ce(+1)-ce=rlbar*(log(rl)-log(rlbar))/(1+rlbar);
ce(+1)-ce=(alphaybar/(xbarkbar))(y(+1)-x(+1)-k)/(1-delta+(alphaybar/(xbarkbar)));
y-x=cebar
xbarce/ybar+wbarnbarxbar(w+n)/ybar+(1+rlbar)lbarxbar*(rlbar*(log(rl(-1))-log(rlbar))/(1+rlbar)+l(-1)-pi)/ybar+ibarxbari/ybar-lbarxbarl/ybar;
k=(1-delta)k(-1)+deltai;
y=a+alphak(-1)+(1-alpha)n;
y=cebar
ce/ybar+cpbar
cp/ybar+ibari/ybar;
pi=betap
pi(+1)+(1-betaptheta)(1-theta)x/theta;
rlbar
(log(rl)-log(rlbar))/(rlbar-rdbar)-rdbar*(log(rd)-log(rdbar))/(rlbar-rdbar)=l;
//rdbar*(log(rd)-log(rdbar))/(1+rdbar)=0.75rdbar(log(rd(-1))-log(rdbar))/(1+rdbar)+0.5pi+0.025(y-y(-1));
rrdbar*(log(rrd)-log(rrdbar))/(1+rrdbar)=0.75rrdbar(log(rrd(-1))-log(rrdbar))/(1+rrdbar)+0.5pi+0.025(y-y(-1));
rd=min(rrd,0.02);
end;

Initval;
y=0;
ce=0;
cp=0;
i=0;
rd=rdbar;
rrd=rrdbar;
pi=0;
w=0;
n=0;
rl=rlbar;
x=0;
l=0;
k=0;
end;

check;

shocks;
var a;
periods 1:1 2:100;
values 1 0;
end;

extended_path(periods=200);[/code]

Please try the most recent snapshot.

Thanks, I tried the most recent snapshot, but it still went wrong.
I want to ask another question, that when I input function min( , ) and end with stoch_simul, the results come out and seem reasonable. I wonder if I can’t use stoch_simul when handle a stochastic model with ZLB condition, what’s the meaning of the results. Many thanks.

When using non-differentiable operators with stoch_simul, the one-sided derivative is taken. Essentially, the operator is ignored and the results are wrong. Thus the error message.