Skip to content

UK firm data: region and legal status - #1781

Draft
vahid-ahmadi wants to merge 15 commits into
mainfrom
uk-firm-region-legal-status
Draft

vahid-ahmadi wants to merge 15 commits into
mainfrom
uk-firm-region-legal-status

Conversation

@vahid-ahmadi

Copy link
Copy Markdown
Contributor

Refs #1705, #1706, #1756.

Draft. Step 3 of the #1706 split: UK firm region and legal status.

Stacked. The base stays main so that CI runs (the test workflow runs only on PRs that target main). Until the PRs below merge, this diff also shows their commits: #1756 (shared firm layer), #1706 (UK paper-parity port). Review only this PR's commit, 182c939d3. Carved file by file from uk-firm-paper-parity-full (f644ab023), as agreed in this comment. Everything here is opt-in and experimental; none of it should feed a published costing yet.

What this PR contains

  • Region and legal status (uk_runtime/firm_attributes.py), drawn after calibration from ONS UK Business 2025: region given SIC division × turnover band (Table 8), legal status given industry group × turnover band (Table 13), weighted by the employment band (Table 12). Table 15 (region × legal status) is held out. Fixtures with workbook provenance; tools/extract_uk_firm_ons_attribute_tables.py --check re-extracts them.
  • Export-group registry (firm_table.UK_FIRM_EXPORT_GROUPS): the export is a base table plus optional input groups; this PR registers attributes only. The later PRs each add their groups as registry entries.
  • Legal-status mapping, as agreed in review:
    • status 4 (public corporation or nationalised body) → COMPANY and firm_is_public_body, so policyengine-uk charges it corporation tax and its Employment Allowance exclusion applies;
    • status 7 (non-profit body or mutual association) → firm_is_charity, labelled assumed (ONS does not split charities out), which gives it charitable rate relief (pe-uk's EA charity exception only matters for public bodies, and no status 7 body is one);
    • statuses 5–6 stay OTHER and public bodies.
  • LLP check: ONS does not name limited liability partnerships. DBT's BPE 2025 methodology note, on the same IDBR frame, counts them with companies, so they most likely sit in status 1 and are charged corporation tax here, although an LLP is tax-transparent. Caveat only; no drawn flag.
  • Data years in the receipt: data_years now adds one key per input group read (firm_build.UK_FIRM_INPUT_DATA_YEARS), apart from rule_period. This PR adds ons_attributes ("2025 frame (turnover mostly 2023-24)").
  • Value-free target candidates (firm_target_candidates.py), not wired into uk_firms_targets.json or the solve.
  • --attributes-dir is required by the build, as on the full branch.

Effect of the status 4 and 7 mappings

Measured on a full 2024-25 build of the top of the stack (2,946,015 rows, every opt-in input on, pe-uk 0d1c25010), with taxes evaluated on the same table under the old and new mappings:

Tax Old mapping New mapping Change
Corporation tax £87.04bn £87.04bn 0: status 4 is CT-liable but gets no allotted profit (HMRC liability bands go to status 1)
Employment Allowance £5.93bn £5.93bn 0: status 4 firms (124 weighted, 27.7k employees) are above the £100k NIC limit either way
Business rates (England) £32.91bn £31.37bn −£1.55bn, all from status 7 charitable relief (£1.95bn → £0.40bn)

With this PR alone (no profit, paybill or rateable value inputs) those taxes are zero, so the movement only shows once 4a–4c are in.

Checks

🤖 Generated with Claude Code

vahid-ahmadi and others added 15 commits November 26, 2026 12:39
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>
policyengine-uk gives period Y the parameter values in force on 30 April
Y, so the 2024-25 vintage is period 2024 (the £90k threshold) and
2023-24 is period 2023. Read test fixtures as UTF-8 and clarify the
#258 changelog.

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>
…ompanies and non-profits to charities

Region and legal status from ONS UK Business 2025 Tables 8, 12 and 13 (Table 15 held out), the export-group registry with the attributes group, value-free target candidates, and the receipt's data year per input group. ONS status 4 now exports as COMPANY and a public body, status 7 as a charity (assumed); LLPs are a caveat only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant