Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2896.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added inputs for the UK totals of the components of corporate_sector_wealth and consumption (uk_total_*), and policyengine_uk.utils.uk_totals.add_uk_totals to write them: where the data carries them, shareholding, consumption_shareholding and carbon tax's corporate part give each household its national share in any simulation of part of the UK, such as a region, an extract or one block of a build, and filter_dataset's extracts carry them.
1 change: 1 addition & 0 deletions changelog.d/2896.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A household situation no longer takes the whole UK total of business rates, corporate Stamp Duty Land Tax, corporate land and the other amounts shared out by shareholding, consumption_shareholding or income decile; whatever its weight or axes, it takes no share unless one is set.
1 change: 1 addition & 0 deletions changelog.d/2896.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the household financial net worth parameter (household.wealth.national_balance_sheet), whose only reader was the shareholding fallback for household situations.
5 changes: 3 additions & 2 deletions docs/book/programs/contrib/ubi-center/carbon-tax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
"For a household with footprint `E_h`, the [`carbon_tax` formula](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/variables/contrib/ubi_center/carbon_tax.py) is:\n",
"\n",
"```text\n",
"E_total = sum(household_weight_h * E_h)\n",
"carbon_tax_h = c * r * E_h + (1 - c) * r * E_total * shareholding_h\n",
"```\n",
"\n",
"Here `r` is the hypothetical price per tonne and `c` is the consumer-incidence fraction, both set by the [carbon-tax parameters](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/parameters/gov/contrib/ubi_center/carbon_tax.yaml). The first term allocates the consumer share by the household's footprint. The second allocates the remaining burden using [`shareholding`](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/variables/household/wealth/shareholding.py), the household's modelled corporate-sector wealth exposure. With a dataset and nonzero corporate wealth, that exposure is normalised by weighted household corporate wealth; otherwise the formula uses the national-balance-sheet denominator.\n",
"`E_total` is the footprint of all UK households. Where the data carries the UK totals of spending by category ([`policyengine_uk.utils.uk_totals`](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/utils/uk_totals.py)), it is each category's UK total times its intensity, so a simulation of part of the UK still uses the UK's footprint. Otherwise, in a simulation built from data, it is `sum(household_weight_h * E_h)` over the simulated households; in a household situation it is the published sector emissions.\n",
"\n",
"Here `r` is the hypothetical price per tonne and `c` is the consumer-incidence fraction, both set by the [carbon-tax parameters](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/parameters/gov/contrib/ubi_center/carbon_tax.yaml). The first term allocates the consumer share by the household's footprint. The second allocates the remaining burden using [`shareholding`](https://github.com/PolicyEngine/policyengine-uk/blob/main/policyengine_uk/variables/household/wealth/shareholding.py), the household's modelled corporate-sector wealth exposure. Where the data carries the UK total of corporate-sector wealth, that exposure is the household's share of it, whichever households are simulated; otherwise, in a simulation built from data, it is normalised by the simulation's weighted corporate-sector wealth. A household situation takes no share unless `shareholding` is set, so its corporate term is zero (policyengine-uk#2896).\n",
"\n",
"This is an allocation assumption, not a calculation of sector-specific demand elasticities, international ownership or the legal incidence of an import tax. Changing the incidence fraction changes who bears the modelled burden, without adding a country-of-production breakdown.\n",
"\n",
Expand Down
9 changes: 9 additions & 0 deletions policyengine_uk/data/filter_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pandas as pd

from policyengine_uk.utils.uk_totals import add_uk_totals, uk_total_columns

