Skip to content

UK firm data: opt-in CT profit and R&D inputs - #1783

Draft
vahid-ahmadi wants to merge 17 commits into
mainfrom
uk-firm-ct-profit-rd
Draft

vahid-ahmadi wants to merge 17 commits into
mainfrom
uk-firm-ct-profit-rd

Conversation

@vahid-ahmadi

Copy link
Copy Markdown
Contributor

Refs #1705, #1706, #1756.

Draft. Step 4b of the #1706 split: opt-in corporation tax profit and R&D inputs for UK firms.

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), #1781, #1782. Review only this PR's commit, b20a5380d. 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

  • Taxable profit (--profit-dir, firm_profit.py): HMRC Corporation Tax statistics 2026, Tables 9A/9B (FY 2024-25), inverted through the rate schedule and allotted to status 1 companies by turnover rank. CT is therefore in-sample, and the receipts tool labels it so. Tables 6A/6B by sector are held out. Public corporations (status 4) export as COMPANY but get no profit, so their CT is 0 (stated in the module and the receipts caveat).
  • R&D (--rd-tax-credits-dir, firm_rd_tax_credits.py): HMRC R&D tax credit statistics (September 2026, 2024-25 provisional): claimants by section and size stratum, expenditure raked to section and size totals and capped at turnover; firm_is_sme from the stratum.
  • Export groups profit and rd_tax_credits; fixtures with provenance and extract tools.
  • Data years: hmrc_ct_statistics, hmrc_rd_statistics.

Losses and capital allowances are not fed: profit is drawn after them, so feeding them would deduct twice.

Checks

  • Local: the UK firm test files, test_uk_receipt_counts, test_uk_runtime_exports and the shared test_firm_* files pass; ruff check and format pass on the changed files; tools/ci_test_plan.py verify passes. The full engine-free suite was not run locally.
  • Reviewed from a fresh context before the push.

🤖 Generated with Claude Code

vahid-ahmadi and others added 17 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>
Paybill, the pay split below the secondary threshold, Employment Allowance flags and take-up, BPE headcount and the labour link, public sector headcount and the 250+ headcount tail, each opt-in and assumed, with sources, data years and receipts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Taxable profit from HMRC Corporation Tax statistics liability bands (CT in-sample) and R&D expenditure from HMRC R&D tax credit statistics, each opt-in and assumed.

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