/
FSYS_agg_generated.jl
226 lines (167 loc) · 13.6 KB
/
FSYS_agg_generated.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# This file has been automatically generated by PreprocessInputs.jl. Any user inputs might be overwritten!
@doc raw"""
Fsys_agg(X, XPrime, Xss, distrSS, m_par, n_par, indexes)
Return deviations from aggregate equilibrium conditions.
`indexes` can be both `IndexStruct` or `IndexStructAggr`; in the latter case
(which is how function is called by [`SGU_estim()`](@ref)), variable-vectors
`X`,`XPrime`, and `Xss` only contain the aggregate variables of the model.
"""
function Fsys_agg(X::AbstractArray, XPrime::AbstractArray, Xss::Array{Float64,1},distrSS::AbstractArray, m_par::ModelParameters,
n_par::NumericalParameters, indexes::Union{IndexStructAggr,IndexStruct})
# The function call with Duals takes
# Reserve space for error terms
F = zeros(eltype(X),size(X))
############################################################################
# I. Read out argument values #
############################################################################
############################################################################
# I.1. Generate code that reads aggregate states/controls
# from steady state deviations. Equations take the form of:
# r = exp.(Xss[indexes.rSS] .+ X[indexes.r])
# rPrime = exp.(Xss[indexes.rSS] .+ XPrime[indexes.r])
############################################################################
# @generate_equations(aggr_names)
@generate_equations()
# Take aggregate model from model file
#------------------------------------------------------------------------------
# THIS FILE CONTAINS THE "AGGREGATE" MODEL EQUATIONS, I.E. EVERYTHING BUT THE
# HOUSEHOLD PLANNING PROBLEM. THE lATTER IS DESCRIBED BY ONE EGM BACKWARD STEP AND
# ONE FORWARD ITERATION OF THE DISTRIBUTION.
#
# AGGREGATE EQUATIONS TAKE THE FORM
# F[EQUATION NUMBER] = lhs - rhs
#
# EQUATION NUMBERS ARE GENEREATED AUTOMATICALLY AND STORED IN THE INDEX STRUCT
# FOR THIS THE "CORRESPONDING" VARIABLE NEEDS TO BE IN THE LIST OF STATES
# OR CONTROLS.
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# AUXILIARY VARIABLES ARE DEFINED FIRST
#------------------------------------------------------------------------------
# Elasticities and steepness from target markups for Phillips Curves
η = μ / (μ - 1.0) # demand elasticity
κ = η * (m_par.κ / m_par.μ) * (m_par.μ - 1.0) # implied steepness of phillips curve
ηw = μw / (μw - 1.0) # demand elasticity wages
κw = ηw * (m_par.κw / m_par.μw) * (m_par.μw - 1.0) # implied steepness of wage phillips curve
# Capital Utilization
MPK_SS = exp(Xss[indexes.rSS]) - 1.0 + m_par.δ_0 # stationary equil. marginal productivity of capital
δ_1 = MPK_SS # normailzation of utilization to 1 in stationary equilibrium
δ_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
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
WagesumPrime = NPrime * wPrime # Total wages in economy t+1
YREACTION = Ygrowth # Policy reaction function to Y
# 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
inc = [τlev .* ((n_par.mesh_y / n_par.H).^tax_prog_scale .*
mcw .*w .* N ./ Ht).^(1.0 - τprog)] # capital liquidation Income (q=1 in steady state)
inc[1][:,:,end] .= τlev .* (n_par.mesh_y[:,:,end] .* profits).^(1.0 - τprog) # profit income net of taxes
incgross = [((n_par.mesh_y / n_par.H).^tax_prog_scale .* mcw .* w .* N ./ Ht)] # capital liquidation Income (q=1 in steady state)
incgross[1][:,:,end] .= (n_par.mesh_y[:,:,end] .* profits) # gross profit income
taxrev = incgross[1] .- inc[1] # tax revenues
incgrossaux = incgross[1]
############################################################################
# Error term calculations (i.e. model starts here) #
############################################################################
#-------- States -----------#
# Error Term on exogeneous States
# Shock processes
F[indexes.Gshock] = log.(GshockPrime) - m_par.ρ_Gshock * log.(Gshock) # primary deficit shock
F[indexes.Tprogshock] = log.(TprogshockPrime) - m_par.ρ_Pshock * log.(Tprogshock) # tax shock
F[indexes.Rshock] = log.(RshockPrime) - m_par.ρ_Rshock * log.(Rshock) # Taylor rule shock
F[indexes.Sshock] = log.(SshockPrime) - m_par.ρ_Sshock * log.(Sshock) # uncertainty shock
# Stochastic states that can be directly moved (no feedback)
F[indexes.A] = log.(APrime) - m_par.ρ_A * log.(A) # (unobserved) Private bond return fed-funds spread (produces goods out of nothing if negative)
F[indexes.Z] = log.(ZPrime) - m_par.ρ_Z * log.(Z) # TFP
F[indexes.ZI] = log.(ZIPrime) - m_par.ρ_ZI * log.(ZI) # Investment-good productivity
F[indexes.μ] = log.(μPrime./m_par.μ) - m_par.ρ_μ * log.(μ./m_par.μ) # Process for markup target
F[indexes.μw] = log.(μwPrime./m_par.μw) - m_par.ρ_μw * log.(μw./m_par.μw) # Process for w-markup target
# Endogeneous States (including Lags)
F[indexes.σ] = log.(σPrime) - (m_par.ρ_s * log.(σ) + (1.0 - m_par.ρ_s) *
m_par.Σ_n * log(Ygrowth) + log(Sshock)) # Idiosyncratic income risk (contemporaneous reaction to business cycle)
F[indexes.Ylag] = log(YlagPrime) - log(Y)
F[indexes.Blag] = log(BlagPrime) - log(B)
F[indexes.Ilag] = log(IlagPrime) - log(I)
F[indexes.wlag] = log(wlagPrime) - log(w)
F[indexes.Tlag] = log(TlagPrime) - log(T)
F[indexes.qlag] = log(qlagPrime) - log(q)
F[indexes.Clag] = log(ClagPrime) - log(C)
F[indexes.av_tax_ratelag] = log(av_tax_ratelagPrime) - log(av_tax_rate)
F[indexes.τproglag] = log(τproglagPrime) - log(τprog)
# Growth rates
F[indexes.Ygrowth] = log(Ygrowth) - log(Y/Ylag)
F[indexes.Tgrowth] = log(Tgrowth) - log(T/Tlag)
F[indexes.Bgrowth] = log(Bgrowth) - log(B/Blag)
F[indexes.Igrowth] = log(Igrowth) - log(I/Ilag)
F[indexes.wgrowth] = log(wgrowth) - log(w/wlag)
F[indexes.Cgrowth] = log(Cgrowth) - log(C/Clag)
# Taylor rule and interest rates
F[indexes.RB] = log(RBPrime) - Xss[indexes.RBSS] -
((1 - m_par.ρ_R) * m_par.θ_π) .* log(π) -
((1 - m_par.ρ_R) * m_par.θ_Y) .* log(YREACTION) -
m_par.ρ_R * (log.(RB) - Xss[indexes.RBSS]) - log(Rshock)
# Tax rule
F[indexes.τprog] = log(τprog) - m_par.ρ_P * log(τproglag) -
(1.0 - m_par.ρ_P) *(Xss[indexes.τprogSS]) -
(1.0 - m_par.ρ_P) * m_par.γ_YP * log(YREACTION) -
(1.0 - m_par.ρ_P) * m_par.γ_BP * (log(B)- Xss[indexes.BSS]) -
log(Tprogshock)
F[indexes.τlev] = av_tax_rate - (distrSS[:]' * taxrev[:]) ./ (distrSS[:]' * incgrossaux[:]) # Union profits are taxed at average tax rate
F[indexes.T] = log(T) - log(distrSS[:]' * taxrev[:] + av_tax_rate * unionprofits)
F[indexes.av_tax_rate] = log(av_tax_rate) - m_par.ρ_τ * log(av_tax_ratelag) -
(1.0 - m_par.ρ_τ) * Xss[indexes.av_tax_rateSS] -
(1.0 - m_par.ρ_τ) * m_par.γ_Yτ * log(YREACTION) -
(1.0 - m_par.ρ_τ) * m_par.γ_Bτ * (log(B) - Xss[indexes.BSS])
# --------- Controls ------------
# Deficit rule
F[indexes.π] = log(BgrowthPrime) + m_par.γ_B * (log(B)- Xss[indexes.BSS]) -
m_par.γ_Y * log(YREACTION) - m_par.γ_π * log(π) - log(Gshock)
F[indexes.G] = log(G) - log(BPrime + T - RB / π * B) # Government Budget Constraint
# Phillips Curve to determine equilibrium markup, output, factor incomes
F[indexes.mc] = (log.(π)- Xss[indexes.πSS]) - κ *(mc - 1 ./ μ ) -
m_par.β * ((log.(πPrime) - Xss[indexes.πSS]) .* YPrime ./ Y)
# Wage Phillips Curve
F[indexes.mcw] = (log.(πw)- Xss[indexes.πwSS]) - (κw * (mcw - 1 ./ μw) +
m_par.β * ((log.(πwPrime) - Xss[indexes.πwSS]) .* WagesumPrime ./ Wagesum))
# worker's wage = mcw * firm's wage
# Wage Dynamics
F[indexes.πw] = log.(w ./ wlag) - log.(πw ./ π) # Definition of real wage inflation
# Capital utilisation
F[indexes.u] = MPKserv - q * (δ_1 + δ_2 * (u - 1.0)) # Optimality condition for utilization
# Prices
F[indexes.r] = log.(r) - log.(1 + MPKserv * u - q * depr ) # rate of return on capital
F[indexes.mcww] = log.(mcww) - log.(mcw * w) # wages that workers receive
F[indexes.w] = log.(w) - log.(wage(Kserv, Z * mc, N, m_par)) # wages that firms pay
F[indexes.unionprofits] = log.(unionprofits) - log.(w.*N .* (1.0 - mcw)) # profits of the monopolistic unions
F[indexes.profits] = log.(profits) - log.(Y .* (1.0 - mc) .+ q .* (KPrime .- (1.0 .- depr) .* K) .- I) # profits of the monopolistic resellers
F[indexes.q] = 1.0 - ZI * q * (1.0 - m_par.ϕ / 2.0 * (Igrowth - 1.0)^2.0 - # price of capital investment adjustment costs
m_par.ϕ * (Igrowth - 1.0) * Igrowth) -
m_par.β * ZIPrime * qPrime * m_par.ϕ * (IgrowthPrime - 1.0) * (IgrowthPrime)^2.0
# Asset market premia
F[indexes.LP] = log.(LP) - (log((q + r - 1.0)/qlag) - log(RB / π)) # Ex-post liquidity premium
F[indexes.LPXA] = log.(LPXA) - (log((qPrime + rPrime - 1.0)/q) - log(RBPrime / πPrime)) # ex-ante liquidity premium
# Aggregate Quantities
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.C] = log.(Y .- G .- I .- BD*m_par.Rbar .+ (A .- 1.0) .* RB .* B ./ π) .- log(C) # Resource constraint
# Error Term on prices/aggregate summary vars (logarithmic, controls), here difference to SS value averages
F[indexes.BY] = log.(BY) - log.(B/Y) # Bond to Output ratio
F[indexes.TY] = log.(TY) - log.(T/Y) # Tax to output ratio
# Distribution summary statistics used in this file (using the steady state distrubtion in case).
# Lines here generate a unit derivative (distributional summaries do not change with other aggregate vars).
F[indexes.K] = log.(K) - Xss[indexes.KSS] # Capital market clearing
F[indexes.BD] = log.(BD) - Xss[indexes.BDSS] # IOUs
F[indexes.B] = log.(B) - Xss[indexes.BSS] # Bond market clearing
# Add distributional summary stats that do change with other aggregate controls/prices and with estimated parameters
distr_y = sum(distrSS, dims=(1,2))
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)))
F[indexes.Ht] = log.(Ht) - log.(Htact)
# other dsitributional statistics not used in other aggregate equations and not changing with parameters,
# but potentially with other aggregate variables are NOT included here. They are found in FSYS.
# @include "../3_Model/input_aggregate_model.jl"
return F
end