Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private school adjustment factor #959

Merged
merged 4 commits into from
Oct 15, 2024
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: 0 additions & 1 deletion docs/streamlit/pages/Capital_Gains_Tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def impute_capital_gains(total_income: float) -> float:
)

with st.expander("Capital gains imputation test runner"):

income = st.slider("Total income", 0, 500000, 50000, 1000)

with st.spinner("Imputing capital gains..."):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: student polulation adjustment factor, tested by Vahid
values:
2010-01-01: 0.77
metadata:
unit: /1
label: student polulation adjustment factor
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
- name: Attends private school returns True when attendance rate is 100%
period: 2024
input:
gov.simulation.private_school_vat.private_school_attendance_rate.100: 1
gov.simulation.private_school_vat.private_school_attendance_rate.95: 1
people:
adult:
age: 25
child:
age: 10
households:
household:
household_weight: 0.001
household_market_income: 1_000_000_000
household_benefits: 0
members: [
adult,
child
]
output:
attends_private_school: [False, True]

- name: Attends private school returns False when attendance rate is 0%
period: 2024
input:
Expand Down
41 changes: 41 additions & 0 deletions policyengine_uk/utils/solve_private_school_attendance_factor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from policyengine_uk import Microsimulation
from policyengine_core.reforms import Reform

# Initialize variables to track the best private_school_factor and its result
best_factor = None
smallest_difference = float("inf")

# Loop over values of private_school_factor from 0.7 to 0.8 in steps of 0.01
for factor in [round(x * 0.01, 2) for x in range(70, 81)]:
# Define the reform with the current private_school_factor value
reform = Reform.from_dict(
{
"gov.contrib.labour.private_school_vat": {
"2024-01-01.2100-12-31": 0.2
},
"gov.simulation.private_school_vat.private_school_factor": {
"2024-01-01.2100-12-31": factor
},
},
country_id="uk",
)

# Run the reformed microsimulation
reformed = Microsimulation(reform=reform)

# Calculate the number of students attending private school in thousands
private_school_attendance = (
reformed.calculate("attends_private_school", period=2025).sum() / 1e3
)

# Compare the result with 550 and track the best value
difference = abs(private_school_attendance - 550)
if difference < smallest_difference:
smallest_difference = difference
best_factor = factor

# Report the best private_school_factor
print(
f"The best private_school_factor is {best_factor} with a difference of {smallest_difference}"
)
# The best private_school_factor is 0.77 with a difference of 1.3427231160653719
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def formula(person, period, parameters):
ps_vat_params.private_school_attendance_rate
)

population_adjustment_factor = ps_vat_params.private_school_factor

person = household.members

is_child = person("is_child", period)
Expand All @@ -44,7 +46,8 @@ def formula(person, period, parameters):
.clip(0, 100)
.values.astype(numpy.int64)
)
STUDENT_POPULATION_ADJUSTMENT_FACTOR = 1.1
# STUDENT_POPULATION_ADJUSTMENT_FACTOR = 0.78
STUDENT_POPULATION_ADJUSTMENT_FACTOR = population_adjustment_factor

p_attends_private_school = (
np.array(
Expand Down
Loading
Loading