In [325]:
using NLsolve
using PyPlot
In [326]:
# model parameters
Cv=0.2;
psi1=1.01;
alpha=0.5;
epsilon=1.0;
hbar=1.0;
gamma=.85;
mu=0.9;
z=1;
zlow=.5;
In [327]:
function q(mm::Float64,gg::Float64,n)
(mm*((1-n)./n).^gg).^(1/(1-gg))
end
Out[327]:
In [ ]:
In [ ]:
In [ ]:
In [328]:
function twoperiodeqflexiblehours!(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; x[9]=q2zlow
# Last period FOC:
# n2z:
residuals[1]=alpha*1*z*x[4]*(z*x[3]*x[4])^(alpha-1)-(1/(1+psi1))*x[4]^(1+psi1)-Cv/x[8]
# n2zlow:
residuals[2]=alpha*1*zlow*x[6]*(zlow*x[5]*x[6])^(alpha-1)-(1/(1+psi1))*x[6]^(1+psi1)-Cv/x[9]
# h2z:
residuals[3]=alpha*1*z*(z*x[3]*x[4])^(alpha-1)-x[4]^psi1
# h2zlow:
residuals[4]=alpha*1*zlow*(zlow*x[5]*x[6])^(alpha-1)-x[6]^psi1
# q2z:
residuals[5]=x[8]-(mu*((x[1]-x[3])./x[3]).^gamma).^(1/(1-gamma))
# q2zlow:
residuals[6]=x[9]-(mu*((1-x[1]-x[5])./x[5]).^gamma).^(1/(1-gamma))
# First period FOC:
# n1:
residuals[7]=alpha*epsilon*z*x[2]*(z*x[1]*x[2])^(alpha-1)-(1/(1+psi1))*x[2]^(1+psi1)-Cv/x[7]-(Cv/x[9])*(gamma/(1-gamma))*(x[5]/(1-x[1]-x[5]))+(Cv/x[8])*(gamma/(1-gamma))*(x[3]/(x[1]-x[3]))
# h1:
residuals[8]=alpha*epsilon*z*(z*x[1]*x[2])^(alpha-1)-x[2]^psi1
# q1:
residuals[9]=x[7]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
end
Out[328]:
In [329]:
h1flexible=Array{Float64,1}(0)
h2zflexible=Array{Float64,1}(0)
h2zlowflexible=Array{Float64,1}(0)
n1flexible=Array{Float64,1}(0)
n2zflexible=Array{Float64,1}(0)
n2zlowflexible=Array{Float64,1}(0)
q1flexible=Array{Float64,1}(0)
q2zflexible=Array{Float64,1}(0)
q2zlowflexible=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=.1:.1:1
epsilon=eps;
r=nlsolve(twoperiodeqflexiblehours!, [ .1; 1; .01; 1; .005; 1; .05; .05; .05])
push!(n1flexible,r.zero[1])
push!(h1flexible,r.zero[2])
push!(n2zflexible,r.zero[3])
push!(h2zflexible,r.zero[4])
push!(n2zlowflexible,r.zero[5])
push!(h2zlowflexible,r.zero[6])
push!(q1flexible,r.zero[7])
push!(q2zflexible,r.zero[8])
push!(q2zlowflexible,r.zero[9])
end
In [330]:
hcat(h1flexible,h2zflexible,h2zlowflexible)
Out[330]:
In [331]:
hcat(n1flexible,n2zflexible,n2zlowflexible)
Out[331]:
In [332]:
hcat(q1flexible,q2zflexible,q2zlowflexible)
Out[332]:
In [333]:
function twoperiodeqfixedhours!(x,residuals)
# x[1]=n1; x[2]=n2z; x[3]=n2zlow; x[4]=q1; x[5]=q2z; x[6]=q2zlow
# Last period FOC:
# n2z:
residuals[1]=alpha*1*z*hbarz*(z*x[2]*hbarz)^(alpha-1)-(1/(1+psi1))*hbarz^(1+psi1)-Cv/x[5]
# n2zlow:
residuals[2]=alpha*1*zlow*hbarzlow*(zlow*x[3]*hbarzlow)^(alpha-1)-(1/(1+psi1))*hbarzlow^(1+psi1)-Cv/x[6]
# q2z:
residuals[3]=x[5]-(mu*((x[1]-x[2])./x[2]).^gamma).^(1/(1-gamma))
# q2zlow:
residuals[4]=x[6]-(mu*((1-x[1]-x[3])./x[3]).^gamma).^(1/(1-gamma))
# First period FOC:
# n1:
residuals[5]=alpha*epsilon*z*hbar*(z*x[1]*hbar)^(alpha-1)-(1/(1+psi1))*hbar^(1+psi1)-Cv/x[4]-(Cv/x[6])*(gamma/(1-gamma))*(x[3]/(1-x[1]-x[3]))+(Cv/x[5])*(gamma/(1-gamma))*(x[2]/(x[1]-x[2]))
# q1:
residuals[6]=x[4]-(mu*((1-x[1])./x[1]).^gamma).^(1/(1-gamma))
end
Out[333]:
In [334]:
hbar=h1flexible[end];
hbarz=h2zflexible[end];
hbarzlow=h2zlowflexible[end];
n1fixed=Array{Float64,1}(0)
n2zfixed=Array{Float64,1}(0)
n2zlowfixed=Array{Float64,1}(0)
q1fixed=Array{Float64,1}(0)
q2zfixed=Array{Float64,1}(0)
q2zlowfixed=Array{Float64,1}(0)
# x[1]=n1; x[2]=n2z; x[3]=n2zlow; x[4]=q1; x[5]=q2z; x[6]=q2zlow
for eps=.1:.1:1
epsilon=eps;
r=nlsolve(twoperiodeqfixedhours!, [ .1; .01; .1; .05; .05; .05])
push!(n1fixed,r.zero[1])
push!(n2zfixed,r.zero[2])
push!(n2zlowfixed,r.zero[3])
push!(q1fixed,r.zero[4])
push!(q2zfixed,r.zero[5])
push!(q2zlowfixed,r.zero[6])
end
In [335]:
hcat(n1fixed,n2zfixed,n2zlowfixed)
Out[335]:
In [336]:
hcat(n1flexible,n2zflexible,n2zlowflexible)
Out[336]:
In [337]:
hcat(h1flexible,h2zflexible,h2zlowflexible)
Out[337]:
In [338]:
output2flexible=(z*n2zflexible.*h2zflexible).^alpha+(zlow*n2zlowflexible.*h2zlowflexible).^alpha;
output2fixed=(z*n2zfixed.*hbarz).^alpha+(zlow*n2zlowfixed.*hbarzlow).^alpha;
output1flexible=collect(.1:.1:1).*(z*n1flexible.*h1flexible).^alpha;
output1fixed=collect(.1:.1:1).*(z*n1fixed.*hbar).^alpha;
hcat(output1flexible,output2flexible)
Out[338]:
In [339]:
hcat(output1fixed,output2fixed)
Out[339]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: