-
Notifications
You must be signed in to change notification settings - Fork 8
Consolidate economic impact analysis into shared compute functions #263
Copy link
Copy link
Open
Description
Problem
The economic impact analysis logic (decile impacts, budget summary, program statistics, poverty, inequality) is currently duplicated between the US and UK analysis.py files, and depends on country-specific string checks scattered throughout the code. This makes it hard to maintain, test, and extend to new countries.
Solution
Introduce shared, country-agnostic compute functions and a CountryConfig frozen dataclass that encapsulates all country-specific parameters:
CountryConfig(outputs/country_config.py): Frozen dataclass withUS_CONFIGandUK_CONFIGsingletons holding income variables, program definitions, budget variables, poverty variables, and inequality settings.BudgetSummaryItem+compute_budget_summary()(outputs/budget_summary.py): Computes baseline/reform/change totals for budget variables usingAggregate.compute_program_statistics()(outputs/program_statistics.py): Computes per-program statistics (totals, counts, winners, losers) usingProgramStatistics/ProgrammeStatistics.compute_decile_impacts()(outputs/decile_impact.py): Computes decile-by-decile impacts from already-run simulations.PolicyReformAnalysis(outputs/policy_reform_analysis.py): Unified result container assembling all analysis outputs.
Each country's analysis.py calls these shared functions with its config, eliminating duplication.
Additional fixes included
- Fix
DecileImpact.run()barenext()→next(..., None)+ValueError(preventsStopIterationcrash) - Fix
AggregateandChangeAggregatewith same pattern (already done in prior commits) - Move inline imports to module top-level in
us/analysis.py - Improve exception logging in
compute_program_statisticswithexc_info=True - Add
model_rebuild()calls forProgramStatistics,BudgetSummaryItem, andPolicyReformAnalysis - Add 11 new tests covering
CountryConfig,compute_decile_impacts,DecileImpacterror handling, andChangeAggregateerror handling
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels