Skip to content

Commit

Permalink
Merge pull request #4 from BASEforHANK/dev_Christian
Browse files Browse the repository at this point in the history
Dev christian
  • Loading branch information
BenjaminBorn authored Mar 1, 2024
2 parents 87bb116 + 4196835 commit 9792d82
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 155 deletions.
2 changes: 1 addition & 1 deletion src/Model/IncomesETC/fcn_incomes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function incomes!(
unionprofits,
av_tax_rate,
)
tax_prog_scale = (m_par.γ + m_par.τ_prog) / ((m_par.γ + τprog))
tax_prog_scale = (m_par.γ + m_par.τprog ) / ((m_par.γ + τprog))
labor_inc = mcw .* w .* N ./ Ht .* (n_par.mesh_y / H) .^ tax_prog_scale
net_labor_inc = τlev .* labor_inc .^ (1.0 - τprog)
net_u_profits = unionprofits .* (1.0 .- av_tax_rate) .* n_par.HW
Expand Down
99 changes: 0 additions & 99 deletions src/Model/IncomesETC/fcn_util_etc.jl

This file was deleted.

136 changes: 136 additions & 0 deletions src/Model/IncomesETC/fcn_utils_product_prices_etc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
##----------------------------------------------------------------------------
## Basic Functions: Utility, marginal utility and its inverse,
## Return on capital, Wages, Employment, Output, etc
##---------------------------------------------------------------------------

## Utility functions and margnal utility
function util(c::AbstractArray, m_par)
if m_par.ξ == 1.0
util = log.(c)
elseif m_par.ξ == 2.0
util = 1.0 - 1.0 ./ c
elseif m_par.ξ == 4.0
util = (1.0 - 1.0 ./ (c .* c .* c)) ./ 3.0
else
util = (c .^ (1.0 .- m_par.ξ) .- 1.0) ./ (1.0 .- m_par.ξ)
end
return util
end

function mutil(c::AbstractArray, m_par)
if m_par.ξ == 1.0
mutil = 1.0 ./ c
elseif m_par.ξ == 2.0
mutil = 1.0 ./ (c .^ 2)
elseif m_par.ξ == 4.0
mutil = 1.0 ./ ((c .^ 2) .^ 2)
else
mutil = c .^ (-m_par.ξ)
end
return mutil
end

function mutil!(mu::AbstractArray, c::AbstractArray, m_par)
if m_par.ξ == 1.0
mu .= 1.0 ./ c
elseif m_par.ξ == 2.0
mu .= 1.0 ./ (c .^ 2)
elseif m_par.ξ == 4.0
mu .= 1.0 ./ ((c .^ 2) .^ 2)
else
mu .= c .^ (-m_par.ξ)
end
return mu
end

function invmutil(mu, m_par)
if m_par.ξ == 1.0
c = 1.0 ./ mu
elseif m_par.ξ == 2.0
c = 1.0 ./ (sqrt.(mu))
elseif m_par.ξ == 4.0
c = 1.0 ./ (sqrt.(sqrt.(mu)))
else
c = 1.0 ./ mu .^ (1.0 ./ m_par.ξ)
end
return c
end

function invmutil!(c, mu, m_par)
if m_par.ξ == 1.0
c .= 1.0 ./ mu
elseif m_par.ξ == 2.0
c .= 1.0 ./ (sqrt.(mu))
elseif m_par.ξ == 4.0
c .= 1.0 ./ (sqrt.(sqrt.(mu)))
else
c .= 1.0 ./ mu .^ (1.0 ./ m_par.ξ)
end
return c
end

## Production functions and factor incomes
# Incomes (K:capital, Z: TFP): Interest rate = MPK.-δ, Wage = MPL, profits = Y-wL-(r+\delta)*K

output(z::Vector, m_par) = z[2] .* (z[1] .^ (m_par.α)) .* (z[3] .^ (1 - m_par.α)) # Z .* K .^ (m_par.α) .* N .^ (1 - m_par.α)
output(K::Number, Z::Number, N::Number, m_par) = output([K; Z; N], m_par)

