Skip to content

Commit

Permalink
Private school adjustment factor (#959)
Browse files Browse the repository at this point in the history
* Private school adjustment factor

* remove unneeded files

* change tests

* change tests
  • Loading branch information
vahid-ahmadi authored Oct 15, 2024
1 parent 7d7eccd commit a6316bd
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 24 deletions.
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

0 comments on commit a6316bd

Please sign in to comment.