Repository navigation
Add a UK budgetary impact from the government's accounts - #780
juaristi22 wants to merge 2 commits into
Conversation
pe.uk.calculate_budgetary_impact and pe.uk.BudgetaryImpact give the change in gov_tax, which counts employer National Insurance, less the change in gov_spending. configure_budgetary_impact_variables adds both accounts to the simulations' outputs before they run. The UK economic_impact_analysis calls neither, because it also runs on stored outputs without those columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vahid-ahmadi
left a comment
There was a problem hiding this comment.
The function itself is right: total is the change in gov_tax less the change in gov_spending, which is the change in gov_balance. Keeping it out of economic_impact_analysis, so that stored outputs without the columns don't break, is the right call. The real-data figures match the ones in sim-api#1171.
One gap, the same one I raised on PolicyEngine/policyengine-sim-api#1171: policyengine-uk's gov_spending doesn't include the gov.contrib.benefit_uprating term that household_benefits adds (general_benefits × uprating.all + non_sp_benefits × uprating.non_sp). I checked on policyengine-uk main (e6909e8) with one household and benefit_uprating.all = 0.05:
household_benefits: +£633.80gov_spendingandgov_balance: no change
So calculate_budgetary_impact would report a benefit uprating reform as costing nothing. The fix belongs in pe-uk (add the term to gov_spending). Once it's there, a test here would keep the two accounts honest: run a benefit_uprating reform on one household and assert spending moves with household_benefits.
Smaller point: the docstring could say that gov_tax and gov_spending also bring in the Lifetime ISA charge and bonus and the reform-only other_public_spending_budget_change. Those are the only other differences from the household totals, and it would save the next reader working that out.
Review drafted with AI assistance and checked against the code at 452c5548bcfd6196bc00b8d7d76eb24c32ad416a.
anth-volk
left a comment
There was a problem hiding this comment.
A few small points, with the code ones inline.
- The description claims a test that doesn't exist yet. It says the simulation API "names its stored UK budget rows after them and tests that the two agree". PolicyEngine/policyengine-sim-api#1171 still has its own copy of the names and doesn't import
BUDGETARY_IMPACT_VARIABLES, so that test only arrives once #1171 is updated to use this PR. Worth wording it as still to come. - Merge timing with #1171. A .py release sends a
policyengine-releasedispatch, and the update bots move both API v1 and the simulation service onto it within hours. That will probably happen before #1171 merges, since #1171 also waits for PolicyEngine/policyengine-api#4379 to deploy. UK reports calculated between that update and #1171's deploy are stored with the old total under the new versions, so they're reused until the next policyengine-uk or .py release. Merging #1171 straight after this release avoids that.
Drafted with Claude Code and checked against 452c5548bcfd6196bc00b8d7d76eb24c32ad416a.
| return float(agg.result) | ||
|
|
||
|
|
||
| def configure_budgetary_impact_variables( |
There was a problem hiding this comment.
This takes exactly a baseline and a reform. One of PolicyEngine/policyengine-sim-api#1171's three call sites, the UK baseline precompute step (_prepare_uk_baseline_outputs in stage12_cache/levels_uk.py), has only a baseline simulation. Taking *simulations: Simulation, as #1171's own configure_budget_total_variables does, would let it call this function instead of keeping its own copy.
| return self.tax_revenue - self.spending | ||
|
|
||
|
|
||
| def _sum_change( |
There was a problem hiding this comment.
This is the same function as _sum_change in us/analysis.py. Could both import one shared helper?
| "uk_latest", | ||
| "calculate_household", | ||
| "economic_impact_analysis", | ||
| "calculate_budgetary_impact", |
There was a problem hiding this comment.
calculate_budgetary_impact is exported from pe.uk, but configure_budgetary_impact_variables isn't, so callers (and the docs example) import it from the module path. They're always used together, so export it too?
policyengine-uk's gov_spending leaves out what the benefit uprating reforms pay, which household_benefits counts, so totalling it would make such a reform look free. The UK headline's spending is now household_benefits plus the two terms gov_spending adds to it, the Lifetime ISA bonus and other_public_spending_budget_change. Its tax stays gov_tax. Decision: fix the headline here, on the policyengine-uk and policyengine.py the service already runs, so that the app is right as soon as possible. Fixing gov_spending first would need a UK data build certified on the fixed policyengine-uk, and moving the rule into policyengine.py first would need a release of it. This deploys before the API moves to .py 6.20.4 (PolicyEngine/policyengine-api#4377), so UK reports compute again when they are next opened. Follow-ups: policyengine-uk counts the uprating in gov_spending; the rule moves into policyengine.py (PolicyEngine/policyengine.py#780) and this service calls it and moves the pin; then both read gov_spending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… points Spending is totalled from household_benefits and the two terms policyengine-uk's gov_spending adds to it, instead of read from gov_spending, which leaves out what the benefit uprating reforms pay. The docstring lists how the accounts differ from the household totals. configure_budgetary_impact_variables takes any number of simulations and is exported from pe.uk. sum_change is one helper for the US and UK functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Done in
It also closes Vahid's gap: spending is totalled from |
|
Both done in |
|
Correction to the merge-timing point in my review: it's out of date. It said to merge PolicyEngine/policyengine-sim-api#1171 straight after this PR's release, but #1171 no longer depends on this PR. The order is the one in this PR's description now: merge this after #1171 has deployed, and move the simulation service onto these functions in a later PR. The full order for the related PRs is on #1171: PolicyEngine/policyengine-sim-api#1171 (comment) Drafted with Claude Code. |
anth-volk
left a comment
There was a problem hiding this comment.
Approving at ef2fb987. The review's code points are in: configure_budgetary_impact_variables takes any number of simulations and is exported from pe.uk, and sum_change is one helper for the US and UK functions. Spending now uses the same terms as PolicyEngine/policyengine-sim-api#1171, so benefit uprating counts.
As the description says, merge after PolicyEngine/policyengine-sim-api#1171 has deployed.
Checked against ef2fb987e0b690fbc748daa33a91859140555ac1.
Fixes #779
Adds a UK budgetary impact from the government's accounts, like the US one:
BudgetaryImpact(tax_revenue,spendingand the computedtotal) andcalculate_budgetary_impactinuk/analysis.py, exported frompe.uk.totalis the change ingov_taxless the change in the government's spending.SPENDING_TERMS:household_benefitsplus the two terms policyengine-uk'sgov_spendingadds to it, the Lifetime ISA bonus andother_public_spending_budget_change. It isn't read fromgov_spending, which leaves out what the benefit uprating reforms (gov.contrib.benefit_uprating) pay andhousehold_benefitscounts, so such a reform would look free. Once policyengine-uk counts them ingov_spendingand a UK data build is certified on it, it can be read instead.configure_budgetary_impact_variables(*simulations), also exported frompe.uk, adds what isn't a default UK output (gov_tax, the public spending term and, on people, the Lifetime ISA bonus) to any number of simulations before they run. A precomputed baseline has no reform to go with it.sum_changeinoutputs/change_aggregate.pyis the helper the US and UK functions share.BUDGETARY_IMPACT_VARIABLESnames the two accounts.Why
The UK headline in the app is the change in
household_taxless the change inhousehold_benefits, computed in the simulation service.household_taxleaves out employer NI. Under policyengine-uk's default incidence an employer NI change moves gross pay, so the headline counts the income tax and employee NI on the pay change and not the employer NI behind it: a cut in the employer rate from 15% to 14% showed as a £3.9bn saving.PolicyEngine/policyengine-sim-api#1171 fixes the app's headline now, in the simulation service, with the same terms, and doesn't use these functions. Moving the rule here, so that it lives in one place, is a follow-up there: the service will call these functions, name its stored UK budget rows from
BUDGETARY_IMPACT_VARIABLES, and move its .py pin to the release that has them.Merge after policyengine-sim-api#1171 has deployed
A .py release starts the bots' updates of the simulation service and of the API. If they reach the API before PolicyEngine/policyengine-sim-api#1171 has deployed, UK reports computed in between keep the old total under the new versions until the next release that reaches the API.
What doesn't change
The UK
economic_impact_analysisdoesn't call the new functions. The simulation service's Stage 12 runs it on stored outputs, andChangeAggregateraises when a column isn't there (a test shows it does, naming the variable). If the analysis readgov_tax, the simulation service's bot update to this release would fail UK Stage 12 reports until its output plans add the columns. As it is, the release changes nothing until the follow-up calls it.On real data
National weighted totals on this branch, with policyengine-uk 2.179.2 and the certified build
uk-frs-calibration-attempt-20261122T100732Z-b891aa69, in 2026:household_taxlesshousehold_benefits, as the app has it today, gives +£3.833bn; employer NI falls £9.704bn.gov_taxlessgov_spendingwould give £0.Tests
tests/test_uk_budgetary_impact.py, 17 tests: the arithmetic and sign, the terms, a JSON round trip, the exports, the accounts resolving on the installed model, what is read being a default output or configured (and not both), the drift guard ongov_spending's list, any number of simulations, a run on output simulations, a missing column, and four that run the installed model on made-up households: at both benefit uprating rates spending has to move withhousehold_benefits, and under a Child Benefit and a Lifetime ISA reform it has to equalgov_spending. With spending read fromgov_spending, the uprating tests fail on the value (0 against £1,342.93 and £192.93).float(aggregate.result)in the shared helper, once where it used to flag it in the US function.🤖 Generated with Claude Code