Skip to content

Commit a316cc1

Browse files
committed
test
1 parent c752129 commit a316cc1

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

reweighting/long_term.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
3+
import pandas as pd
4+
import numpy as np
5+
6+
from policyengine_us import Microsimulation
7+
8+
H5_PATH = '/home/baogorek/devl/sep/policyengine-us-data/policyengine_us_data/datasets/cps/long_term/projected_datasets/'
9+
10+
# 2027
11+
sim = Microsimulation(dataset = H5_PATH + "2027.h5")
12+
parameters = sim.tax_benefit_system.parameters
13+
14+
assert sim.default_calculation_period == '2027'
15+
ss_total_b = sim.calculate("social_security").sum() / 1E9
16+
17+
# Trustees SingleYearTRTables_TR2025.xlsx, Tab VI.G9
18+
# Intermediate scenario for row 69, for Intermediate Scenario, 2027, Cost is: $1,715 billion
19+
ss_cost_b = 1_715
20+
assert ss_total_b > ss_cost_b # 2 years of inflation
21+
22+
23+
# Note: not our CPI-W: parameters.gov.bls.cpi.cpi_w("2026-01-05")
24+
#
25+
# CPI from Trustees SingleYearTRTables_TR2025.xlsx, Tab VI.G6
26+
cpi_w_2025 = 100
27+
cpi_w_2027 = 104.95
28+
29+
cpi_w_2025_b = parameters.gov.ssa.uprating("2025-01-01")
30+
cpi_w_2027_b = parameters.gov.ssa.uprating("2027-01-01")
31+
32+
ratio = cpi_w_2027 / cpi_w_2025
33+
ratio_b = cpi_w_2027_b / cpi_w_2025_b
34+
35+
assert round(ss_total_b) == round(ss_cost_b * ratio) # Fails, but close
36+
37+
38+
# 2100
39+
sim = Microsimulation(dataset = H5_PATH + "2100.h5")
40+
parameters = sim.tax_benefit_system.parameters
41+
42+
assert sim.default_calculation_period == '2100'
43+
ss_total_b = sim.calculate("social_security").sum() / 1E9
44+
45+
# Trustees SingleYearTRTables_TR2025.xlsx, Tab VI.G9
46+
# Intermediate scenario for row 143, for Intermediate Scenario, 2100, Cost is: $1,033,686.26 billion
47+
ss_cost_b = 5809
48+
assert ss_total_b > ss_cost_b # many years of inflation
49+
50+
parameters.gov.ssa.uprating# Note: not our CPI-W: parameters.gov.bls.cpi.cpi_w("2026-01-05")
51+
#
52+
# CPI from Trustees SingleYearTRTables_TR2025.xlsx, Tab VI.G6
53+
cpi_w_2025 = 100
54+
cpi_w_2100 = 592.78
55+
56+
cpi_w_2025_b = parameters.gov.ssa.uprating("2025-01-06")
57+
cpi_w_2100_b = parameters.gov.ssa.uprating("2100-01-06")
58+
59+
ratio = cpi_w_2100 / cpi_w_2025
60+
ratio_b = cpi_w_2100_b / cpi_w_2025_b
61+
62+
assert round(ss_total_b) == round(ss_cost_b * ratio) # fails, not close!
63+
64+
# Population count, total
65+
ss_total_pop = 458_325_282
66+
total_pop_est = np.sum(sim.calculate("person_weight", map_to="person").weights)
67+
assert round(ss_total_pop) == round(total_pop_est)
68+
69+
# Population count of 6 year olds
70+
ss_age6_pop = 5_162_540
71+
72+
person_weights = sim.calculate("age", map_to="person").weights
73+
person_ages = sim.calculate("age", map_to="person").values
74+
person_is_6 = person_ages == 6
75+
76+
total_age6_est = np.sum(person_is_6 * person_weights)
77+
assert ss_age6_pop == round(total_age6_est)

0 commit comments

Comments
 (0)