Repository navigation
UK firm data: paper-parity port on the shared firm layer - #1706
vahid-ahmadi wants to merge 14 commits into
Conversation
juaristi22
left a comment
There was a problem hiding this comment.
Reviewed at f644ab023. The port and the rules seam look sound, #636 is fixed, and CI is green. Your three questions first, then some notes.
Rule period: 2024-25 evaluated as period 2024
This is right. In pe-uk, period Y is the fiscal year that starts in Y. Each parameter takes its value on 30 April Y, unless it opts into day-weighting (convert_to_fiscal_year_parameters). That gives the £90k threshold, the FY2024 CT rates and the 2024-25 NICs.
Two caveats are worth recording in the receipt or the docs:
- 1 January changes aren't apportioned. A change dated 1 January only counts for part of the year if the parameter is day-weighted.
- The data lag the rules by a year. The ONS 2025 workbook's turnover comes mostly from VAT returns for FY2023/24 (its note 4, which is recorded in the fixture's provenance). So the "2024-25" frame's turnover predates the £90k threshold. The rules are 2024-25, but the turnover distribution near the threshold is from the £85k regime. The receipt should record the rule period and the data year separately.
ONS legal status to pe-uk legal forms
Counts from the fixture (ONS 2025, Table 12):
- companies: 2,096,600
- sole proprietors: 380,515
- partnerships: 160,865
- public corporations: 165
- central government: 3,350
- local authorities: 9,120
- non-profit bodies: 84,000
By status:
- Statuses 1–3 map one to one. Fine.
- Statuses 5–6 go to
OTHERwith the public-body flag. This is right:- local authorities are outside "company" for CT (CTA 2010 s.1121);
- the Crown isn't charged;
- both are excluded from the Employment Allowance.
- Status 4 (public corporations) goes to
OTHER, which takes them out of CT. But most public corporations are bodies corporate, and so within CT. As public-sector bodies, they're probably also excluded from the Employment Allowance.COMPANYplus the public-body flag would be closer. The count is tiny, but some of these bodies are large. - Status 7 (non-profit bodies) goes to
OTHER. That's reasonable for CT, since charitable profits and mutual trading are exempt.- The catch is that pe-uk ties two things to
firm_is_charity: mandatory charitable rate relief (80%) and the Employment Allowance's charity exception. - The export leaves
firm_is_charityasnot_set, so status-7 bodies pay full business rates. - Setting
firm_is_charityas an assumption for status 7, or for a share of those bodies, would fix most of that.
- The catch is that pe-uk ties two things to
- LLPs are worth checking. The workbook only says "3 - Partnership". If ONS puts LLPs under "1 - Company", they're charged CT, which they don't pay.
Input VAT at 20% of input costs
This is fine as a labelled placeholder, but it's an upper bound. It also combines with the export's other VAT assumption: in-scope turnover is all standard-rated, out-of-scope turnover is all exempt, and nothing is zero-rated or reduced-rated.
-
No firm can have negative net VAT. Inputs cap at 0.95 of turnover, so repayment traders can't exist. The paper puts them out of scope and leaves the £1-to-threshold band uncalibrated; that band's net VAT was −£300m in 2024-25.
-
Gross output VAT and input VAT are both overstated. Calibration pins net VAT by band, so totals are right by construction. The 1.068× VAT check is in-sample, so it doesn't test this. But anything that depends on the output/input split is off:
- the Flat Rate Scheme choice;
- partial exemption;
- voluntary registration;
- reforms that treat sales and inputs differently.
-
The PR already has the data for a fix. It extracts the ONS Supply and Use Tables 2024 for consumption shares. The same tables give each sector's purchase mix, and from that, by SIC section:
- an effective recoverable input-VAT rate;
- the shares of sales that are zero-rated and reduced-rated.
Until then, I'd keep the table out of analyses that depend on the split.
Notes
-
#636 and #258. #636 is fixed:
firm_generation.pynow imports frommicrocosm.calibrate.solveonly names that are in its__all__. For #258, the 0.20 rate now sits in the rules engine. -
Size and description. The PR is now 36 commits, 146 files and +44,589 lines, and the body's plan predates most of it. These are all in as opt-in groups:
- paybill, CT profit, rateable value and R&D;
- Employment Allowance take-up and BPE headcount;
- the Supply and Use consumption shares and the pay split;
- the household-link design.
I'd update the body and split the PR for review:
-
The opt-in inputs aren't ready yet. The receipts comparison shows:
- the Employment Allowance at £10.98bn and 2.21m claimants, against HMRC's £3.30bn and 1.22m;
- business rates in England at 1.226× official;
- the apprenticeship levy at 0.616× official.
That's fine as diagnostics in a draft, but none of it should feed a published costing yet.
-
Parity. The full build matches the paper within tolerances: the row count is exact and the frame population is +0.15%. It also fits net VAT more closely than the paper does (0.999 against 0.981). So "parity" describes it better than "reproduces".
Checked
- The generator, firm table, attribute and rules-adapter code.
- The solver imports.
- The legal-status fixture and its provenance.
- pe-uk's
convert_to_fiscal_year_parameters. - CI at the head, which is all green.
|
One more question, apart from the review above: how much of this could be made country-agnostic? Most of the details are UK-specific: the ONS and HMRC sources, the VAT and legal-status mappings, and the policyengine-uk columns. But some of the algorithms, mechanics and tools underneath may not be. If another country wanted similar synthetic firm data, it could reuse those rather than start again. From the PR description, possible candidates are:
Where do you think the line between |
|
Good question. My rough line: the data sources, the mappings and the policyengine-uk column names stay in Could be shared, with little change:
Shared in shape, but needs a country spec:
Blocked:
I'd keep this PR UK-only so it stays reviewable, then do the extraction as a follow-up once a second country actually needs it. That way the shared interface is shaped by two real cases rather than guessed from one. Does that line match what you had in mind? Reply drafted with AI assistance. |
|
Thanks, that breakdown helps. On timing, though, I'd recommend making as much of this country-agnostic as we can now, rather than planning a migration later. Otherwise the next country tends to rewrite the same code without the abstraction, instead of extracting it. Would that be too big a lift here? If not, I'd recommend this approach:
If reviewability is the concern, the shared mechanics could be one of the split PRs suggested in the review. |
|
Agreed, let's do it now rather than later. Plan:
The firm-only Reply drafted with AI assistance. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… against them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port sector-conditional employment, two-universe calibration with per-band registration propensity, stratified thinning with base weights and in_frame/vat_scope flags from firm-microsim-paper. Solve with the public solve_constraint_system (fixes #636) and use the paper's input-ratio imputation (fixes #258). Add the UKFirmRules seam keyed by firm_id, the firm universe helpers, and a policyengine-uk-named firm table export. Name policyengine-uk as the firm rules home in docs/firm-support-plan.md. Refs #1705, PolicyEngine/policyengine-uk#2939. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Commit the paper's processed 2024-25 tables with provenance and golden numbers from paper runs at aa1ce07 (full, fast and CI modes, seed 42). The engine-free test runs a thinned build and checks exact targets and propensities plus distributional tolerances; tools/firm_paper_parity.py prints the full comparison table. Refs #1705. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Share the HMRC band names between firm_universe and firm_generation, remove the unused assign_vat_flags and calculate_vat_liability_values, add UKFirmGenerationConfig.with_vintage, prove thinned solves start from base weights, feed a generated population through the policyengine-uk firm table, rename the parity tool to tools/uk_firm_paper_parity.py, and correct the changelog and docs. Refs #1705. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hash the reference JSON in the fixture provenance with the commands that produced it, assert the golden full run reproduces the paper's published 2024-25 headline, reuse the shared HMRC band names, and note the parity test in the firm support plan. Refs #1705. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pts comparison Carved from #1706's state at bd59841 without the region, legal-status and paybill steps, which move to later PRs of the split. The input-status map covers the 71 policyengine-uk inputs at the committed 0d1c25010 snapshot, with only the base columns set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…apart from the rule period The same-seed thinned 2024-25 population (295,271 rows) is identical, checked exactly against the code before this commit on the same main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…what this PR sets Fable review fixes: the support plan and README no longer say the policyengine-uk adapter is unimplemented; the receipts paybill caveat no longer describes an imputation this PR does not contain; note 4 cites the ONS publication; a FirmRuleOutputs without the VAT output raises ValueError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f644ab0 to
b11c37e
Compare
Fixes #258, fixes #636. Refs #1705, #1756 and PolicyEngine/policyengine-uk#2940.
Draft. Narrowed on 26 Nov 2026 as step 2 of the split agreed in this comment. This PR is now the UK paper-parity port, rebuilt on the country-neutral
microcosm.build.firmslayer from #1756.Stacked on #1756. The base stays
mainso that CI runs, which means that until #1756 merges, this diff also shows #1756's five commits (microcosm/build/firms/, its tests and its changelog fragment). Review only the commits aftereb799a296. The 36-commit version this PR held before is kept on the branchuk-firm-paper-parity-full(f644ab023), and the later PRs are carved from it.What this PR contains
uk_runtime/firm_generation.py): sector-conditional employment, the two universes (ONS frame and HMRC registered traders, with a per-band registration propensity), zero-turnover traders as an out-of-frame stratum, optional stratified thinning, and thein_frame/vat_scope/vat_registeredflags.0.2 + Beta(4,2)·0.6, and the 0.20 VAT rate sits in the rules engine.solve_constraint_system.microcosm.build.firms:firm_universeruns thinning and the two-universe functions throughUK_VAT_REGISTRATION_SPEC:Negative_or_Zerois excluded,£1_to_Thresholdis registrable, and the six bands above the threshold are selected.firm_rules.UKFirmRuleOutputsis aFirmRuleOutputscarryingvat_liability_if_registered.draw_in_band.PolicyEngineUKFirmRulesreadsfirm_vat_liability_if_registered.evaluate_uk_firm_taxesandweighted_uk_firm_tax_totalsread every pe-uk firm tax.tools/build_uk_firms.py,uk_runtime/firm_build.py): writesuk_firms.parquetand a deterministic receipt. It has no publish or staging path.tools/compare_uk_firm_taxes_to_receipts.py): compares totals with HMRC and MHCLG 2024-25 figures, onfirms.receipts.0d1c25010(71 inputs), read throughread_entity_variables. The input-status map sets only the 10 base columns, and every other input isnot_set.Review fixes from the 24 Nov review
rule_period(2024 for 2024-25) apart fromdata_years:rule_period_notesays a change dated later in the tax year, such as 1 January, is not apportioned unless the parameter is day-weighted.COMPANYplus the public-body flag, status 7 →firm_is_charityas an assumption) and the LLP check go to PR 3;Not in this PR (later PRs of the split)
Region and legal status:
Until PR 3 lands, this PR's build writes no region or legal status, so pe-uk applies its defaults.
Opt-in input groups, each with its source receipts:
The household-link design note, off
main.None of the opt-in diagnostics should feed a published costing yet.
Checks
Unchanged outputs. The same-seed thinned 2024-25 population (295,271 rows, 1,000 epochs) is exactly identical before and after the move onto
microcosm.build.firms, both on currentmain, checked withassert_frame_equal(check_exact=True). On currentmain, the code before the move still passed every check intest_uk_firm_paper_parity.py, including sector accuracy against the 0.90 bar, somain's solver change does not break parity.Tool equivalence. The rewired snapshot tool reproduces the committed snapshot. The receipts tool's report matched the previous tool's byte for byte, before the paybill caveat was reworded for this scope.
Local tests. The UK firm test files pass, along with ruff and
tools/ci_test_plan.py verify:test_uk_firm_paper_parity,test_uk_firm_generation,test_uk_firm_universeandtest_uk_firm_rules;test_uk_firm_buildandtest_uk_firms_targets;test_uk_firm_policyengine_uk_rulesandtest_uk_firm_policyengine_uk_schema;test_uk_firm_tax_receipts,test_uk_firm_tableandtest_uk_runtime_exports.The full engine-free suite was not run locally.
🤖 Generated with Claude Code