economy with 2 periods

$t=1,2$ periods: $F(n_t,h_t)=\epsilon_t(z_tn_t^{\beta}h_t^{(1-\beta)})^{\alpha}$, $\alpha,\beta\in(0,1)$

$z_t$: worker skills or human capital.

$z_2=z_1(1-u_1)+\underline{z}u_1$

$\underline{z} < z_1$

$u_1$: unemployment rate at $t=1$

policy, as before: $b(H-h)/H$


In [113]:
using NLsolve
using PyPlot

In [114]:
# model parameters
Cv=.1;
psi0=.025;
psi1=1.05;
alpha=0.4;
bbeta=0.2;
epsilon=1.0;
gamma=.7;
mu=0.7;
z=1.0;
zlow=0.3;
b=.1;
g=0.1;

In [115]:
function q(mm::Float64,gg::Float64,n)
    (mm*((1-n)./n).^gg).^(1/(1-gg))
end


Out[115]:
q (generic function with 1 method)

In [116]:
function ztilda(zed::Float64,zedlow::Float64,urate)
    ztil=(1-urate).*zed+urate.*zedlow
end


Out[116]:
ztilda (generic function with 1 method)

In [ ]:


In [117]:
function twoperiodbaseline!(x,residuals)
    # x[1]=n1; x[2]=h1; x[3]=n2; x[4]=h2; x[5]=q1; x[6]=q2; 
    
    # Last period FOC:
    
    # n2:
    residuals[1]=1*ztilda(z,zlow,1-x[1])*alpha*bbeta*(1/x[3])*(ztilda(z,zlow,1-x[1])*(x[3]^bbeta)*x[4]^(1-bbeta))^(alpha)-(b+psi0*x[4]^(1+psi1))-Cv/x[6]

    # h2:
    residuals[2]=1*ztilda(z,zlow,1-x[1])*alpha*(1-bbeta)*(1/x[4])*(ztilda(z,zlow,1-x[1])*(x[3]^bbeta)*x[4]^(1-bbeta))^(alpha)-(b/x[4]+psi0*x[4]^(psi1))-(-b/x[4]+psi0*psi1*x[4]^(psi1))
    # q2:
    residuals[3]=x[6]-(mu*((1-x[3])./x[3]).^gamma).^(1/(1-gamma))
    
    # First period FOC:
    
    # n1:
    residuals[4]=epsilon*alpha*bbeta*(1/x[1])*((x[1]^bbeta)*x[2]^(1-bbeta))^(alpha)-(b+psi0*x[2]^(1+psi1))-Cv/x[5]
    
    # h1:
    residuals[5]=epsilon*alpha*(1-bbeta)*(1/x[2])*((x[1]^bbeta)*x[2]^(1-bbeta))^(alpha)-(b/x[2]+psi0*x[2]^(psi1))-(-b/x[2]+psi0*psi1*x[2]^(psi1))
    
    # q1:
    residuals[6]=x[5]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
    
end


Out[117]:
twoperiodbaseline! (generic function with 1 method)

In [118]:
n1baseline=Array{Float64,1}(0)
n2baseline=Array{Float64,1}(0)
h1baseline=Array{Float64,1}(0)
h2baseline=Array{Float64,1}(0)
q1baseline=Array{Float64,1}(0)
q2baseline=Array{Float64,1}(0)


for eps=1:-.01:.8
    epsilon=eps;
    r=nlsolve(twoperiodbaseline!, [ .2; .2; .5; .5; .1; .1])
    push!(n1baseline,r.zero[1])
    push!(h1baseline,r.zero[2])
    push!(n2baseline,r.zero[3])
    push!(h2baseline,r.zero[4])
    push!(q1baseline,r.zero[5])
    push!(q2baseline,r.zero[6])

end

In [ ]:


In [119]:
hbar=n1baseline[1];

function twoperiodpolicy!(x,residuals)
    # x[1]=n1; x[2]=h1; x[3]=n2; x[4]=h2; x[5]=q1; x[6]=q2; 
    
    # Last period FOC:
    
    # n2:
    residuals[1]=1*ztilda(z,zlow,1-x[1])*alpha*bbeta*(1/x[3])*(ztilda(z,zlow,1-x[1])*(x[3]^bbeta)*x[4]^(1-bbeta))^(alpha)-(b+psi0*x[4]^(1+psi1))-Cv/x[6]

    # h2:
    residuals[2]=1*ztilda(z,zlow,1-x[1])*alpha*(1-bbeta)*(1/x[4])*(ztilda(z,zlow,1-x[1])*(x[3]^bbeta)*x[4]^(1-bbeta))^(alpha)-(b/x[4]+psi0*x[4]^(psi1))-(-b/x[4]+psi0*psi1*x[4]^(psi1))
    # q2:
    residuals[3]=x[6]-(mu*((1-x[3])./x[3]).^gamma).^(1/(1-gamma))
    
    # First period FOC:
    
    # n1:
    residuals[4]=epsilon*alpha*bbeta*(1/x[1])*((x[1]^bbeta)*x[2]^(1-bbeta))^(alpha)-(b-g*(hbar-x[2])/hbar+psi0*x[2]^(1+psi1))-Cv/x[5]
    
    # h1:
    residuals[5]=epsilon*alpha*(1-bbeta)*(1/x[2])*((x[1]^bbeta)*x[2]^(1-bbeta))^(alpha)-(b/x[2]-g*(hbar-x[2])/(hbar*x[2])+psi0*x[2]^(psi1))-(-b/x[2]+g/x[2]+psi0*psi1*x[2]^(psi1))
    
    # q1:
    residuals[6]=x[5]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
    