if typing.TYPE_CHECKING:
from policyengine_uk import Microsimulation
from policyengine_uk.data import UKSingleYearDataset
Expand All @@ -27,6 +29,11 @@ def filter_dataset(
the values it had in sim. Private school attendance ranks incomes, so the
first extract from a simulation computes its taxes and benefits.

The extract also carries the UK totals its shares of national totals are
taken by (policyengine_uk.utils.uk_totals), worked out over the whole
dataset unless it carries them already, so it keeps the shares it had in
sim rather than taking every UK total.

Parameters
----------
sim : Microsimulation
Expand All @@ -43,6 +50,8 @@ def filter_dataset(
"""
dataset: UKSingleYearDataset = sim.dataset[year]
new_dataset = dataset.copy()
if not set(uk_total_columns()) <= set(new_dataset.household.columns):
new_dataset = add_uk_totals(new_dataset)
person = new_dataset.person
# These are imputed across the whole population: birthdays are spread over
# the year, and private school attendance follows each household's income
Expand Down
8 changes: 7 additions & 1 deletion policyengine_uk/data/fiscal_partition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,16 @@ overlap_guards:
property: The level is only in gov_tax; the response incidence is only in household_tax.
- id: corporate_incidence_allocations
kind: shared_allocation_key
heads: [business_rates, sdlt_corporate, corporate_incident_tax_change, carbon_tax, land_value_tax]
heads: [business_rates, sdlt_corporate, corporate_incident_tax_change, carbon_tax, land_value_tax, employer_nics_response_capital]
property: >-
Each allocates a different receipt by shareholding; none reads another.
corporate_tax_incidence sums two of them and is excluded.
- id: consumer_incidence_allocations
kind: shared_allocation_key
heads: [consumer_incident_tax_change, employer_nics_response_consumer]
property: >-
Each allocates a different amount by consumption_shareholding; neither
reads the other.
- id: private_school_vat_level_and_change
kind: level_and_change
heads: [private_school_vat, private_school_vat_change]
Expand Down
18 changes: 18 additions & 0 deletions policyengine_uk/data/uprating_indices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,21 @@ gov.economic_assumptions.yoy_growth.orr.per_capita.rail_passenger_journeys:
- rail_usage
gov.economic_assumptions.yoy_growth.ons.population:
- household_weight
# UK totals of the keys' components, which grow like the column they sum,
# times population as household weights do (policyengine-uk#2896).
gov.economic_assumptions.yoy_growth.uk_totals.per_capita_gdp:
- uk_total_corporate_wealth
- uk_total_private_pension_wealth
gov.economic_assumptions.yoy_growth.uk_totals.consumer_price_index:
- uk_total_food_and_non_alcoholic_beverages_consumption
- uk_total_alcohol_and_tobacco_consumption
- uk_total_clothing_and_footwear_consumption
- uk_total_housing_water_and_electricity_consumption
- uk_total_household_furnishings_consumption
- uk_total_health_consumption
- uk_total_transport_consumption
- uk_total_communication_consumption
- uk_total_recreation_consumption
- uk_total_education_consumption
- uk_total_restaurants_and_hotels_consumption
- uk_total_miscellaneous_consumption
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Growth of the UK totals a dataset can carry (policyengine-uk#2896).

A UK total sums a household column over all UK households at their weights.
Household weights grow with population, so the total grows with the column's
own growth and with population: (1 + column growth) x (1 + population growth)
- 1. The totals of corporate and private pension wealth, which grow with
per-capita GDP, therefore grow with nominal GDP; those of spending, which grows
with CPI, with CPI and population. Each series is generated before the index
pass, so it gets its index like any other.
"""

from policyengine_core.parameters import Parameter, ParameterNode

# Each generated series: the per-household growth it combines with population
# growth, and its label.
UK_TOTAL_GROWTH = {
"per_capita_gdp": ("obr.per_capita.gdp", "UK total growth with per-capita GDP"),
"consumer_price_index": ("obr.consumer_price_index", "UK total growth with CPI"),
}


def _years(parameter: Parameter) -> list:
return [int(value.instant_str[:4]) for value in parameter.values_list]


def add_uk_total_growth(parameters: ParameterNode) -> ParameterNode:
yoy_growth = parameters.gov.economic_assumptions.yoy_growth
population = yoy_growth.ons.population
node = ParameterNode(name="gov.economic_assumptions.yoy_growth.uk_totals", data={})
for name, (path, label) in UK_TOTAL_GROWTH.items():
per_household = yoy_growth.get_child(path)
# From the first year both series cover. A series that ends early holds
# its last rate, as the index pass reads it.
first = max(min(_years(per_household)), min(_years(population)))
last = max(max(_years(per_household)), max(_years(population)))
values = {
f"{year}-01-01": (1 + per_household(year)) * (1 + population(year)) - 1
for year in range(first, last + 1)
}
node.add_child(
name,
Parameter(
f"gov.economic_assumptions.yoy_growth.uk_totals.{name}",
data={
"description": (
"Year-on-year growth of a UK total of a household "
f"column that grows with {path}: that growth and "
"population growth combined."
),
"values": values,
"metadata": {
"unit": "/1",
"label": label,
},
},
),
)
yoy_growth.add_child("uk_totals", node)
return parameters

This file was deleted.

5 changes: 5 additions & 0 deletions policyengine_uk/tax_benefit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
from policyengine_uk.parameters.gov.economic_assumptions.create_economic_assumption_indices import (
create_economic_assumption_indices,
)
from policyengine_uk.parameters.gov.economic_assumptions.create_uk_total_growth import (
add_uk_total_growth,
)
from policyengine_uk.parameters.gov.economic_assumptions.create_energy_price_indices import (
add_energy_price_indices,
)
Expand Down Expand Up @@ -143,6 +146,7 @@ def _install_parameters(system, parameters: ParameterNode) -> None:
add_earnings_uprating,
add_triple_lock,
add_september_cpi_uprating,
add_uk_total_growth,
create_economic_assumption_indices,
add_energy_price_indices,
project_state_pension_rates,
Expand Down Expand Up @@ -203,6 +207,7 @@ def process_parameter_tree(
- statutory uprating inputs (September CPI, May-July earnings)
- triple lock calculations for state pensions
- earnings and September CPI uprating
- growth of the UK totals a dataset can carry (policyengine-uk#2896)
- economic assumption indices
- household energy price indices
- State Pension weekly rates, projected each April from the year before
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Shares of national totals on the certified dataset (policyengine-uk#2896).

Over a whole UK dataset, shareholding and consumption_shareholding sum to one
at the dataset's weights. A part of the UK taken from a dataset that carries
its UK totals (add_uk_totals) gets the same allocations as in the UK run.
"""

import numpy as np
import pytest

from policyengine_uk import Microsimulation
from policyengine_uk.utils.uk_totals import add_uk_totals

YEAR = 2026
ALLOCATIONS = [
"shareholding",
"corporate_land_value",
"business_rates",
"corporate_sdlt",
]


@pytest.fixture(scope="module")
def uk():
return Microsimulation()


@pytest.mark.microsimulation
def test_weighted_shares_sum_to_one(uk):
weight = np.asarray(uk.calculate("household_weight", YEAR))
for variable in ["shareholding", "consumption_shareholding"]:
share = np.asarray(uk.calculate(variable, YEAR))
assert np.sum(share * weight) == pytest.approx(1, rel=1e-6), variable


@pytest.mark.microsimulation
def test_corporate_land_value_is_the_shareholding_of_corporate_land(uk):
land = uk.tax_benefit_system.parameters(f"{YEAR}-01-01").household.wealth.land
expected = (
np.asarray(uk.calculate("shareholding", YEAR))
* land.value.aggregate_corporate_land_value
)
assert np.asarray(uk.calculate("corporate_land_value", YEAR)) == pytest.approx(
expected, rel=1e-6
)


@pytest.mark.microsimulation
def test_a_nation_carrying_the_uk_totals_gets_its_uk_run_allocations(uk):
dataset = add_uk_totals(uk.dataset[YEAR])
in_scotland = (dataset.household["region"].astype(str) == "SCOTLAND").to_numpy()
scotland = dataset.copy()
scotland.household = scotland.household[in_scotland]
kept = set(scotland.household.household_id)
scotland.person = scotland.person[scotland.person.person_household_id.isin(kept)]
scotland.benunit = scotland.benunit[
scotland.benunit.benunit_id.isin(set(scotland.person.person_benunit_id))
]
alone = Microsimulation(dataset=scotland)

position = {
household_id: i
for i, household_id in enumerate(np.asarray(uk.calculate("household_id", YEAR)))
}
rows = [position[i] for i in np.asarray(alone.calculate("household_id", YEAR))]
for variable in ALLOCATIONS:
in_uk_run = np.asarray(uk.calculate(variable, YEAR))[rows]
assert np.asarray(alone.calculate(variable, YEAR)) == pytest.approx(
in_uk_run, rel=1e-4
), variable
2 changes: 1 addition & 1 deletion policyengine_uk/tests/shard_durations.toml
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@
"policyengine_uk/tests/test_lha_freeze.py::test_great_britain_lha_reforms_leave_northern_ireland_rates_unchanged" = 26
"policyengine_uk/tests/test_bonus_sacrifice_properties.py::test_bonus_sacrifice_scores_like_salary_sacrifice[split-2028]" = 26
"policyengine_uk/tests/test_legacy_carer_premium_properties.py::test_scottish_caring_hours_follow_carer_support_payment" = 26
"policyengine_uk/tests/test_weighted_incidence.py::test_zero_weight_holder_uses_existing_fallback[shareholding-expected0]" = 26
"policyengine_uk/tests/test_weighted_incidence.py::test_zero_weighted_total_gives_no_share[shareholding]" = 26
"policyengine_uk/tests/test_dated_reform_routes.py::test_a_dict_reform_reaches_the_uc_rebalancing_inputs" = 26
"policyengine_uk/tests/test_legacy_award_readers_properties.py::test_claimant_and_partner_awards_passport_housing_benefit_income" = 25
"policyengine_uk/tests/test_dataframe_dataset.py::test_spending_on_a_small_frame_goes_to_the_deciles_it_holds[nhs]" = 25
Expand Down
Loading
Loading