Repository navigation
Count employer National Insurance in the UK budget headline - #1171
Conversation
The economy output's tax and benefit figures were the changes in household_tax and household_benefits for every country. policyengine-uk's household_tax holds only the taxes households pay, so it leaves out employer National Insurance; under the model's default incidence an employer NI change moves gross pay, and the headline saw only the tax on that pay change. A cut in the employer rate showed as a saving. The UK now totals gov_tax and gov_spending (gov_balance), named per country in the contract's budget_total_variables. UK runs request them as extra output variables before they run: in the annual-impact runtime, the Stage 12 output plan and the UK precompute hook. UK reports store their tax and benefit budget rows under the new names. Fixes #1170 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vahid-ahmadi
left a comment
There was a problem hiding this comment.
I checked the diagnosis against policyengine-uk main (e6909e8de), and it holds. There is one gap in the new measure that I think needs closing before this merges.
The diagnosis
household_taxaddsbudget_variables_in_effect("tax", …)fromprograms.yaml, which has noni_employer.gov_tax(GOV_TAX_VARIABLES) has it, andgov_balance = gov_tax − gov_spending.- I diffed the two pairs of lists at 2026, and the differences are exactly the ones the PR description gives:
gov_taxaddsni_employerandlifetime_isa_withdrawal_charge, and holdsvatandprivate_school_vatas levels wherehousehold_taxholds their changes;household_taxhas the two employer NI incidence allocations;gov_spendingaddslifetime_isa_bonusandother_public_spending_budget_change.
- A one-household check (one employee on £30,000 and a pensioner, employer rate 15%→14% from 2026) shows the same sign flip at small scale:
household_tax+£61.41, whilegov_taxandgov_balancefall by £157.89. - Choosing the government accounts over "household taxes +
ni_employer" is right. With non-zero consumer or capital incidence, the household route would count the allocations as well as the NI they come from.gov_taxcounts the revenue once, throughconsumer_incident_tax_revenue_changeandcorporate_incident_tax_revenue_change.
The gap: gov_spending doesn't include the benefit uprating contrib term. household_benefits adds general_benefits × gov.contrib.benefit_uprating.all + non_sp_benefits × …non_sp on top of its list. gov_spending is a fixed list without that term. On the same household with gov.contrib.benefit_uprating.all = 0.05:
household_benefits: £12,676.00 → £13,309.80 (+£633.80)gov_spending: £12,676.00 → £12,676.00 (no change)gov_balance: no change
So after this PR, a benefit uprating reform's cost would drop out of the UK headline, swapping one wrong headline for another. Council tax abolition is fine, because both routes drop the same three terms. That uprating term is the only other difference I found.
Two ways to fix it:
- Add the uprating term to
gov_spendingin policyengine-uk, sogov_balanceis right as well. That's the better fix, but it needs a pe-uk release and a bump in the executor's pins before this PR goes in. - Keep
household_benefitsfor the UK benefit row and change only the tax row togov_tax, then document the mixed pair.
Either way, a test in test_simulation_output_budget.py with a benefit uprating reform would keep the gap closed.
Rollout
- Stored reports. As the PR says, UK reports stored before the deploy keep the old headline until they are computed again. If Dan reopens his report after we tell him the fix is live, he will still see £3.9bn. It's worth invalidating stored UK economy results when this deploys, or at least those touching employer NI, or telling him to rerun.
- The £3.9bn against £3.8bn gap. That fits a different data build or year, and the sign and size reproduce, so I wouldn't block on it.
Your "where we may have this wrong" questions: I agree with the measure, subject to the gap above, and with keeping the per-country names in the contract library. I didn't audit coverage of every UK budget path.
Review drafted with AI assistance and checked against the code at a1643ae35e0fe6d448c3bc41d14d497d45b890c8 (and policyengine-uk main at e6909e8de).
anth-volk
left a comment
There was a problem hiding this comment.
Requesting changes so this doesn't merge before it uses .py's new UK budget functions.
This PR hasn't changed since it was opened (head a1643ae3). It still:
- keeps its own copy of the UK variable names (
BUDGET_TOTAL_VARIABLESandbudget_total_variablesinpolicyengine_simulation_contract.macro_output); - adds them to the simulations' outputs with its own
configure_budget_total_variables; - doesn't call PolicyEngine/policyengine.py#780's
calculate_budgetary_impact, and doesn't move the executor'spolicyenginepin.
The descriptions of PolicyEngine/policyengine.py#780 and PolicyEngine/policyengine-app-v2#1636 both describe this PR as already calling those functions and moving its .py pin to the release that has them.
I assume that's because this PR depends on #780: it can only call the functions once #780 is merged and released. Before this merges, please:
- Once #780's release is out, replace the local names,
configure_budget_total_variablesand the UK branch ofbuild_budgetary_impactwith .py'sBUDGETARY_IMPACT_VARIABLES,configure_budgetary_impact_variablesandcalculate_budgetary_impact, and pin the executor to that release. The UK baseline precompute step (_prepare_uk_baseline_outputs) has only a baseline simulation, so it needs .py's configure function to accept any number of simulations; I've noted that on #780. - Until then, say in this PR's description that moving to .py's functions is still to come, so it matches what #780 and app-v2#1636 say.
Drafted with Claude Code and checked against a1643ae35e0fe6d448c3bc41d14d497d45b890c8.
|
Follow-up to my review above: moving to .py's functions can wait. This PR doesn't need PolicyEngine/policyengine.py#780. It totals I also suggested the .py release so that stored UK reports would be calculated again. That doesn't need #780 either. Today app v3 reads a report from API v1, and API v1 serves a fresh report whenever its installed policyengine-uk, .py or policyengine-core version differs from the stored report's. So any release that reaches API v1 after this deploys does it. So, from my review:
What's left before this merges is the gap Vahid found above. Drafted with Claude Code. |
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>
|
Thanks. Pushed
The policyengine-uk fix to |
|
You're right about Fix: the spending is now totalled from its terms, Test: yours, at both rates, on the installed model. It fails on the value if the total reads Stored reports: I had this wrong in the description. The app's report pages read the API's v1 economy route, whose cache, like the saved report outputs, is keyed by the API's own policyengine-uk, .py and core versions. PolicyEngine/policyengine-api#4377 moved the API to 6.20.4, the version this deploys on, before this merged, so UK reports computed in between keep the old headline. As you suggested, I'll have them invalidated: PolicyEngine/policyengine-api#4388 raises the API's cache versions once this has deployed, and every report then computes again when it is next opened. The v2 stored reports do keep their figures until they are run again. Coverage: The description has the decision and the follow-up steps. |
anth-volk
left a comment
There was a problem hiding this comment.
Approving at 32129667. This replaces my earlier request for changes.
The benefit uprating gap is fixed. UK spending is now household_benefits plus lifetime_isa_bonus and other_public_spending_budget_change, the two terms gov_spending adds to it, so a benefit uprating reform's cost counts. The new tests check, on the installed model, that the uprating is counted at both rates and that gov_spending adds nothing else to household_benefits.
Before merging: PolicyEngine/policyengine-api#4379 must be merged and fully deployed to production. UK reports stored after this PR hold only gov_tax and gov_spending rows, and API v2's stored-report reader can't read them without #4379.
Checked against 321296675b322fb51bcc79813eca961b9d442b64.
|
Merge order for this fix and the PRs around it:
Drafted with Claude Code. |
Fixes #1170
The UK budget headline in the economy output (
budget.tax_revenue_impact,benefit_spending_impactandbudgetary_impact) now totals the government's accounts instead ofhousehold_taxandhousehold_benefits:gov_tax, which counts employer National Insurance.household_taxdoesn't, so every employer NI reform came out with the wrong sign in the headline.household_benefitsplus the two terms policyengine-uk'sgov_spendingadds to it,lifetime_isa_bonusandother_public_spending_budget_change. It isn'tgov_spendingitself yet, which leaves out the benefit uprating reforms (see the decision).US output is unchanged.
PolicyEngine/policyengine-api#4377 merged first, on 2 December at 13:25 UTC. It moves the API to .py 6.20.4, the version this deploys on, so the app uses this code as soon as it deploys, but UK results computed in between keep the old headline, in the API's cache and in saved reports. Once this has deployed, the API's cache versions have to be raised to drop them (see Rollout).
The sections below set out the decision and what follows it, then the question, the diagnosis and the evidence step by step, so a reviewer can check the reasoning as well as the code. Where we may have this wrong lists the points we are least sure of.
The decision: fix it here first
We want the app to show the right figure as soon as possible, so this fixes the headline in the simulation service, on the policyengine-uk and policyengine.py it already runs. Review raised two points, and both are dealt with here or in a follow-up.
gov_spendingleaves out the benefit uprating reforms.household_benefitsadds what they pay (gov.contrib.benefit_uprating.alland.non_sp), andgov_spendingdoesn't, so totallinggov_spendingwould make a benefit uprating reform look free, swapping one wrong headline for another. The right fix is in policyengine-uk, but it can't reach the app quickly. policyengine.py refuses a policyengine-uk that its UK data build isn't certified for. The current build claims onlypolicyengine-uk ==2.179.2, published builds don't change, and the automated qualification of a pair skips Microcosm builds. So it needs a new data build on the fixed policyengine-uk; the last one took about six days from the policyengine-uk release to the certificate. Instead, this totals the same spending from its terms. With today's policyengine-uk, they givegov_spendingplus the uprating, and a test checks that the two extra terms are still allgov_spendingadds tohousehold_benefits.The rule should live in policyengine.py, with the pin moved to the release that has it. That is follow-up 3, and review agreed it can wait. It needs a policyengine.py release between the fix and the app. The pin's other purpose, making UK reports compute again, doesn't need it: raising the API's cache versions once this has deployed does that, and so does any release that reaches the API later (see Rollout). This PR doesn't call policyengine.py's UK functions and doesn't move the pin.
Follow-up steps
economy_impactandreport_outputinRUNTIME_CACHE_SCHEMA_VERSIONS, once this has deployed and not before, so that the API stops serving UK results computed between its move to 6.20.4 (Update PolicyEngine bundle to 6.20.4 policyengine-api#4377, merged) and this. Raise the economy cache schema version so ×100 decile results stop being served policyengine-api#4026 raisedeconomy_impactfor Economy output: decile.relative is now a percentage (×100), not a fraction #827. That move also brought in the other changes of 6.20.1 to 6.20.4, so UK figures move for other reasons too.gov_spendingcounts the benefit uprating reforms. Written, not yet opened.calculate_budgetary_impact, with the same spending terms, and a follow-up here calls it and moves the .py pin to the release. Merge Expose job stage and progress on annual economy job status #780 after this has deployed: its release starts the bots' updates of the simulation service and the API. Once a UK data build is certified on a policyengine-uk with (2), both readgov_spendingdirectly.The question that started this
A user cut the Class 1 employer NI rate from 15% to 14% from 2026-27 in the app. The report showed:
HMRC's ready reckoner (June 2025) costs a 1 percentage point change in the employer rate at £11.15bn in 2026-27 (table 9). The user did not expect a cut in the rate to raise revenue.
Diagnosis
output.budget.budgetary_impact(ReportContents.tsx). It requests it from the API's v1 economy route (fetchSocietyWideCalculation), which passes this service's result through, so the headline is whatbuild_budgetary_impactcomputes: the change inhousehold_taxless the change inhousehold_benefits, for every country. The v2 stored reports, which the app's report pages don't read today, hold the same totals:report_run_results._budget_rowsstores them asbudget_summaryrows, andbudget_impactin the Public API'stransformations.pyrebuilds the headline from those rows. (An earlier version of this description said the app reads the v2 rows.)household_taxholds in policyengine-uk. The taxes a household pays: income tax,national_insurance(the employee and self-employed classes only), council tax, duties, the change in VAT and so on, plus the shares of an employer NI change that the model assigns to consumers and shareholders. Employer NI itself (ni_employer) is not in it.gov_tax, the model's government revenue account, includesni_employer, andgov_balance = gov_tax - gov_spending. policyengine-uk's employer NI incidence page namesgov_balanceas the net government measure.gov.contrib.policyengine.employer_ni.employee_incidencedefaults to 1: employers hold their total employment cost fixed, soemployer_ni_fixed_employer_cost_changemoves gross pay by the employer's saving in the same year, andemployment_incomeadds it. The consumer and capital channels are zero when employee incidence is 1.household_taxsees only the extra tax on pay, so the headline shows a saving where the model's own government balance shows a cost.Evidence
The figures are national weighted totals.
This branch on real data, on the executor's own pins (policyengine 6.20.4, policyengine-uk 2.179.2, policyengine-core 3.34.10) and the certified UK data build
uk-frs-calibration-attempt-20261122T100732Z-b891aa69, model year 2026. The year file is built withensure_datasets, the reform compiled withcompile_interval_policy, and baseline and reformpolicyengine.core.Simulations getconfigure_budget_total_variables("uk", ...)beforeensure(), thenbuild_budgetary_impact("uk", ...):gov.hmrc.national_insurance.class_1.employer_scale[1].rateto 0.14 from 2026-01-01): −£5.871bn with this branch (tax −£5.933bn, spending −£0.062bn), against +£3.833bn today.gov_taxlessgov_spendinggives the same −£5.871bn.gov.contrib.benefit_uprating.all): −£6.713bn with this branch and today.gov_taxlessgov_spendinggives £0.000bn, which is the gap.gov.contrib.policyengine.budget.other_public_spending): −£0.998bn with this branch and withgov_taxlessgov_spending; today's headline leaves it out.Decomposition of the employer NI cut, model year 2026, the model's default incidence (policyengine 6.20.0 with policyengine-uk 2.177.7 and the data build
uk-frs-calibration-attempt-20261115T104657Z-fcfac709, two managed microsimulations):ni_employer): −£9.70bnemployer_ni_fixed_employer_cost_change): +£9.65bnhousehold_tax−household_benefits, today's headline: +£3.83bngov_balance: −£5.87bnThe gainers and child poverty figures match the report and follow from the pay rise; they are not separate bugs.
Pay held fixed (all three incidence channels set to 0): employer NI falls £11.05bn (Class 1 £11.01bn, Class 1A £0.04bn), 0.9% below HMRC's £11.15bn. HMRC's figure includes Class 1A and 1B and leaves out effects through earnings and profits (its note 7). Today's headline for this run is £0.00bn, because it doesn't count employer NI at all.
We have not traced why the app showed £3.9bn where we get £3.8bn for 2026 and £4.1bn for 2027. The deployed data build or the report year are the likely causes; the sign and size reproduce.
What this changes
policyengine_simulation_contract.macro_output:BUDGET_TOTAL_VARIABLESandbudget_total_variables(country)name a country's tax and benefit rows. The US, and any country without an entry, keepshousehold_taxandhousehold_benefits; the UK usesgov_taxandgov_spending.simulation_output_budget.UK_SPENDING_TERMSlists the terms of the UK's spending.build_budgetary_impacttotalsgov_taxand those terms for the UK.configure_budget_total_variablesadds the ones that aren't default outputs (gov_tax,other_public_spending_budget_changeand, on people,lifetime_isa_bonus) to each simulation'sextra_variables:ChangeAggregateneeds the columns.simulation_runtime);_configure_country_outputs, beside the US'sconfigure_budgetary_impact_variables);_prepare_uk_baseline_outputs). The UK has no prebuilt baselines yet, so this only keeps future ones complete.report_run_results._budget_rowsnames each budget row afterbudget_total_variables, so a UK report's tax and benefit rows aregov_taxandgov_spending. US rows are unchanged. The benefit row's value is the spending total above, which isgov_spendingplus the uprating.household_benefitspays, and under a Child Benefit and a Lifetime ISA reform the spending total has to equalgov_spending. One checks thatgov_spendinglists nothing beyondhousehold_benefitsexcept the two terms. With a spending total that readgov_spending, the uprating tests fail on the value (0 against £1,342.93 and £192.93).Other UK reforms. The accounts differ from the household totals in these terms (policyengine-uk 2.179.2):
gov_taxadds two termshousehold_taxlacks:ni_employer(Class 1 and 1A) and the Lifetime ISA withdrawal charge.household_taxholds their changes from baseline. Both give the same change.household_taxalso holds the employer NI consumer and capital allocations. These are shares of theni_employerchange, not revenue of their own.lifetime_isa_bonusandother_public_spending_budget_change, a term only a reform sets.Nothing else differs: on the 13 hand-built households of policyengine-uk's
test_budget_totals_pinned.py, under no reform, the two uprating rates (separately and together), council tax abolition and a basic income, in 2025 and 2026, the government accounts with the uprating counted equal the household totals plus the terms above, to within £0.01 (checked on policyengine-uk 2.181.0 with the fix).Rollout
This deploys on .py 6.20.4. PolicyEngine/policyengine-api#4377 moved the API to it on 2 December, so once its deploy is out, the app's UK reports run on this code as soon as it deploys. The API keys its cached economy results and its stored report outputs by its own policyengine-uk, .py and core versions, so moving the API made them compute again, but on the code the simulation service has at the time.
RUNTIME_CACHE_SCHEMA_VERSIONS(economy_impact,report_output), so raising the two once this has deployed makes every such report compute again when it is next opened, US reports included. Raising them earlier would only cache the old headline under the new versions. A newer .py that reaches the API after this deploys does the same as raising them.gov_taxandgov_spending, which the Public API's reader can't read until Read UK budget rows from gov_tax and gov_spending policyengine-api#4379 deploys ("the budget summary has no household_tax row"), so #4379 should deploy first.stored_plan_holds). UK baselines stored before this deploys lack the new columns, so each is calculated again once.Where we may have this wrong
ni_employeralone. The accounts also bring in the Lifetime ISA bonus and charge and the reform-only public spending term.lifetime_isa_bonusandother_public_spending_budget_changebeing all thatgov_spendingadds tohousehold_benefits. A test reads policyengine-uk's two lists and fails if that changes. The row is still namedgov_spendingwhile its value adds the uprating.build_budgetary_impacthas one caller, the output builder, which is constructed in three places: the annual-impact runtime (which makes the first call above just before), Stage 12 aggregation (covered by the output plan) and the segmented national reduce, which is US only. Budget windows read each year'sbudgetfrom the child results.Checks run
projects/*/srcandlibs/*/src: clean.🤖 Generated with Claude Code