
% This model shows the labor suppy shock (B) has a permanent effect on hours but it does not have a permanent effect on labor productivity.
% In addition, technology shock (A) is the only shock that can have a long run effect on productivity.

var c k y B h A y_h i w r log_y log_h log_y_h log_w log_c c_y log_c_y ;
varexo eps_a eps_b;

parameters delta psi alpha beta ;

% Parameter Values 

beta = 0.95; 
psi = 0.33; 
alpha = 0.68; 
delta = 0.07; 


Model; 

y = k(-1)^(1-alpha)*exp(eps_a+eps_b)^(alpha-1)*h^alpha; 
log(A)=log(A(-1)) + eps_a; 
log(B)=log(B(-1)) + eps_b; 
r = (1-alpha)*(y/k(-1))*exp(eps_a+eps_b); 
w= alpha*(y/h); 
c^(-1)= exp(eps_a(+1)+eps_b(+1))^(-1)*beta*c(+1)^(-1)*(1+r(+1)-delta); 
h^(1/psi) = c^(-1)*w; 
y_h = y/h; 
c + k = y + (1-delta)*k(-1)*exp(eps_a+eps_b)^(-1); 
i = y-c;
c_y = c/y; 


// use logarithm to get variables in percentage deviations
log_y=log(y);
log_h=log(h);
log_y_h=log(y_h);
log_w=log(w);
log_c=log(c);
log_c_y=log(c_y);
end; 




steady_state_model;
A=1;
B=1;
r=(1/beta)-(1-delta);
y_k=r/(1-alpha);
k_y=(1-alpha)/r;
i_y=(1/y_k)*delta;
c_y=1-i_y;
h= (alpha*1/c_y)^(psi/(1+psi));
k=((h^alpha)/y_k)^(1/alpha);
y=k^(1-alpha)*h^alpha;
c=c_y*y;
i=i_y*y;
y_h =y/h;
w=alpha*(y_h);
log_y=log(y);
log_h=log(h);
log_y_h=log(y_h);
log_w=log(w);
log_c=log(c);
log_c_y=log(c_y);
end;


shocks;
var eps_a; stderr 0.01;
var eps_b; stderr 0.01;
end;
resid(1);
steady;
check;  


stoch_simul(order=1, periods=1000,drop=960) y h y_h w c;

// Rebuild non-stationary time series by remultiplying with A_{t} and B_{t} 

log_A_0=0; //Initialize Level of Technology at t=0;
log_B_0=0; //Initialize Level of Technology at t=0;
log_A(1,1)=log_A_0 ; //Level of Tech. after shock in period 1
log_B(1,1)=log_B_0; //Level of Tech. after shock in period 1 

// reaccumulate the non-stationary level series  (non-stationary log-level variables)

for ii=1:options_.periods

    log_A(ii+1,1)=log_A(ii,1);
    log_B(ii+1,1)=log_B(ii,1);
    log_y_nonstationary(ii+1,1)=log_y(ii,1)+log_A(ii,1)+log_B(ii,1);                
    log_h_nonstationary(ii+1,1)=log_h(ii,1)+log_B(ii,1);  
    log_y_h_nonstationary(ii+1,1)=log_y_h(ii,1)+log_A(ii,1);              
    log_c_nonstationary(ii+1,1)=log_c(ii,1)+log_A(ii,1)+log_B(ii,1);                
  
end