Page 1 of 1
problems with simulation in deterministic model
Posted:
Sun Nov 03, 2013 3:30 pm
by firefoxxp
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: Select all
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=kyratio*ikratio;
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=lyratio*ybar;
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)=betap*cp/pi(+1);
w=(1-alpha)*y/(x*n);
pi(+1)*ce(+1)=(1+rl)*betae*ce;
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)=betap*log(pi(+1)/pibar)+(1-betap*theta)*(1-theta)*(log(x/xbar))/theta;
rl=rd;
log(rd/rdbar)=0.27*(1.27*log(pi(-1)/pibar)+0.13*log(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;
//steady;
//check;
shocks;
var a;
periods 1 2:1000;
values 2 1;
end;
simul(periods=1000);
Re: problems with simulation in deterministic model
Posted:
Mon Nov 04, 2013 9:27 am
by jpfeifer
Please use the most recent snapshot. There has been a fix to simul. If you run
- Code: Select all
model_diagnostics(M_,options_,oo_)
you get
- Code: Select all
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
Moreover, if you use
- Code: Select all
resid(1);
you can see that your steady state values do not solve the model equations.
Re: problems with simulation in deterministic model
Posted:
Mon Nov 04, 2013 3:42 pm
by firefoxxp
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: Select all
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=kyratio*ikratio;
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=lyratio*ybar;
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)=betap*cp/pi(+1);
w=(1-alpha)*y/(x*n);
pi(+1)*ce(+1)=(1+rl)*betae*ce+lamda*rl;
1/ce=betae*(1-delta+alpha*y(+1)/(x(+1)*k))/ce(+1)+lamda*pi(+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)=betap*log(pi(+1)/pibar)+(1-betap*theta)*(1-theta)*(log(x/xbar))/theta;
rl-rd=cl*l;
(1+rd)=(1+rdbar)^0.25*(1+rd(-1))^0.75*(pi/pibar)^0.5*(y/y(-1))^0.025;
rl*l=m*pi(+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;
//steady;
//check;
shocks;
var a;
periods 1 2:1000;
values 2 1;
end;
simul(periods=1000);
Re: problems with simulation in deterministic model
Posted:
Mon Nov 04, 2013 4:15 pm
by jpfeifer
I said you should use the most recent snapshot
http://www.dynare.org/download/dynare-unstable, not the most recent stable version.
Re: problems with simulation in deterministic model
Posted:
Tue Nov 05, 2013 12:38 am
by firefoxxp
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: Select all
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=kyratio*ikratio;
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=lyratio*ybar;
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=-nbar*n/(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=(alpha*ybar/(xbar*kbar))*(y(+1)-x(+1)-k)/(1-delta+(alpha*ybar/(xbar*kbar)));
y-x=cebar*xbar*ce/ybar+wbar*nbar*xbar*(w+n)/ybar+(1+rlbar)*lbar*xbar*(rlbar*(log(rl(-1))-log(rlbar))/(1+rlbar)+l(-1)-pi)/ybar+ibar*xbar*i/ybar-lbar*xbar*l/ybar;
k=(1-delta)*k(-1)+delta*i;
y=a+alpha*k(-1)+(1-alpha)*n;
y=cebar*ce/ybar+cpbar*cp/ybar+ibar*i/ybar;
pi=betap*pi(+1)+(1-betap*theta)*(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.75*rdbar*(log(rd(-1))-log(rdbar))/(1+rdbar)+0.5*pi+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;
//steady;
//check;
shocks;
var a;
periods 1 2:1000;
values 1 0;
end;
simul(periods=1000);
Re: problems with simulation in deterministic model
Posted:
Tue Nov 05, 2013 9:46 am
by jpfeifer
Simulations terminate without convergence. Your model does not satisfy the BK-conditions (use check;). This might be the source of trouble.
Re: problems with simulation in deterministic model
Posted:
Wed Nov 06, 2013 11:51 am
by firefoxxp
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!
Re: problems with simulation in deterministic model
Posted:
Wed Nov 06, 2013 4:24 pm
by jpfeifer
You cannot do it using stoch_simul as it requires differentiability. You could use the extended path method in Dynare.
Re: problems with simulation in deterministic model
Posted:
Thu Nov 07, 2013 3:12 am
by firefoxxp
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: Select all
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=kyratio*ikratio;
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=lyratio*ybar;
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=-nbar*n/(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=(alpha*ybar/(xbar*kbar))*(y(+1)-x(+1)-k)/(1-delta+(alpha*ybar/(xbar*kbar)));
y-x=cebar*xbar*ce/ybar+wbar*nbar*xbar*(w+n)/ybar+(1+rlbar)*lbar*xbar*(rlbar*(log(rl(-1))-log(rlbar))/(1+rlbar)+l(-1)-pi)/ybar+ibar*xbar*i/ybar-lbar*xbar*l/ybar;
k=(1-delta)*k(-1)+delta*i;
y=a+alpha*k(-1)+(1-alpha)*n;
y=cebar*ce/ybar+cpbar*cp/ybar+ibar*i/ybar;
pi=betap*pi(+1)+(1-betap*theta)*(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.75*rdbar*(log(rd(-1))-log(rdbar))/(1+rdbar)+0.5*pi+0.025*(y-y(-1));
rrdbar*(log(rrd)-log(rrdbar))/(1+rrdbar)=0.75*rrdbar*(log(rrd(-1))-log(rrdbar))/(1+rrdbar)+0.5*pi+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;
steady;
check;
shocks;
var a;
periods 1:1 2:100;
values 1 0;
end;
extended_path(periods=200);
Re: problems with simulation in deterministic model
Posted:
Thu Nov 07, 2013 9:33 am
by jpfeifer
Please try the most recent snapshot.
Re: problems with simulation in deterministic model
Posted:
Sun Nov 10, 2013 3:33 pm
by firefoxxp
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.
Re: problems with simulation in deterministic model
Posted:
Sun Nov 10, 2013 4:20 pm
by jpfeifer
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.