# Factor incomes as marginal products
interest(K::Number, Z::Number, N::Number, m_par) = Z .* m_par.α .* (K ./ N) .^ (m_par.α - 1.0) .- m_par.δ_0
wage(K::Number, Z::Number, N::Number, m_par) = Z .* (1 - m_par.α) .* (K ./ N) .^ m_par.α

# Alternatively, using ForwardDiff instead of analytical derivatives.
# Yields small differences in the results due to numerical precision differences.
# interest(K::Number, Z::Number, N::Number, m_par) = ForwardDiff.gradient(z -> output(z, m_par), [K; Z; N])[1] - m_par.δ_0 # derivative instead of gradient leads to perturbation confusion
# wage(K::Number, Z::Number, N::Number, m_par) = ForwardDiff.gradient(z -> output(z, m_par), [K; Z; N])[3] # derivative instead of gradient leads to perturbation confusion

## Labor supply given wages (paid to households), resulting from leisure preferences
labor_supply(w, τlev, τprog, Ht, m_par) = ((1.0 .- τprog ) .* τlev .* w^(1.0 .- τprog)).^
(1.0 ./ (m_par.γ .+ τprog)) .* Ht

labor_supply(w, m_par) = labor_supply(w, m_par.τlev, m_par.τprog, 1.0, m_par) # steady state version

## Asset markets
# price of tradable stock in steady state
qΠSS_fnc(Y::Number, RB, m_par) =
m_par.ωΠ .* (1.0 .- 1.0 ./ m_par.μ) .* Y ./
(RB ./ m_par.π .- 1 .+ m_par.ιΠ) + 1.0

# steady state payout to entrepreneurs
profitsSS_fnc(Y::Number, RB, m_par) =
(1.0 - m_par.ωΠ) .* (1.0 .- 1.0 ./ m_par.μ) .* Y .+
m_par.ιΠ .* (qΠSS_fnc(Y, RB, m_par) .- 1.0)

# Valuation of liquid wealth (stock)
value_liquid(B, qΠ, qΠlag) = 1.0 .+ (qΠ .- qΠlag) ./ B

##--------------------------------------------------------------------------------------
## Functions only used in the steady state calculations
##--------------------------------------------------------------------------------------
# Employment given labor supply = labor demand at a given capital stock and productivity
# This is used in the steady state calculations.
employment(K::Number, Z::Number, m_par) =
(
Z .* (1.0 - m_par.α) .*
(m_par.τlev .* (1.0 - m_par.τprog )) .^ (1.0 / (1.0 - m_par.τprog )) .*
K .^ (m_par.α)
) .^
((1.0 - m_par.τprog ) ./ (m_par.γ + m_par.τprog + (m_par.α) .* (1 - m_par.τprog )))

# Capital intensity (K/N) given interest rate and productivity,
# used for starting guesses in the steady state calculations
# Optimal capital intensity under Cobb Douglas
capital_intensity(r, m_par) = ((r + m_par.δ_0) ./ m_par.α .* m_par.μ)^(1.0 ./ (m_par.α .- 1))

# Capital used in production (in complete markets) at a given interest rate, taking labor supply into account
CompMarketsCapital(r, m_par) = capital_intensity(r, m_par) .*
labor_supply(
wage(
capital_intensity(r, m_par), 1.0 ./ m_par.μ, 1.0, m_par
) ./ m_par.μw # wage markup needs to be taken into account
, m_par)





4 changes: 2 additions & 2 deletions src/Model/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ julia> priors = collect(metaflatten(m_par, prior))

# Further steady-state parameters
ψ::T = 0.1 | "psi" | L"\psi" | _ | false # steady-state bond to capital ratio
τ_lev::T = 0.8225 | "tau_lev" | L"\tau^L" | _ | false # steady-state income tax rate level
τ_prog::T = 0.1022 | "tau_pro" | L"\tau^P" | _ | false # steady-state income tax rate progressivity
τlev::T = 0.8225 | "tau_lev" | L"\tau^L" | _ | false # steady-state income tax rate level
τprog ::T = 0.1022 | "tau_pro" | L"\tau^P" | _ | false # steady-state income tax rate progressivity

