In [131]:
using NLsolve
using PyPlot
In [132]:
# model parameters
Cv=0.2;
psi1=1.01;
alpha=0.5;
epsilon=1.0;
hbar=1.0;
gamma=.85;
mu=0.9;
z=1.0;
zlow=.5;
In [133]:
function q(mm::Float64,gg::Float64,n)
(mm*((1-n)./n).^gg).^(1/(1-gg))
end
Out[133]:
In [145]:
function ztilda(zed::Float64,zedlow::Float64,urate)
ztil=(1-urate).*zed+urate.*zedlow
end
Out[145]:
In [135]:
function twoperiodeqflexible!(x,residuals)
# x[1]=n1; x[2]=h1; x[3]=n2z; x[4]=h2z; x[5]=n2zlow; x[6]=h2zlow; x[7]=q1; x[8]=q2z;
# Last period FOC:
# n2:
residuals[1]=alpha*1*ztilda(z,zlow,1-x[1])*x[4]*(z*x[3]*x[4])^(alpha-1)-(1/(1+psi1))*x[4]^(1+psi1)-Cv/x[6]
# h2:
residuals[2]=alpha*1*ztilda(z,zlow,1-x[1])*(z*x[3]*x[4])^(alpha-1)-x[4]^psi1
# q2:
residuals[3]=x[6]-(mu*((1-x[3])./x[3]).^gamma).^(1/(1-gamma))
# First period FOC:
# n1:
residuals[4]=alpha*epsilon*z*x[2]*(z*x[1]*x[2])^(alpha-1)-(1/(1+psi1))*x[2]^(1+psi1)-Cv/x[5]
# h1:
residuals[5]=alpha*epsilon*z*(z*x[1]*x[2])^(alpha-1)-x[2]^psi1
# q1:
residuals[6]=x[5]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
end
Out[135]:
In [136]:
h1flexible=Array{Float64,1}(0)
h2flexible=Array{Float64,1}(0)
n1flexible=Array{Float64,1}(0)
n2flexible=Array{Float64,1}(0)
q1flexible=Array{Float64,1}(0)
q2flexible=Array{Float64,1}(0)
# x[1]=n1; x[2]=h1; x[3]=n2z; x[4]=h2z; x[5]=n2zlow; x[6]=h2zlow; x[7]=q1; x[8]=q2z; x[9]=q2zlow
for eps=.5:.01:1
epsilon=eps;
r=nlsolve(twoperiodeqflexible!, [ .1; 1; .01; 1; .05; .05;])
push!(n1flexible,r.zero[1])
push!(h1flexible,r.zero[2])
push!(n2flexible,r.zero[3])
push!(h2flexible,r.zero[4])
push!(q1flexible,r.zero[5])
push!(q2flexible,r.zero[6])
end
In [137]:
hcat(n1flexible,n2flexible)
Out[137]:
In [138]:
hcat(h1flexible,h2flexible)
Out[138]:
In [139]:
function twoperiodeqfixed!(x,residuals)
# x[1]=n1; x[2]=n2; x[3]=q1; x[4]=q2;
# Last period FOC:
# n2:
residuals[1]=alpha*1*ztilda(z,zlow,1-x[1])*hbar2*(z*x[2]*hbar2)^(alpha-1)-(1/(1+psi1))*hbar2^(1+psi1)-Cv/x[4]
# q2:
residuals[2]=x[4]-(mu*((1-x[2])./x[2]).^gamma).^(1/(1-gamma))
# First period FOC:
# n1:
residuals[3]=alpha*epsilon*z*hbar*(z*x[1]*hbar)^(alpha-1)-(1/(1+psi1))*hbar^(1+psi1)-Cv/x[3]
# q1:
residuals[4]=x[3]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
end
Out[139]:
In [ ]:
In [140]:
n1fixed=Array{Float64,1}(0)
n2fixed=Array{Float64,1}(0)
q1fixed=Array{Float64,1}(0)
q2fixed=Array{Float64,1}(0)
# x[1]=n1; x[2]=n2; x[3]=q1; x[4]=q2;
hbar=h1flexible[end]
hbar2=h2flexible[end]
for eps=.5:.01:1
epsilon=eps;
r=nlsolve(twoperiodeqfixed!, [ .1; .1; .05; .05;])
push!(n1fixed,r.zero[1])
push!(n2fixed,r.zero[2])
push!(q1fixed,r.zero[3])
push!(q2fixed,r.zero[4])
end
In [141]:
hcat(n1fixed,n2fixed)
Out[141]:
In [142]:
hcat(n1flexible,n2flexible)
Out[142]:
In [143]:
fig, ax = subplots()
ax[:plot](.5:.01:1,n1flexible./n1flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 1, flexible hours")
ax[:plot](.5:.01:1,n1fixed./n1fixed[end], linewidth=2, color="red", alpha=0.9, label="Period 1, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Employment in period 1")
Out[143]:
In [144]:
fig, ax = subplots()
ax[:plot](.5:.01:1,n2flexible./n2flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 2, flexible hours")
ax[:plot](.5:.01:1,n2fixed./n2fixed[end], linewidth=2, color="red", alpha=0.9, label="Period 2, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Employment in period 2")
Out[144]:
In [150]:
output2flexible=(ztilda(z,zlow,1-n1flexible).*n2flexible.*h2flexible).^alpha;
output1flexible=collect(.5:.01:1).*(z*n1flexible.*h1flexible).^alpha;
output2fixed=(ztilda(z,zlow,1-n1fixed).*n2fixed.*hbar2).^alpha;
output1fixed=collect(.5:.01:1).*(z*n1fixed.*hbar).^alpha;
In [151]:
fig, ax = subplots()
ax[:plot](.5:.01:1,output1flexible./output1flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 1, flexible hours")
ax[:plot](.5:.01:1,output1fixed./output1fixed[end], linewidth=2, color="red", alpha=0.9, label="Period 1, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Output in period 1")
Out[151]:
In [152]:
fig, ax = subplots()
ax[:plot](.5:.01:1,output2flexible./output2flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 2, flexible hours")
ax[:plot](.5:.01:1,output2fixed./output2fixed[end], linewidth=2, color="red", alpha=0.9, label="Period 2, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Output in period 2")
Out[152]:
In [156]:
fig, ax = subplots()
ax[:plot](.5:.01:1,h2flexible./h2flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 2, flexible hours")
ax[:plot](.5:.01:1,ones(length(.5:.01:1)), linewidth=2, color="red", alpha=0.9, label="Period 2, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Hours in period 2")
Out[156]:
In [155]:
fig, ax = subplots()
ax[:plot](.5:.01:1,h1flexible./h1flexible[end], linewidth=2, color="blue", alpha=0.9, label="Period 1, flexible hours")
ax[:plot](.5:.01:1,ones(length(.5:.01:1)), linewidth=2, color="red", alpha=0.9, label="Period 1, fixed hours")
ax[:legend](loc="lower right")
ax[:set_title]("Hours in period 1")
Out[155]:
In [ ]: