-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduce_exhibits.jl
148 lines (121 loc) · 4.83 KB
/
produce_exhibits.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
## Load packages
using Plots
using RauhValladaresEsteban2023
using StatsBase
using Tectonic
## Run data work in Stata
run(`stata -q do stata/main.do`)
# Compile LaTeX tables
for i ∈ 1:2
tectonic() do bin
run(`$bin tables/hearnings_$i.tex`)
end
end
## Define race groups and load parameters for each group
groups = ["Black", "White"]
p = Dict(r => generateparameters(r) for r ∈ groups)
## Model simulated wages (using data labour supply) vs. data
# Load NLSY microdata
nlsymd = Dict(r => loadnlsydata(r) for r ∈ groups)
nlsymd["All"] = loadnlsydata()
# Simulate wages microdata based on NLSY labour supply
simwmd = simulatewages(nlsymd["All"], p[rand(groups)])
# Plot and export
plotmvsd(:wage,
statsfbyage(mean, simwmd),
statsfbyage(mean, nlsymd["All"]),
de = statsfbyage(sterror, nlsymd["All"]),
haxis = p[rand(groups)].agerange,
spttls = ["Ability/AFQT Decile $i" for i ∈ 1:length(nlsymd["All"])],
lyt = (2, 5),
sz = (2000, 1000)
)
png("figures/mvsd_wage_dataLS")
## Model simulated hours employment, and wage vs. data
# Simulate model microdata for both groups
benchmarkmd = Dict(r => solvemodel(p[r]) for r ∈ groups)
# Iterate over ability groupings
for (ig, groupings) ∈ enumerate([[1, 2, 3, 4, 5:10], [5, 6, 7, 8, 9, 10]])
for r ∈ groups
# Create vector of subplot titles
spttls = ["$r Ability Decile $i" for i ∈ groupings]
# Plot hours and employment rates
for s ∈ [:hours, :employed, :wage]
plotmvsd(s,
groupingmean(groupings, statsfbyage(mean, benchmarkmd[r]), p[r]),
statsfbyage(mean, catmicrodata(groupings, nlsymd[r])),
de = statsfbyage(sterror, catmicrodata(groupings, nlsymd[r])),
haxis = p[r].agerange,
spttls = spttls,
ylms = (0, (s == :hours ? 1 : Inf)),
lyt = (1, length(groupings))
)
png("figures/mvsd_$(string(s))_$(r)_$(ig)")
end
end
end
## Counterfactual experiements
# Initialise dictionary to store counterfactual experiments
experiments = Dict{String, Any}()
# Utility of staying at home (κ₀ , κ₁, κ₂, and η)
experiments["Utility home"] = solvemodel(modifyparameters(p["Black"],
κ₀ = p["White"].κ₀, κ₁ = p["White"].κ₁, κ₂ = p["White"].κ₂, η = p["White"].η
))
# Utility employed (ψ and γ)
experiments["Utility employed"] = solvemodel(modifyparameters(p["Black"],
ψ = p["White"].ψ, γ = p["White"].γ
))
# Utilities home & employed
experiments["Utilities home & employed"] = solvemodel(modifyparameters(p["Black"],
κ₀ = p["White"].κ₀, κ₁ = p["White"].κ₁, κ₂ = p["White"].κ₂, η = p["White"].η,
ψ = p["White"].ψ, γ = p["White"].γ
))
# Constant labor supply
experiments["Constant labor supply"] = solveconstantls(p["Black"], p["White"])
## Counterfactual gaps
# Define function to compute gaps with respect to benchmark Whites
fgap(cf, cfps = p["Black"].popshare, w = benchmarkmd["White"], wps = p["White"].popshare) =
meangap(cf, cfps, w, wps)
# Initialise dictionary to store counterfactual experiments
gaps = Dict{String, AggregateData}()
# Iterate over saved experiments
for (nexp, mdexp) ∈ experiments
gaps[nexp] = fgap(mdexp)
end
# Benchmark
gaps["Benchmark"] = fgap(benchmarkmd["Black"])
# Distribution (a, h₁)
gaps["Distribution"] = fgap(benchmarkmd["Black"], p["White"].popshare)
# Distribution & utility home
gaps["Distribution & utility home"] = fgap(experiments["Utility home"], p["White"].popshare)
# Distribution & utility employed
gaps["Distribution & utility employed"] = fgap(experiments["Utility employed"], p["White"].popshare)
# Print LaTeX table with gaps
latexcf(gaps)
# Compile LaTeX
tectonic() do bin
run(`$bin tables/counterfactuals.tex`)
end
## Model racial gaps over the life cycle vs. data
# Aggregate NLSY data to group age means
nlsyad = Dict(r => statsfbyage(mean, catmicrodata(nlsymd[r])) for r ∈ groups)
# Aggregate model data to group age means
benchmarkad =
Dict(r => groupingmean(statsfbyage(mean, benchmarkmd[r]), p[r].popshare) for r ∈ groups)
# Aggregate distribution counterfactual age means
distributionad = groupingmean(statsfbyage(mean, benchmarkmd["Black"]), p["White"].popshare)
# Plot wage and employment rates
for s ∈ [:wage, :employed]
plotmvsd(
gap.(getfield(benchmarkad["Black"], s), getfield(benchmarkad["White"],s)),
gap.(getfield(nlsyad["Black"], s), getfield(nlsyad["White"], s)),
haxis = p[rand(groups)].agerange,
mlbl = "Benchmark"
)
plot!(p[rand(groups)].agerange,
gap.(getfield(distributionad, s), getfield(benchmarkad["White"], s)),
label = "Equal initial conditions", linecolor = :gray, linewidth = 3, linestyle = :dash,
ylims = (0, NaN)
)
png("figures/mvsdcf_$(string(s))")
end