Commit 695d9b2
Remove randomness from country package (#1439)
* Remove randomness from country package
Move stochastic variable generation to data package. Variables now read
pre-computed values from datasets for deterministic, reproducible
calculations.
Changes:
- would_claim_pc, would_claim_uc, would_claim_child_benefit,
child_benefit_opts_out, would_evade_tv_licence_fee, household_owns_tv,
main_residential_property_purchased_is_first_home,
is_disabled_for_benefits: Remove formulas, use default_value
- would_claim_marriage_allowance: New variable for take-up decision
- marriage_allowance: Use would_claim_marriage_allowance instead of random()
- attends_private_school: Use pre-generated random draw from dataset
- is_higher_earner: Use age as deterministic tie-breaker instead of random()
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add tests for deterministic stochastic variables
Tests verify:
- Default values work correctly in policy calculator mode
- Variables can be explicitly overridden in situations
- is_higher_earner uses deterministic tie-breaking (older wins)
- Calculations are deterministic across multiple runs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Format test file with black
* Add Scottish Child Payment with deterministic take-up
Add SCP variable and parameters with would_claim_scp for deterministic
take-up (matching the pattern for other benefits in this PR).
Changes:
- Add would_claim_scp variable (default True, generated in dataset)
- Add scottish_child_payment variable with defined_for="would_claim_scp"
- Add is_scp_eligible_child helper variable
- Add SCP parameters with legislation references:
- amount.yaml (Regulation 20)
- max_age.yaml (Regulation 18)
- premium_under_one_amount.yaml (Scottish Budget 2026-27)
- qualifying_benefits/ (Regulation 14)
- takeup_rate/ (for dataset generation)
- Add tests for SCP baby bonus
Source: The Scottish Child Payment Regulations 2020
https://www.legislation.gov.uk/ssi/2020/351/contents
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor SCP to Person level with adds=['benunit']
* Add is_scp_eligible Person variable, simplify scottish_child_payment
* Split SCP into Person and BenUnit variables
- Create scottish_child_payment_person at Person level with defined_for
- Keep scottish_child_payment at BenUnit level using adds to aggregate
- Maintains backward compatibility with existing tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix SCP parameters: add 2026 rate, correct baby boost start date
- Add 2026-04-01: £28.20 rate (inflation increase per Scottish Budget)
- Change baby boost start from 2026-04-06 to 2027-04-06 (payments start 2027-28)
Source: Scottish Budget 2026-27 confirms "will be paid in 2027-28"
https://www.gov.scot/publications/scottish-budget-2026-2027/pages/6/
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix SCP tests: use confirmed rate, baby boost starts 2027
- Remove unconfirmed 2026 rate (£28.20) - belongs in PR #1475
- Update baby bonus tests to use £27.15 standard rate
- Baby boost starts 2027-04-06 per Scottish Budget announcement
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Remove baby bonus from takeup migration PR
Baby bonus (SCP Premium for under-ones) belongs in draft PR #1475
(Scottish Budget 2026-27), not this deterministic takeup PR.
This PR is only about migrating from random() to would_claim_scp.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Simplify SCP to Person level directly
Remove BenUnit wrapper - scottish_child_payment is now Person-level
with defined_for="is_scp_eligible".
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Update SCP tests for Person-level output format
Tests now specify per-person expected values since scottish_child_payment
is a Person-level variable.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 62bb695 commit 695d9b2
20 files changed
Lines changed: 560 additions & 520 deletions
File tree
- policyengine_uk
- parameters/gov/social_security_scotland/scottish_child_payment
- tests
- policy/baseline/gov/social_security_scotland
- variables
- contrib/labour
- gov
- dcms/bbc/tv_licence
- dwp
- pension_credit
- universal_credit
- hmrc
- income_tax/allowances
- social_security_scotland
- household
- consumption
- demographic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
17 | | - | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
Lines changed: 71 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | | - | |
48 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
| |||
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
69 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
| |||
86 | 95 | | |
87 | 96 | | |
88 | 97 | | |
89 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
90 | 101 | | |
91 | 102 | | |
92 | 103 | | |
| |||
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
109 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
110 | 123 | | |
111 | 124 | | |
112 | 125 | | |
| |||
129 | 142 | | |
130 | 143 | | |
131 | 144 | | |
132 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
133 | 149 | | |
134 | 150 | | |
135 | 151 | | |
| |||
149 | 165 | | |
150 | 166 | | |
151 | 167 | | |
152 | | - | |
153 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
154 | 172 | | |
155 | 173 | | |
156 | 174 | | |
| |||
170 | 188 | | |
171 | 189 | | |
172 | 190 | | |
173 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
174 | 194 | | |
175 | 195 | | |
176 | 196 | | |
| |||
190 | 210 | | |
191 | 211 | | |
192 | 212 | | |
193 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
194 | 216 | | |
195 | 217 | | |
196 | 218 | | |
| |||
216 | 238 | | |
217 | 239 | | |
218 | 240 | | |
219 | | - | |
220 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
221 | 248 | | |
222 | 249 | | |
223 | 250 | | |
| |||
239 | 266 | | |
240 | 267 | | |
241 | 268 | | |
242 | | - | |
243 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
244 | 273 | | |
245 | 274 | | |
246 | 275 | | |
| |||
262 | 291 | | |
263 | 292 | | |
264 | 293 | | |
265 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
266 | 297 | | |
267 | 298 | | |
268 | 299 | | |
| |||
283 | 314 | | |
284 | 315 | | |
285 | 316 | | |
286 | | - | |
287 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
288 | 321 | | |
289 | 322 | | |
290 | 323 | | |
| |||
306 | 339 | | |
307 | 340 | | |
308 | 341 | | |
309 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
310 | 345 | | |
311 | 346 | | |
312 | 347 | | |
| |||
327 | 362 | | |
328 | 363 | | |
329 | 364 | | |
330 | | - | |
331 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
332 | 369 | | |
333 | 370 | | |
334 | 371 | | |
| |||
349 | 386 | | |
350 | 387 | | |
351 | 388 | | |
352 | | - | |
353 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
354 | 393 | | |
355 | 394 | | |
356 | 395 | | |
| |||
371 | 410 | | |
372 | 411 | | |
373 | 412 | | |
374 | | - | |
375 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
376 | 417 | | |
377 | 418 | | |
378 | 419 | | |
| |||
393 | 434 | | |
394 | 435 | | |
395 | 436 | | |
396 | | - | |
397 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
0 commit comments