end


Out[119]:
twoperiodpolicy! (generic function with 1 method)

In [120]:
n1policy=Array{Float64,1}(0)
n2policy=Array{Float64,1}(0)
h1policy=Array{Float64,1}(0)
h2policy=Array{Float64,1}(0)
q1policy=Array{Float64,1}(0)
q2policy=Array{Float64,1}(0)


for eps=1:-.01:.8
    epsilon=eps;
    r=nlsolve(twoperiodpolicy!, [ .2; .2; .5; .5; .1; .1])
    push!(n1policy,r.zero[1])
    push!(h1policy,r.zero[2])
    push!(n2policy,r.zero[3])
    push!(h2policy,r.zero[4])
    push!(q1policy,r.zero[5])
    push!(q2policy,r.zero[6])

end

In [ ]:


In [121]:
figure("employment1",figsize=(8,6))
delta=1-collect(1:-.01:.8)
fig, ax = subplots()
ax[:plot](delta,n1baseline./n1baseline[1], linewidth=2, color="red", alpha=0.9, label="Period 1")
ax[:plot](delta,n1policy./n1policy[1], linewidth=2, color="blue", alpha=0.9, label="Period 1, policy")

ax[:legend](loc="lower right")
ax[:set_title]("Employment in period 1")
savefig("employment1.png")
close("employment1")



In [122]:
figure("hours1",figsize=(8,6))
fig, ax = subplots()
ax[:plot](delta,h1baseline./h1baseline[1], linewidth=2, color="red", alpha=0.9, label="Period 1")
ax[:plot](delta,h1policy./h1policy[1], linewidth=2, color="blue", alpha=0.9, label="Period 1, policy")

ax[:legend](loc="lower right")
ax[:set_title]("Hours in period 1")
savefig("hours1.png")
close("hours1")



In [123]:
figure("employment2",figsize=(8,6))
fig, ax = subplots()
ax[:plot](delta,n2baseline./n2baseline[1], linewidth=2, color="red", alpha=0.9, label="Period 1")
ax[:plot](delta,n2policy./n2policy[1], linewidth=2, color="blue", alpha=0.9, label="Period 1, policy")

ax[:legend](loc="lower right")
ax[:set_title]("Employment in period 2")
savefig("employment2.png")
close("employment2")



In [ ]:


In [ ]:


In [124]:
figure("hours2",figsize=(8,6))

fig, ax = subplots()
ax[:plot](delta,h2baseline./h2baseline[1], linewidth=2, color="red", alpha=0.9, label="Period 1")
ax[:plot](delta,h2policy./h2policy[1], linewidth=2, color="blue", alpha=0.9, label="Period 1, policy")

ax[:legend](loc="lower right")
ax[:set_title]("Hours in period 2")
savefig("hours2.png")
close("hours2")



In [125]:
output1baseline=(1-delta).*(n1baseline.^bbeta.*h1baseline.^(1-bbeta)).^alpha;
output2baseline=(1).*(ztilda(z,zlow,1-n1baseline).*n2baseline.^bbeta.*h2baseline.^(1-bbeta)).^alpha;

output1policy=(1-delta).*(n1policy.^bbeta.*h1policy.^(1-bbeta)).^alpha;
output2policy=(1).*(ztilda(z,zlow,1-n1policy).*n2policy.^bbeta.*h2policy.^(1-bbeta)).^alpha;

In [126]:
figure("output1",figsize=(8,6))

fig, ax = subplots()
ax[:plot](delta,output1baseline./output1baseline[1], linewidth=2, color="black", alpha=0.9, label="baseline")
ax[:plot](delta,output1policy./output1policy[1], linewidth=2, linestyle="--", color="black", alpha=0.5, label="policy")
ax[:legend](loc="upper right")
ax[:set_title]("Output period 1")
ax[:set_xticks]([0, .1, .2])
xlabel(L"$\Delta_\epsilon$")

savefig("output1.png")
close("output1")



In [127]:
figure("output2",figsize=(8,6))

fig, ax = subplots()
ax[:plot](delta,output2baseline./output2baseline[1], linewidth=2, color="black", alpha=0.9, label="baseline")
ax[:plot](delta,output2policy./output2policy[1], linewidth=2, linestyle="--", color="black", alpha=0.5, label="policy")
ax[:legend](loc="upper right")
ax[:set_title]("Output period 2")
ax[:set_xticks]([0, .1, .2])
xlabel(L"$\Delta_\epsilon$")

savefig("output2.png")
close("output2")