Skip to content

Fix economic_impact_analysis() — correct programs, add budget summary, intra-decile, poverty demographics #258

@anth-volk

Description

@anth-volk

Problem

economic_impact_analysis() in both us/analysis.py and uk/analysis.py is broken and untested. The API (policyengine-api-v2-alpha) bypasses it entirely, reimplementing all orchestration in computation_modules.py (818 lines) with workarounds for library bugs.

What's broken today

Issue Detail
Wrong US program names payroll_taxemployee_payroll_tax, state_income_tax not a program
Wrong US entity for ssi Uses person, should be spm_unit
Too many US programs 11 programs; API only uses 6 that work
Missing model_rebuild() ProgrammeStatistics (UK) never rebuilt
calculate_decile_impacts() creates new sims Wasteful when caller already has run simulations
No intra-decile computation API computes this; library skips it
No budget summary No class exists; API has workaround for double-weighting
No poverty by demographics API computes age/gender/race breakdowns; library skips them
StopIteration on missing variables Crashes instead of clear error

Solution

  • Add CountryConfig strategy class with US_CONFIG/UK_CONFIG — eliminates country conditionals
  • Add compute_budget_summary(), compute_decile_impacts(), compute_program_statistics() as individual functions
  • Add PolicyReformAnalysis unified result container
  • Rewrite economic_impact_analysis() for both countries to use individual compute functions
  • Fix model_rebuild() in both __init__.py files
  • Fix error handling in Aggregate/ChangeAggregate (StopIterationValueError)

This is Phase 1 of consolidating logic from policyengine-api-v2-alpha back into policyengine.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions