Page 1 of 1

Saving simulated data in transition periods

PostPosted: Wed May 04, 2016 7:30 pm
by Fidia
Hi,

I want to save simulated data for "Y ,C ,Iit, Iitn ,N ,Kit, Kitn " both in transition periods and steady states . After running the code below I receive error :

Index exceeds matrix dimensions.

Error in dynasave (line 49)
eval([var_list(1,:) '=oo_.endo_simul(ivar(1),:)'';'])

Error in my4 (line 248)
dynasave('my4data',var_list_);

Error in dynare (line 180)
evalin('base',fname) ;



My code is :

var Y C Iit Iitn N Kit Kitn psi A V lam1 lam2 lam3 s3 s2 s1;
varexo ea eit ewit ep;

parameters alpha1 alpha2 beta eta a v b gamma deltait deltaitn rhop sea seit sewit sep;
alpha1 = 0.11;
alpha2=0.13;
deltait = 0.315;
deltaitn=0.056;
rhop=0.95;
beta = 0.99;
b = 0.8;
gamma = 0.3;
a = 0.0362;
v=-0.1732;
eta = 1;
sea=.99;
seit=.66;
sewit=0.33;
sep=.0015;


model;

%wrt C
exp(lam1)= (exp(C)-b*exp(C(-1)))^(-1)-beta*b*(exp(C(+1))-b*exp(C))^(-1);

%wrt N
exp(psi)*exp(N)^(1/eta)= exp(lam1)*exp(A)*exp(Kit(-1))^alpha1*exp(Kitn(-1))^alpha2*(1-alpha1-alpha2)*exp(N)^(-alpha1-alpha2);

%wrt Kit(t+1)
exp(lam2)=beta*(exp(lam1(+1))*exp(A(+1))*alpha1*(exp(Kit)^(alpha1-1))*(exp(Kitn)^alpha2)*exp(N(+1))^(1-alpha1-alpha2)+exp(lam2(+1))*(1-deltait)*((exp(V(+1)))^-1)*(exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1);

%wrt Kitn(t+1)
exp(lam3)=beta*(exp(lam1(+1))*exp(A(+1))*alpha2*(exp(Kitn)^(alpha2-1))*(exp(Kit)^alpha1)*exp(N(+1))^(1-alpha1-alpha2)+exp(lam3(+1))*(1-deltaitn)*(exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1);

%wrt Iit(t)
exp(lam1)= exp(lam2)*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)*(1-gamma/2*exp(Iit)/exp(Iit(-1))*(exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)^2 + gamma*(1-gamma/2*exp(Iit)/exp(Iit(-1))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)*exp(Iit)/exp(Iit(-1))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)+beta*gamma*((exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1))*exp(lam2(+1))*(exp(Iit(+1)))/exp(Iit)^2*(1-gamma/2*exp(Iit(+1))/exp(Iit))*((exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1);

%wrt Iitn(t)
exp(lam1)= exp(lam3)*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)*(1-gamma/2*exp(Iitn)/exp(Iitn(-1))*(exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)^2 + gamma*(1-gamma/2*exp(Iitn)/exp(Iit(-1))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)*exp(Iitn)/exp(Iitn(-1))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)+beta*gamma*((exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1))*exp(lam3(+1))*(exp(Iitn(+1)))/exp(Iitn)^2*(1-gamma/2*exp(Iitn(+1))/exp(Iitn))*((exp(A(+1)+alpha1*V(+1))/(1-alpha1-alpha2))^-1);

% resource contraint
exp(Y)=exp(C)+exp(Iit)+exp(Iitn);

%Accumulation equation
exp(Kit)=(1-gamma/2*(exp(Iit)/exp(Iit(-1)))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1))^2*exp(Iit)*((exp(A+alpha1*V))^-1)+(1-deltait)*exp(Kit(-1))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)*(exp(V))^-1;

%Accumulation equation
exp(Kitn)=(1-gamma/2*(exp(Iitn)/exp(Iitn(-1)))*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1))^2*exp(Iitn)*((exp(A+alpha1*V)/(1-alpha1-alpha2))^-1)+(1-deltaitn)*exp(Kitn(-1))*(exp(A+alpha1*V)/(1-alpha1-alpha2))^-1;

%production function
exp(Y)= exp(A)*exp(Kit(-1))^alpha1*exp(Kitn(-1))^alpha2*exp(N)^(1-alpha1-alpha2);

% (11) Preference shock
psi = rhop*psi(-1) + ep;

%neutral technology
A=a+ea;

%news tech
V=v+eit+s3(-1);

s1=ewit;
s2=s1(-1);
s3=s2(-1);

end;

initval;
Kit=log(2);
Kitn=log(2);
C=log(2);
Y=log(3);
N=log(0.5);
Iit=log(0.25);
Iitn=log(.25);
psi=1;
lam1=0;
lam2=0;
lam3=0;

end;

shocks;
var ea=sea^2;
var eit=seit^2;
var ewit=sewit^2;
var ep=sep^2;
end;

steady;
check;

stoch_simul(order=1,irf=20,nograph);

dynasave (my4data);





Thanks

Re: Saving simulated data in transition periods

PostPosted: Fri May 06, 2016 8:42 am
by jpfeifer
The unstable version says:
dynasave:: The results structure does not contain simulated series. Maybe the periods option has not been set.

To save simulated variables, you need to simulate them first. The is done by setting
Code: Select all
stoch_simul(periods=x)