-
Notifications
You must be signed in to change notification settings - Fork 8
/
1_Income.jl
324 lines (293 loc) · 11.6 KB
/
1_Income.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
################################################################################
########################### INCOME DISTRIBUTION ################################
################################################################################
using Distributions, StatsBase, Statistics
################################################################################
function incomeDistribution(user::AbstractString)
println("Import Guvenen's income distribution")
path="C:/Users/"*user*"/Dropbox/QMUL/PhD/Code/Guvenen FORTRAN Code/"
yit = readdlm(path*"LaborReal.dat")
println("\tMedian income in period 40 is $(median(yit[:, end]))")
# Retirement benefits
ybar_i = mean(yit, dims=2)
linreg2(x, y) = hcat(fill!(similar(x), 1), x) \ y
(γ_0, γ_1) = linreg2(yit[:, 40], ybar_i)
function get_pension(y::T, k_0::T, k_1::T, avgy::T) where T <: AbstractFloat
ytilde = (k_0 + k_1*y)/avgy
rratio = 0.0
if ytilde < 0.3
rratio = 0.9*ytilde
elseif ytilde <= 2.0
rratio = 0.27 + 0.32*(ytilde - 0.3)
elseif ytilde <= 4.1
rratio = 0.814 + 0.15*(ytilde - 2.0)
else
rratio = 1.129
end
return rratio*avgy
end
pension = Array(Float64, 100000)
ybar = mean(yit)
for i = 1:100000
pension[i] = get_pension(yit[i, 40], γ_0, γ_1, ybar)
end
return yit, pension
end
################################################################################
function incomeDistribution(agents::T, bs::T, tW::T; profile="none") where T <: Integer
# Life cycle profiles
if profile == "psid"
# PSID log real labour income, 1968-1996 (median income at 40: $29703)
g_t = [8.36 + 0.07*t - 0.15*t^2/100 for t = 1:tW]
μₐ = 1.17; μᵦ = 0.009
var_α = 0.03; var_β = 0.00031; corr_αβ = -0.3
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.013; var_ɛ = 0.03
ρ = 0.853
elseif profile == "psid_68_86"
# PSID log real labour income, 1968-1996 (median income at 40: $29703)
g_t = [8.36 + 0.07*t - 0.15*t^2/100 for t = 1:tW]
μₐ = 1.17; μᵦ = 0.009
var_α = 0.11; var_β = 0.00001; corr_αβ = -0.42
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.013; var_ɛ = 0.043
ρ = 0.885
elseif profile == "psid_87_13"
# PSID log real labour income, 1968-1996 (median income at 40: $29703)
g_t = [8.36 + 0.07*t - 0.15*t^2/100 for t = 1:tW]
μₐ = 1.17; μᵦ = 0.009
var_α = 0.097; var_β = 0.00025; corr_αβ = -0.31
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.032; var_ɛ = 0.085
ρ = 0.854
elseif profile == "bhps_grosslab"
# BHPS log real gross labour income, 1992-2008 (median £25k mean £28.7k)
g_t = [9.65 + 0.024*t + 0.019*t^2/100 - 0.014*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.036; var_β = 0.00032; corr_αβ = -0.51
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.106; var_ɛ = 0.08
ρ = 0.719
elseif profile == "bhps_netlab"
# BHPS log real net labour income, 1992-2008 (median £19k, mean £21.6k)
g_t = [9.41 + 0.019*t + 0.029*t^2/100 - 0.014*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.032; var_β = 0.00019; corr_αβ = -0.59
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.073; var_ɛ = 0.07
ρ = 0.808
elseif profile == "bhps_netinc"
# BHPS log real net houseold income, 1992-2008 (median £22.6k, mean £26k)
g_t = [9.49 + 0.026*t - 0.008*t^2/100 - 0.007*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.052; var_β = 0.00011; corr_αβ = -0.42
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.027; var_ɛ = 0.056
ρ = 0.857
elseif profile == "bhps_netincdef"
# BHP log real net household income, deflated & equivalized, 1992-2008
# (median £16.9k, mean £19.4k)
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.1; var_β = 0.0; corr_αβ = -1.
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.039; var_ɛ = 0.042
ρ = 0.812
elseif profile == "baseline"
# PSID Profile
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "low_beta"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00015; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "high_beta"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.0007; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "low_alpha"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.01; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "high_alpha"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.1; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "low_cov"
# PSID Profile
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.8
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "high_cov"
# PSID Profile
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009
var_α = 0.03; var_β = 0.00038; corr_αβ = 0.
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "low_eta"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.01; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "high_eta"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.1; var_ɛ = 0.05;
ρ = 0.82
elseif profile == "low_eps"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.02;
ρ = 0.82
elseif profile == "high_eps"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.13;
ρ = 0.82
elseif profile == "low_rho"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.71
elseif profile == "high_rho"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.03; var_β = 0.00038; corr_αβ = -0.2
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.03; var_ɛ = 0.05;
ρ = 0.91
elseif profile == "RIP"
g_t = [9.64 - 0.002*t + 0.027*t^2/100 - 0.004*t^3/1000 for t = 1:tW]
μₐ = .0; μᵦ = 0.009;
var_α = 0.0; var_β = 0.0; corr_αβ = 0.
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.05; var_ɛ = 0.03;
ρ = 0.95
elseif profile == "guvenen"
g_t = zeros(tW)
μₐ = 2.0; μᵦ = 0.009;
var_α = 0.005; var_β = 0.00038; corr_αβ = -0.23
cov_αβ = corr_αβ*sqrt(var_β*var_α);
var_η = 0.029; var_ɛ = 0.047;
ρ = 0.82
else
g_t = zeros(tW)
μₐ = 1.17; μᵦ = 0.009
var_α = 0.03; var_β = 0.00031; corr_αβ = -0.3
cov_αβ = corr_αβ*sqrt(var_β*var_α)
var_η = 0.013; var_ɛ = 0.03
ρ = 0.853
profile = "no"
end
println("Draw an income distribution using the $profile profile")
println("Parameters of the income process are:")
println("ρ=$ρ, var_α=$var_α, var_β=$var_β, var_η=$var_η, var_ɛ=$var_ɛ")
# Draw some alphas and betas
if (var_α>0.) && (var_β > 0.)
min_β = max(-0.05, μᵦ-2.5*sqrt(var_β))
ab = MvNormal([μₐ; μᵦ], [var_α cov_αβ; cov_αβ var_β])
draw1 = rand(ab, bs)'
draw2 = rand(ab, bs)'
for i = 1:bs
draw1[i,2] < min_β ? draw1[i,2] = min_β + abs(draw1[i,2]-min_β)/50.0 : 0
draw2[i,2] < min_β ? draw2[i,2] = min_β + abs(draw2[i,2]-min_β)/50.0 : 0
end
α = (draw1[:,1] + draw2[:,1])/2.
α = reshape(repeat(α,1,100)', agents*bs)
β_u = reshape(repeat(draw1[:, 2],1,100)', agents*bs)
β_k = reshape(repeat(draw2[:, 2],1,100)', agents*bs)
β = (1-fpu)*β_k + fpu*β_u
else
α = μₐ*ones(agents*bs)
β = μᵦ*ones(agents*bs)
β_k = μᵦ*ones(agents*bs)
end
# Draw the income distribution:
yit = zeros(bs*agents, tW); z = similar(yit)
z[:, 1] = sqrt(var_η/(1-ρ^2))*randn(agents*bs)
for t = 1:tW, i = 1:bs*agents
yit[i, t] = exp(g_t[t] + α[i] + β[i]*t + z[i, t] + sqrt(var_ɛ)*randn()) +0.4
t < tW ? z[i, t+1] = ρ*z[i, t] + sqrt(var_η)*randn() : 0
end
# Median income in last period for calculation of retirement benefitss
println("\tMedian and mean income in period 40 are "*
"$(round(median(yit[:, end]); digits = 2)) and "*
"$(round(mean(yit[:, end]); digits = 2))")
ybar_i = mean(yit, dims = 2)
linreg2(x, y) = hcat(fill!(similar(x), 1), x) \ y
(γ_0, γ_1) = linreg2(yit[:, 40], ybar_i)
function get_pension(y::T, k_0::T, k_1::T, avgy::T) where T<:AbstractFloat
ytilde = (k_0 + k_1*y)/avgy
rratio = 0.0
if ytilde < 0.3
rratio = 0.9*ytilde
elseif ytilde <= 2.0
rratio = 0.27 + 0.32*(ytilde - 0.3)
elseif ytilde <= 4.1
rratio = 0.814 + 0.15*(ytilde - 2.0)
else
rratio = 1.129
end
return rratio*avgy
end
pension = Array{Float64}(undef, size(yit,1))
ybar = mean(yit)
for i = 1:size(yit, 1)
pension[i] = get_pension(yit[i, 40], γ_0, γ_1, ybar)
end
return yit, pension, α, β, β_k, g_t, ρ, var_α, var_β, cov_αβ, var_η, var_ɛ
end
################################################################################
function incomeDistribution(α::T, β::T, var_η_RIP::T, var_ɛ_RIP::T,
zpoints_RIP::Int64, epspoints::Int64, tW::Int64) where T<:AbstractFloat
println("1. Drawing an RIP-consistent income distribution")
println("\tσ²(η) = $var_η_RIP, σ²(ɛ) = $var_ɛ_RIP")
zdisc = [-(1/2)*(zpoints_RIP-1)*sqrt(var_η_RIP)+(i-1)*sqrt(var_η_RIP)
for i = 1:zpoints_RIP]
epsdisc = [-(1/2)*(epspoints-1)*sqrt(var_ɛ_RIP)+(i-1)*sqrt(var_ɛ_RIP)
for i = 1:epspoints]
yit = Array(Float64, (zpoints_RIP, epspoints, tW))
for t = 1:tW, z = 1:zpoints_RIP, ɛ = 1:epspoints
if t < 2
yit[:, ɛ, t] = exp(α + β*t + 0.8*zdisc[z] + 0.6*epsdisc[ɛ])
elseif t < 3
yit[:, ɛ, t] = exp(α + β*t + zdisc[z] + epsdisc[ɛ])
elseif t < 5
yit[:, ɛ, t] = exp(α + β*t + zdisc[z] + epsdisc[ɛ])
else
yit[:, ɛ, t] = exp(α + β*t + zdisc[z] + epsdisc[ɛ])
end
end
return yit
end