R::T = 1.01 | "R" | L"R" | _ | false # steady state rate of return capital (unused)
K::T = 40.0 | "K" | L"K" | _ | false # steady state quantity of capital (unused)
Expand Down
20 changes: 10 additions & 10 deletions src/Model/input_aggregate_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MPKSS = exp(XSS[indexes.rSS]) - 1.0 + m_par.δ_0 # stationary equil. margi
δ_2 = δ_1 .* m_par.δ_s # express second utilization coefficient in relative terms
# Auxiliary variables
Kserv = K * u # Effective capital
MPKserv = mc .* Z .* m_par.α .* (Kserv ./ N) .^ (m_par.α - 1.0) # marginal product of Capital
MPKserv = interest(Kserv, mc.*Z, N, m_par) .+ m_par.δ_0 # mc .* Z .* m_par.α .* (Kserv ./ N) .^ (m_par.α - 1.0) # marginal product of Capital
depr = m_par.δ_0 + δ_1 * (u - 1.0) + δ_2 / 2.0 * (u - 1.0)^2.0 # depreciation

Wagesum = N * w # Total wages in economy t
Expand All @@ -41,7 +41,7 @@ YREACTION = Ygrowth # Policy reaction function
distr_y = sum(distrSS, dims = (1, 2))

# tax progressivity variabels used to calculate e.g. total taxes
tax_prog_scale = (m_par.γ + m_par.τ_prog) / ((m_par.γ + τprog)) # scaling of labor disutility including tax progressivity
tax_prog_scale = (m_par.γ + m_par.τprog ) / ((m_par.γ + τprog)) # scaling of labor disutility including tax progressivity
incgross = ((n_par.grid_y ./ n_par.H) .^ tax_prog_scale .* mcw .* w .* N ./ Ht) # capital liquidation Income (q=1 in steady state)
incgross[end] = (n_par.grid_y[end] .* profits) # gross profit income
inc = τlev .* (incgross .^ (1.0 .- τprog)) # capital liquidation Income (q=1 in steady state)
Expand All @@ -52,7 +52,7 @@ IncAux = dot(distr_y, incgross)

