generated from UBICenter/analysis-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_was.py
84 lines (75 loc) · 2.48 KB
/
process_was.py
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
import pandas as pd
import microdf as mdf
RENAMES = {
"R6xshhwgt": "weight",
# Components for estimating land holdings.
"DVLUKValR6_sum": "uk_land",
"DVPropertyR6": "property_values",
"DVFESHARESR6_aggr": "emp_shares_options",
"DVFShUKVR6_aggr": "uk_shares",
"DVIISAVR6_aggr": "investment_isas",
"DVFCollVR6_aggr": "unit_investment_trusts",
"TotpenR6_aggr": "pensions",
"DvvalDBTR6_aggr": "db_pensions",
# Predictors for fusing to FRS.
"dvtotgirR6": "gross_income",
"NumAdultW6": "num_adults",
"NumCh18W6": "num_children",
# Household Gross Annual income from occupational or private pensions
"DVGIPPENR6_AGGR": "pension_income",
"DVGISER6_AGGR": "self_employment_income",
# Household Gross annual income from investments
"DVGIINVR6_aggr": "investment_income",
# Household Total Annual Gross employee income
"DVGIEMPR6_AGGR": "employment_income",
"HBedrmW6": "num_bedrooms",
"GORR6": "region",
"DVPriRntW6": "is_renter", # {1, 2} TODO: Get codebook values.
"CTAmtW6": "council_tax",
# Other columns for reference.
"DVLOSValR6_sum": "non_uk_land",
"HFINWNTR6_Sum": "net_financial_wealth",
"DVLUKDebtR6_sum": "uk_land_debt",
"HFINWR6_Sum": "gross_financial_wealth",
"TotWlthR6": "wealth",
}
was = (
pd.read_csv(
"~/was_round_6_hhold_eul_mar_20.tab",
usecols=RENAMES.keys(),
delimiter="\t",
)
.replace(" ", 0)
.astype(float)
.rename(columns=RENAMES)
)
# Land value held by households and non-profit institutions serving
# households: 3.9tn as of 2019 (ONS).
HH_NP_LAND_VALUE = 3_912_632e6
# Land value held by financial and non-financial corporations.
CORP_LAND_VALUE = 1_600_038e6
# Land value held by government (not used).
GOV_LAND_VALUE = 196_730e6
was["non_db_pensions"] = was.pensions - was.db_pensions
was["corp_wealth"] = was[
[
"non_db_pensions",
"emp_shares_options",
"uk_shares",
"investment_isas",
"unit_investment_trusts",
]
].sum(axis=1)
totals = mdf.weighted_sum(
was, ["uk_land", "property_values", "corp_wealth", "wealth"], "weight"
)
print(totals)
land_prop_share = (HH_NP_LAND_VALUE - totals.uk_land) / totals.property_values
land_corp_share = CORP_LAND_VALUE / totals.corp_wealth
was["est_land"] = (
was.uk_land
+ was.property_values * land_prop_share
+ was.corp_wealth * land_corp_share
)
print(mdf.weighted_sum(was, "est_land", "weight"))
was.to_csv("~/was.csv", index=False)