@@ -53,86 +53,135 @@ of = on(obs) do p
53
53
println (tot)
54
54
end
55
55
56
- settings. included_data_years = [2021 ,2022 , 2023 ] # same as 3 year HBAI
57
- settings. requested_threads = 4
58
- settings. to_y= 2025
59
- settings. to_q= 3
60
- Uprating. load_prices ( settings, true )
61
- settings. num_households, settings. num_people, nhhs2 =
62
- FRSHouseholdGetter. initialise ( settings; reset= true )
63
- res = Runner. do_one_run ( settings, [sys,sys], obs )
64
- results_hhs = res. hh[1 ]
65
- results_hhs. grossing_factor = Weights ( results_hhs. weighted_people)
66
- # results_hhs = results_hhs[results_hhs.bhc_net_income .>= 0,:] # emulate HBAI non-neg only
67
-
68
- jhhs = leftjoin (results_hhs, model_hhs, on= [:hid ,:data_year ], makeunique= true )
69
-
70
- results_hhs. eq_scale_bhc ./= Results. TWO_ADS_EQ_SCALES. oecd_bhc
71
- results_hhs. eq_scale_ahc ./= Results. TWO_ADS_EQ_SCALES. oecd_ahc
72
-
73
- # overwrite raw data with uprated/matched versions
74
- dataset_artifact = get_data_artifact ( settings )
75
- model_hhs = HouseholdFromFrame. read_hh (
76
- joinpath ( dataset_artifact, " households.tab" )) # CSV.File( ds.hhlds ) |> DataFrame
77
- model_people = HouseholdFromFrame. read_pers (
78
- joinpath ( dataset_artifact, " people.tab" ))
79
- model_hhs = model_hhs[ model_hhs. data_year .∈ ( settings. included_data_years, ) , :]
80
- model_people = model_people[ model_people. data_year .∈ ( settings. included_data_years, ) , :]
81
- DataSummariser. overwrite_raw! ( model_hhs, model_people, settings. num_households )
56
+ function onerun ( ;
57
+ weighting_relative_to_ons_weights :: Bool ,
58
+ to_y:: Int ,
59
+ to_q :: Int )
60
+ settings. included_data_years = [2019 ,2021 ,2022 , 2023 ] # same as 3 year HBAI
61
+ settings. requested_threads = 4
62
+ settings. to_y= to_y # match hbai, kinda sorta
63
+ settings. to_q= to_q
64
+ settings. weighting_relative_to_ons_weights = weighting_relative_to_ons_weights
65
+ Uprating. load_prices ( settings, true )
66
+ settings. num_households, settings. num_people, nhhs2 =
67
+ FRSHouseholdGetter. initialise ( settings; reset= true )
68
+ res = Runner. do_one_run ( settings, [sys,sys], obs )
69
+ results_hhs = res. hh[1 ]
70
+ results_hhs. grossing_factor = Weights ( results_hhs. weighted_people)
71
+ results_indiv= res. indiv[1 ]
72
+ results_indiv. grossing_factor = Weights ( results_indiv. weight)
73
+ # results_hhs = results_hhs[results_hhs.bhc_net_income .>= 0,:] # emulate HBAI non-neg only
74
+ results_hhs. eq_scale_bhc ./= Results. TWO_ADS_EQ_SCALES. oecd_bhc
75
+ results_hhs. eq_scale_ahc ./= Results. TWO_ADS_EQ_SCALES. oecd_ahc
76
+ return res, results_hhs, results_indiv
77
+ end
82
78
79
+ function load_model_data ()
80
+ # overwrite raw data with uprated/matched versions
81
+ dataset_artifact = get_data_artifact ( settings )
82
+ model_hhs = HouseholdFromFrame. read_hh (
83
+ joinpath ( dataset_artifact, " households.tab" )) # CSV.File( ds.hhlds ) |> DataFrame
84
+ model_people = HouseholdFromFrame. read_pers (
85
+ joinpath ( dataset_artifact, " people.tab" ))
86
+ model_hhs = model_hhs[ model_hhs. data_year .∈ ( settings. included_data_years, ) , :]
87
+ model_people = model_people[ model_people. data_year .∈ ( settings. included_data_years, ) , :]
88
+ DataSummariser. overwrite_raw! ( model_hhs, model_people, settings. num_households )
89
+ jhhs = leftjoin (results_hhs, model_hhs, on= [:hid ,:data_year ], makeunique= true )
90
+ return jhhs, model_people, model_hhs
91
+ end
83
92
84
- #
93
+ function get_hbai ()
94
+ hbai = CSV. File ( " /mnt/data/hbai/2024-ed/UKDA-5828-tab/main/20224.csv" ; delim= ' ,' , missingstring= [" " ," -9" ," A" ]) |> DataFrame
95
+ rename! (lowercase, hbai)
96
+ hbai = hbai[( .! ismissing .( hbai. s_oe_bhc .+ hbai. s_oe_ahc .+ hbai. eahchh)), :]
97
+ hbai. eq_ahc_net_income = Float64 .( hbai. s_oe_ahc )
98
+ hbai. eq_bhc_net_income = Float64 .(hbai. s_oe_bhc)
99
+ hbai. ahc_net_income = Float64 .(hbai. eahchh)
100
+ # hbai.ahc_net_income_spi = Float64.(hbai.esahchh)
101
+ hbai. total_housing_costs = Float64 .(hbai. ehcost)
102
+ hbai. after_hc_eqscale = Float64 .(hbai. eqoahchh)
103
+ hbai. before_hc_eqscale= Float64 .(hbai. eqobhchh)
104
+ hbai. grossing_factor = Weights ( Float64 .(hbai. gs_indpp))
105
+ hbai. data_year = hbai. year .+ 1993 # 30 -> 2023
106
+ hbai. cpi_av_pub = Float64 .(hbai. ahcpubdef)
107
+ hbai. bhc_net_income = hbai. ahc_net_income + hbai. total_housing_costs
108
+ hbai_heads = hbai[hbai. hrpid .== 1 ,:]
109
+ #=
110
+ HBAI deflators
111
+ AHCDEF Value CPI-based AHC deflator for the average of the survey year
112
+ AHCPUBDEF Value CPI-based AHC deflator for latest (publication) year
113
+ AHCYRDEF Value CPI-based AHC deflator for survey year (average of financial year)
114
+ =#
115
+ hbai_s = hbai[(hbai. gvtregn .== 12 ),:]
116
+ hbai_heads_s = hbai_s[hbai_s. hrpid .== 1 ,:]
117
+ hb23 = hbai[(hbai. data_year.== 2023 ),:]
118
+ hb23_s = hbai_s[(hbai_s. data_year.== 2023 ),:]
119
+ hb23_heads = hb23[hb23. hrpid .== 1 ,:]
120
+ hbai, hbai_s, hb23_s, hb23_heads
121
+ end
85
122
86
123
87
- # eq scales rel to 2 adults
88
- # .. already done now
89
- # hhs.eqscale_bhc = round.( hhs.eqscale_bhc/Results.TWO_ADS_EQ_SCALES.oecd_bhc, digits=2)
90
- # hhs.eqscale_ahc = round.( hhs.eqscale_ahc/Results.TWO_ADS_EQ_SCALES.oecd_ahc, digits=2)
91
- #
92
- # NOTE column label missing 3rd from end in the HBAI files - I added `nothinggks` as a
93
- # label
94
- #
95
- hbai = CSV. File ( " /mnt/data/hbai/2024-ed/UKDA-5828-tab/main/20224.csv" ; delim= ' ,' , missingstring= [" " ," -9" ," A" ]) |> DataFrame
96
- rename! (lowercase, hbai)
97
- hbai = hbai[( .! ismissing .( hbai. s_oe_bhc .+ hbai. s_oe_ahc .+ hbai. eahchh)), :]
98
- hbai. after_hc_net_equivalised = Float64 .( hbai. s_oe_ahc )
99
- hbai. after_hc_net_equivalised = Float64 .(hbai. s_oe_ahc)
100
- hbai. before_hc_net_equivalised = Float64 .(hbai. s_oe_bhc)
101
- hbai. ahc_net_income = Float64 .(hbai. eahchh)
102
- # hbai.ahc_net_income_spi = Float64.(hbai.esahchh)
103
- hbai. total_housing_costs = Float64 .(hbai. ehcost)
104
- hbai. after_hc_eqscale = Float64 .(hbai. eqoahchh)
105
- hbai. before_hc_eqscale= Float64 .(hbai. eqobhchh)
106
- hbai. grossing_factor = Weights ( Float64 .(hbai. gs_indpp))
107
- hbai. data_year = hbai. year .+ 1993 # 30 -> 2023
108
- hbai. cpi_av_pub = Float64 .(hbai. ahcpubdef)
109
- hbai. bhc_net_income = hbai. ahc_net_income + hbai. total_housing_costs
110
- hbai_heads = hbai[hbai. hrpid .== 1 ,:]
111
- #=
112
- HBAI deflators
113
- AHCDEF Value CPI-based AHC deflator for the average of the survey year
114
- AHCPUBDEF Value CPI-based AHC deflator for latest (publication) year
115
- AHCYRDEF Value CPI-based AHC deflator for survey year (average of financial year)
116
- =#
117
-
118
- hbai_s = hbai[(hbai. gvtregn .== 12 ),:]
119
- hbai_heads_s = hbai_s[hbai_s. hrpid .== 1 ,:]
120
- hb23 = hbai[(hbai. data_year.== 2023 ),:]
121
- hb23_s = hbai_s[(hbai_s. data_year.== 2023 ),:]
122
- hb23_heads = hb23[hb23. hrpid .== 1 ,:]
123
-
124
- sbmean_grossed = mean ( results_hhs. bhc_net_income, results_hhs. grossing_factor)
125
- sbmean_ungrossed = mean ( results_hhs. bhc_net_income)
126
- hbai_mean_grossed = mean (hbai_s. bhc_net_income,hbai_s. grossing_factor)
127
- hbai_mean_ungrossed = mean (hbai_s. bhc_net_income )
128
- sbmean_frs_weights = mean ( jhhs. bhc_net_income, Weights ( jhhs. weight_1 ./ 3 ) )
129
-
130
- sbmedian_grossed = median ( results_hhs. bhc_net_income, results_hhs. grossing_factor)
131
- sbmedian_ungrossed = median ( results_hhs. bhc_net_income)
132
- hbai_median_grossed = median (hbai_s. bhc_net_income,hbai_s. grossing_factor)
133
- hbai_median_ungrossed = median (hbai_s. bhc_net_income )
134
- sbmedian_frs_weights = median ( jhhs. bhc_net_income, Weights ( jhhs. weight_1 ./ 3 ) )
124
+ hbai, hbai_s, hb23_s, hb23_heads = get_hbai ()
125
+ jhhs, model_people, model_hhs = load_model_data ()
126
+ n= 16 * 4
127
+ df = DataFrame (
128
+ uprated = fill (" " ,n),
129
+ gross_type_relative_to = fill (" " ,n),
130
+ grossed = fill (" " ,n),
131
+ stat= fill (" " ,n),
132
+ inc_measure = fill (" " ,n),
133
+ scotben_hh = zeros (n), # [sb_h_mean_grossed, sb_h_mean_ungrossed,sb_h_median_grossed, sb_h_median_ungrossed ],
134
+ scotben_indiv = zeros (n), # [sb_i_mean_grossed, sb_i_mean_ungrossed,sb_i_median_grossed, sb_i_median_ungrossed ],
135
+ hbai = zeros (n)) # [hbai_mean_grossed, hbai_mean_ungrossed, hbai_median_grossed, hbai_median_ungrossed])
136
+
137
+ r = 0
138
+
139
+ for uprate in [" current" , " y2024" ]
140
+ to_y, to_q = if uprate== " current"
141
+ 2025 ,3
142
+ else
143
+ 2024 ,2 # kinda sorta
144
+ end
145
+ for weighting_relative_to_ons_weights in [false ,true ]
146
+ results, results_hhs, results_indiv = onerun (
147
+ weighting_relative_to_ons_weights = weighting_relative_to_ons_weights,
148
+ to_y = to_y,
149
+ to_q = to_q)
150
+ for inc in [:bhc_net_income , :ahc_net_income ,:eq_bhc_net_income , :eq_ahc_net_income ]
151
+ for grossed in [true , false ]
152
+ for f in [mean, median]
153
+ global r
154
+ r += 1
155
+ row = df[r,:]
156
+ row. gross_type_relative_to = if weighting_relative_to_ons_weights
157
+ " ONS Weights"
158
+ else
159
+ " Uniform Weights"
160
+ end
161
+ row. uprated = " $uprate ($to_y q$(to_q) )"
162
+ row. grossed = grossed ? " Grossed" : " Ungrossed"
163
+ row. inc_measure = pretty (string (inc))
164
+ row. stat = string (f)
165
+ hhs_weights, indiv_weights, hbai_weights = if grossed
166
+ results_hhs. grossing_factor,
167
+ results_indiv. grossing_factor,
168
+ hbai_s. grossing_factor
169
+ else
170
+ Weights ( results_hhs. num_people ),
171
+ Weights ( ones ( size ( results_indiv)[1 ])),
172
+ Weights ( ones ( size ( hbai_s)[1 ]))
173
+ end
174
+ row. scotben_hh = f (results_hhs[! ,inc], hhs_weights )
175
+ row. scotben_indiv = f ( results_indiv[! ,inc], indiv_weights )
176
+ row. hbai = f ( hbai_s[! ,inc], hbai_weights )
177
+ end # func
178
+ end # gross
179
+ end # incs
180
+ end
181
+ end # uprating
135
182
183
+
184
+ sbmedian_frs_weights = median ( jhhs. bhc_net_income, Weights ( jhhs. weight_1 ./ 3 ) )
136
185
# select summary hbai
137
186
hbai_s[! ,[:sernum ,:grossing_factor ,:ahc_net_income ,:before_hc_eqscale ,:data_year ,:ahcpubdef ,:ahcyrdef ]]
138
187
@@ -149,8 +198,8 @@ summarystats( hbai_s.bhc_net_income )
149
198
#
150
199
151
200
152
- median (hbai. after_hc_net_equivalised ,Weights (hbai. grossing_factor))
153
- median (hb23. after_hc_net_equivalised ,Weights (hb23. grossing_factor))
201
+ median (hbai. eq_ahc_net_income ,Weights (hbai. grossing_factor))
202
+ median (hb23. eq_ahc_net_income ,Weights (hb23. grossing_factor))
154
203
# should match ... these:
155
204
unique (hbai. mdoeahc)
156
205
# should match ... these:
0 commit comments