Skip to content

Add a UK budgetary impact from the government's accounts - #780

Draft
juaristi22 wants to merge 2 commits into
mainfrom
uk-budgetary-impact-gov-accounts
Draft

juaristi22 wants to merge 2 commits into
mainfrom
uk-budgetary-impact-gov-accounts

Conversation

@juaristi22

@juaristi22 juaristi22 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #779

Adds a UK budgetary impact from the government's accounts, like the US one:

  • BudgetaryImpact (tax_revenue, spending and the computed total) and calculate_budgetary_impact in uk/analysis.py, exported from pe.uk. total is the change in gov_tax less the change in the government's spending.
  • Spending is totalled from SPENDING_TERMS: household_benefits plus the two terms policyengine-uk's gov_spending adds to it, the Lifetime ISA bonus and other_public_spending_budget_change. It isn't read from gov_spending, which leaves out what the benefit uprating reforms (gov.contrib.benefit_uprating) pay and household_benefits counts, so such a reform would look free. Once policyengine-uk counts them in gov_spending and a UK data build is certified on it, it can be read instead.
  • configure_budgetary_impact_variables(*simulations), also exported from pe.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_change in outputs/change_aggregate.py is the helper the US and UK functions share.
  • BUDGETARY_IMPACT_VARIABLES names the two accounts.

Why

The UK headline in the app is the change in household_tax less the change in household_benefits, computed in the simulation service. household_tax leaves 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_analysis doesn't call the new functions. The simulation service's Stage 12 runs it on stored outputs, and ChangeAggregate raises when a column isn't there (a test shows it does, naming the variable). If the analysis read gov_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:

  • The employer NI cut (15% to 14% from 2026): total −£5.871bn (tax revenue −£5.933bn, spending −£0.062bn). household_tax less household_benefits, as the app has it today, gives +£3.833bn; employer NI falls £9.704bn.
  • A 1% uprating of all benefits: total −£6.713bn (spending +£6.713bn), as the household totals give. gov_tax less gov_spending would 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 on gov_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 with household_benefits, and under a Child Benefit and a Lifetime ISA reform it has to equal gov_spending. With spending read from gov_spending, the uprating tests fail on the value (0 against £1,342.93 and £192.93).
  • 85 tests pass in the touched test files and the ones that use the US helper or the UK analysis. Ruff 0.17.6 format and check pass on the repository.
  • mypy is informational in CI. It flags float(aggregate.result) in the shared helper, once where it used to flag it in the US function.
  • Changelog fragment check and agent-notes check: pass.

🤖 Generated with Claude Code

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 vahid-ahmadi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.80
  • gov_spending and gov_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 anth-volk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small points, with the code ones inline.

  1. 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.
  2. Merge timing with #1171. A .py release sends a policyengine-release dispatch, 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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

juaristi22 added a commit to PolicyEngine/policyengine-sim-api that referenced this pull request Dec 2, 2026
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>
@juaristi22

Copy link
Copy Markdown
Contributor Author

Done in ef2fb987:

It also closes Vahid's gap: spending is totalled from household_benefits and the two terms, so the follow-up doesn't bring the gap back.

@juaristi22

Copy link
Copy Markdown
Contributor Author

Both done in ef2fb987. Spending is totalled from household_benefits plus the two terms gov_spending adds to it, rather than read from gov_spending, until the policyengine-uk fix can be pinned. Your test is in, at both rates, on the installed model. The docstring lists the differences from the household totals.

@anth-volk

Copy link
Copy Markdown
Contributor

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 anth-volk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a UK budgetary impact from the government's accounts

3 participants