Add congressional district breakdowns to state-level simulations #217
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #216
Summary
Adds congressional district-level breakdowns to US state-level simulation results, mirroring the existing UK parliamentary constituency breakdown functionality.
Changes
Core Implementation
policyengine/outputs/macro/single/calculate_single_economy.pycongressional_district_geoid: List[int] | NonetoSingleEconomymodelcalculate_congressional_district_geoid()method toGeneralEconomyTaskpolicyengine/outputs/macro/comparison/calculate_economy_comparison.pyUSCongressionalDistrictImpactmodel (per-district results)USCongressionalDistrictBreakdownWithValuesmodel (list of districts)us_congressional_district_breakdown()function using identical formulas to UK constituenciescongressional_district_impactfield toEconomyComparisongeoid_to_district_name()helper to convert SSDD format to "GA-05" style namesSTATE_FIPS_TO_ABBREVmappingTests
tests/country/test_us_congressional_districts.py(new file)tests/fixtures/simulation.pycreate_mock_single_economy()helpertests/conftest.pyandtests/fixtures/__init__.pyOutput Format
{ "congressional_district_impact": { "districts": [ { "district": "RI-01", "average_household_income_change": 320.73, "relative_household_income_change": 0.001944 }, { "district": "RI-02", "average_household_income_change": 199.13, "relative_household_income_change": 0.001132 } ] } }Verification
Tested with Rhode Island (2 districts) - making CTC fully refundable:
Formula Confirmation
The district-level calculations use identical formulas to UK parliamentary constituencies:
average_household_income_change(reform.sum() - baseline.sum()) / baseline.count()relative_household_income_changereform.sum() / baseline.sum() - 1Test Plan
geoid_to_district_name()us_congressional_district_breakdown()with mocked data