Skip to content

Commit c5e2038

Browse files
Add free school meals variables, remove capital gains, add free TV licences (#1166)
1 parent 789ab94 commit c5e2038

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

policyengine_uk/data/dataset_schema.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pandas as pd
2+
from policyengine_uk import Microsimulation
23

34

45
class UKDataset:
@@ -19,6 +20,7 @@ def __init__(
1920
self.person = f["person"]
2021
self.benunit = f["benunit"]
2122
self.household = f["household"]
23+
self.time_period = f["time_period"].iloc[0]
2224
else:
2325
if person is None or benunit is None or household is None:
2426
raise ValueError(
@@ -39,6 +41,7 @@ def save(self, file_path: str):
3941
f.put(
4042
"household", self.household, format="table", data_columns=True
4143
)
44+
f.put("time_period", pd.Series([self.time_period]), format="table")
4245

4346
def load(self):
4447
data = {}
@@ -54,3 +57,25 @@ def copy(self):
5457
benunit=self.benunit.copy(),
5558
household=self.household.copy(),
5659
)
60+
61+
@staticmethod
62+
def from_simulation(simulation: Microsimulation, fiscal_year: int = 2025):
63+
entity_dfs = {}
64+
65+
for entity in ["person", "benunit", "household"]:
66+
input_variables = [
67+
variable
68+
for variable in simulation.input_variables
69+
if simulation.tax_benefit_system.variables[variable].entity.key
70+
== entity
71+
]
72+
entity_dfs[entity] = simulation.calculate_dataframe(
73+
input_variables, period=fiscal_year
74+
)
75+
76+
return UKDataset(
77+
person=entity_dfs["person"],
78+
benunit=entity_dfs["benunit"],
79+
household=entity_dfs["household"],
80+
fiscal_year=fiscal_year,
81+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from policyengine_uk.model_api import *
2+
3+
4+
class free_school_fruit_veg(Variable):
5+
label = "free school fruit and vegetables"
6+
entity = Person
7+
definition_period = YEAR
8+
value_type = float
9+
unit = GBP
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from policyengine_uk.model_api import *
2+
3+
4+
class free_school_meals(Variable):
5+
label = "free school meals"
6+
entity = Person
7+
definition_period = YEAR
8+
value_type = float
9+
unit = GBP
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from policyengine_uk.model_api import *
2+
3+
4+
class free_school_milk(Variable):
5+
label = "free school milk"
6+
entity = Person
7+
definition_period = YEAR
8+
value_type = float
9+
unit = GBP

policyengine_uk/variables/household/income/hbai_household_net_income.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ class hbai_household_net_income(Variable):
1212
definition_period = YEAR
1313

1414
adds = [
15-
"household_market_income",
15+
"employment_income",
16+
"self_employment_income",
17+
"savings_interest_income",
18+
"dividend_income",
19+
"miscellaneous_income",
20+
"property_income",
21+
"private_pension_income",
22+
"private_transfer_income",
23+
"maintenance_income",
1624
"child_benefit",
1725
"esa_income",
1826
"esa_contrib",
@@ -43,6 +51,10 @@ class hbai_household_net_income(Variable):
4351
"cost_of_living_support_payment",
4452
"winter_fuel_allowance",
4553
"tax_free_childcare",
54+
"free_school_meals",
55+
"free_school_fruit_veg",
56+
"free_school_milk",
57+
"tv_licence_discount",
4658
# Reference for tax-free-childcare: https://assets.publishing.service.gov.uk/media/5e7b191886650c744175d08b/households-below-average-income-1994-1995-2018-2019.pdf
4759
]
4860
subtracts = [

0 commit comments

Comments
 (0)