Htact = dot(
distr_y[1:end-1],
(n_par.grid_y[1:end-1] / n_par.H) .^ ((m_par.γ + m_par.τ_prog) / (m_par.γ + τprog)),
(n_par.grid_y[1:end-1] / n_par.H) .^ ((m_par.γ + m_par.τprog ) / (m_par.γ + τprog)),
)
############################################################################
# Error term calculations (i.e. model starts here) #
Expand Down Expand Up @@ -189,13 +189,13 @@ F[indexes.LPXA] = log.(LPXA) - (log((qPrime + rPrime - 1.0) / q) - log(RBPrime /
F[indexes.I] =
KPrime .- K .* (1.0 .- depr) .-
ZI .* I .* (1.0 .- m_par.ϕ ./ 2.0 .* (Igrowth - 1.0) .^ 2.0) # Capital accumulation equation
F[indexes.N] =
log.(N) -
log.(
((1.0 - τprog) * τlev * (mcw .* w) .^ (1.0 - τprog)) .^ (1.0 / (m_par.γ + τprog)) .*
Ht
) # labor supply
F[indexes.Y] = log.(Y) - log.(Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α) # production function

F[indexes.N] = log.(N) - log.(labor_supply(w.*mcw, τlev, τprog, Ht, m_par))
# log.(
# ((1.0 - τprog) * τlev * (mcw .* w) .^ (1.0 - τprog)) .^ (1.0 / (m_par.γ + τprog)) .*
# Ht
# ) # labor supply
F[indexes.Y] = log.(Y) - log.(output(Kserv, Z, N, m_par)) #log.(Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α) # Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α # production function
F[indexes.C] = log.(Y .- G .- I .- BD * m_par.Rbar .+ (A .- 1.0) .* RL .* B ./ π) .- log(C) # Resource constraint

# Error Term on prices/aggregate summary vars (logarithmic, controls), here difference to SS value averages
Expand Down
4 changes: 2 additions & 2 deletions src/Model/input_aggregate_steady_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ZSS = 1.0
ZISS = 1.0
μSS = m_par.μ
μwSS = m_par.μw
τprogSS = m_par.τ_prog
τlevSS = m_par.τ_lev
τprogSS = m_par.τprog
τlevSS = m_par.τlev

σSS = 1.0
τprog_obsSS = 1.0
Expand Down
Binary file modified src/Output/Saves/linearresults.jld2
Binary file not shown.
Binary file modified src/Output/Saves/reduction.jld2
Binary file not shown.
Binary file modified src/Output/Saves/steadystate.jld2
Binary file not shown.
20 changes: 10 additions & 10 deletions src/Preprocessor/generated_fcns/FSYS_agg_generated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ MPKSS = exp(XSS[indexes.rSS]) - 1.0 + m_par.δ_0 # stationary equil. margi
δ_2 = δ_1 .* m_par.δ_s # express second utilization coefficient in relative terms
# Auxiliary variables
Kserv = K * u # Effective capital
MPKserv = mc .* Z .* m_par.α .* (Kserv ./ N) .^ (m_par.α - 1.0) # marginal product of Capital
MPKserv = interest(Kserv, mc.*Z, N, m_par) .+ m_par.δ_0 # mc .* Z .* m_par.α .* (Kserv ./ N) .^ (m_par.α - 1.0) # marginal product of Capital
depr = m_par.δ_0 + δ_1 * (u - 1.0) + δ_2 / 2.0 * (u - 1.0)^2.0 # depreciation

Wagesum = N * w # Total wages in economy t
Expand All @@ -84,7 +84,7 @@ YREACTION = Ygrowth # Policy reaction function
distr_y = sum(distrSS, dims = (1, 2))

# tax progressivity variabels used to calculate e.g. total taxes
tax_prog_scale = (m_par.γ + m_par.τ_prog) / ((m_par.γ + τprog)) # scaling of labor disutility including tax progressivity
tax_prog_scale = (m_par.γ + m_par.τprog ) / ((m_par.γ + τprog)) # scaling of labor disutility including tax progressivity
incgross = ((n_par.grid_y ./ n_par.H) .^ tax_prog_scale .* mcw .* w .* N ./ Ht) # capital liquidation Income (q=1 in steady state)
incgross[end] = (n_par.grid_y[end] .* profits) # gross profit income
inc = τlev .* (incgross .^ (1.0 .- τprog)) # capital liquidation Income (q=1 in steady state)
Expand All @@ -95,7 +95,7 @@ IncAux = dot(distr_y, incgross)

Htact = dot(
distr_y[1:end-1],
(n_par.grid_y[1:end-1] / n_par.H) .^ ((m_par.γ + m_par.τ_prog) / (m_par.γ + τprog)),
(n_par.grid_y[1:end-1] / n_par.H) .^ ((m_par.γ + m_par.τprog ) / (m_par.γ + τprog)),
)
############################################################################
# Error term calculations (i.e. model starts here) #
Expand Down Expand Up @@ -232,13 +232,13 @@ F[indexes.LPXA] = log.(LPXA) - (log((qPrime + rPrime - 1.0) / q) - log(RBPrime /
F[indexes.I] =
KPrime .- K .* (1.0 .- depr) .-
ZI .* I .* (1.0 .- m_par.ϕ ./ 2.0 .* (Igrowth - 1.0) .^ 2.0) # Capital accumulation equation
F[indexes.N] =
log.(N) -
log.(
((1.0 - τprog) * τlev * (mcw .* w) .^ (1.0 - τprog)) .^ (1.0 / (m_par.γ + τprog)) .*
Ht
) # labor supply
F[indexes.Y] = log.(Y) - log.(Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α) # production function

F[indexes.N] = log.(N) - log.(labor_supply(w.*mcw, τlev, τprog, Ht, m_par))
# log.(
# ((1.0 - τprog) * τlev * (mcw .* w) .^ (1.0 - τprog)) .^ (1.0 / (m_par.γ + τprog)) .*
# Ht
# ) # labor supply
F[indexes.Y] = log.(Y) - log.(output(Kserv, Z, N, m_par)) #log.(Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α) # Z .* N .^ (1.0 .- m_par.α) .* Kserv .^ m_par.α # production function
F[indexes.C] = log.(Y .- G .- I .- BD * m_par.Rbar .+ (A .- 1.0) .* RL .* B ./ π) .- log(C) # Resource constraint

# Error Term on prices/aggregate summary vars (logarithmic, controls), here difference to SS value averages
Expand Down
Loading

0 comments on commit 9792d82

Please sign in to comment.