Skip to content

Commit 931b682

Browse files
vahid-ahmadiclaude
andcommitted
Add Scotland UC households with youngest child under 1 calibration target
Add calibration target for UC households in Scotland where the youngest child is aged 0 (under 1 year old). Data sourced from DWP Stat-Xplore UC Households dataset (November 2023): 13,992 households. This target helps calibrate the population eligible for the Scottish Child Payment baby boost. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7d2da06 commit 931b682

6 files changed

Lines changed: 77 additions & 2 deletions

File tree

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
27-
pip install black
27+
pip install black==25.1.0
2828
- name: Check formatting
2929
run: black . -l 79 --check
3030
test:

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: minor
2+
changes:
3+
added:
4+
- Add calibration target for UC households in Scotland with youngest child under 1 (~14k from DWP Stat-Xplore)

policyengine_uk_data/storage/demographics.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ scotland_age_80_89,person-k,ons_age_sex_region,,,,,274,282,290,297,302,307,312,,
7777
scotland_children_under_16,person-k,nrs_mid_year_population_estimates,,,,,904,900,896,892,888,884,880,,,
7878
scotland_babies_under_1,person-k,nrs_vital_events,,,,,46,46,46,46,46,46,46,,,
7979
scotland_households_3plus_children,household-k,scotland_census_2022,,,,,82,82,82,82,82,82,82,,,
80+
scotland_uc_households_child_under_1,household-k,dwp_stat_xplore,,,,,14,14,14,14,14,14,14,,,
8081
south_east_age_0_9,person-k,ons_age_sex_region,,,,,1047,1044,1042,1039,1034,1028,1024,,,
8182
south_east_age_10_19,person-k,ons_age_sex_region,,,,,1122,1119,1117,1114,1108,1102,1097,,,
8283
south_east_age_20_29,person-k,ons_age_sex_region,,,,,1046,1062,1079,1093,1106,1114,1118,,,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Test Scotland UC households with child under 1 calibration target.
2+
3+
Source: DWP Stat-Xplore, UC Households dataset, November 2023
4+
https://stat-xplore.dwp.gov.uk/
5+
Filters: Scotland, Age of Youngest Child = 0
6+
Result: 13,992 households (~14k)
7+
"""
8+
9+
import pytest
10+
11+
12+
@pytest.mark.xfail(
13+
reason="Will pass after recalibration with new scotland_uc_households_child_under_1 target"
14+
)
15+
def test_scotland_uc_households_child_under_1(baseline):
16+
"""Test that UC households in Scotland with child under 1 matches DWP data.
17+
18+
Target: ~14,000 households (13,992 from Stat-Xplore November 2023)
19+
Source: DWP Stat-Xplore UC Households dataset
20+
"""
21+
region = baseline.calculate(
22+
"region", map_to="household", period=2025
23+
).values
24+
uc = baseline.calculate("universal_credit", period=2025).values
25+
household_weight = baseline.calculate(
26+
"household_weight", map_to="household", period=2025
27+
).values
28+
29+
# Check if household has child under 1
30+
is_child = baseline.calculate(
31+
"is_child", map_to="person", period=2025
32+
).values
33+
age = baseline.calculate("age", map_to="person", period=2025).values
34+
35+
child_under_1 = is_child & (age < 1)
36+
has_child_under_1 = (
37+
baseline.map_result(child_under_1, "person", "household") > 0
38+
)
39+
40+
scotland_uc_child_under_1 = (
41+
(region == "SCOTLAND") & (uc > 0) & has_child_under_1
42+
)
43+
total = (household_weight * scotland_uc_child_under_1).sum()
44+
45+
TARGET = 14_000 # DWP Stat-Xplore November 2023: 13,992 rounded to 14k
46+
TOLERANCE = 0.15 # 15% tolerance
47+
48+
assert abs(total / TARGET - 1) < TOLERANCE, (
49+
f"Expected ~{TARGET/1000:.0f}k UC households with child under 1 in Scotland, "
50+
f"got {total/1000:.0f}k ({total/TARGET*100:.0f}% of target)"
51+
)

policyengine_uk_data/utils/loss.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,25 @@ def pe_count(*variables):
536536
target_names.append("sss/scottish_child_payment")
537537
target_values.append(scp_target)
538538

539+
# UC households in Scotland with child under 1
540+
# Source: DWP Stat-Xplore, UC Households dataset, November 2023
541+
# https://stat-xplore.dwp.gov.uk/
542+
# Filters: Scotland, Age of Youngest Child = 0
543+
# ~14,000 households (13,992 in November 2023)
544+
uc_amount = sim.calculate("universal_credit")
545+
on_uc_family = uc_amount > 0
546+
on_uc_household = household_from_family(on_uc_family) > 0
547+
548+
child_under_1 = is_child & (age < 1)
549+
has_child_under_1 = household_from_person(child_under_1) > 0
550+
551+
scotland_uc_child_under_1 = (
552+
(household_region == "SCOTLAND") & on_uc_household & has_child_under_1
553+
)
554+
df["ons/scotland_uc_households_child_under_1"] = (
555+
scotland_uc_child_under_1.astype(float)
556+
)
557+
539558
# Council Tax band counts
540559

541560
ct_data = pd.read_csv(STORAGE_FOLDER / "council_tax_bands_2024.csv")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ python_classes = ["Test*"]
5959
python_functions = ["test_*"]
6060
markers = [
6161
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
62-
"unit: marks tests as unit tests",
62+
"unit: marks tests as unit tests",
6363
"integration: marks tests as integration tests",
6464
]
6565
filterwarnings = [

0 commit comments

Comments
 (0)