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

Add FTE impacts to labor supply and constituency outputs #2218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Labor supply FTE impacts.
30 changes: 30 additions & 0 deletions policyengine_api/endpoints/economy/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
self_emp_income = MicroSeries(
baseline["self_employment_income_hh"], weights=household_weight
)
total_ftes = (

Check warning on line 57 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L57

Added line #L57 was not covered by tests
MicroSeries(
baseline["weekly_hours_hh"], weights=household_weight
).sum()
/ 40
)
earnings = emp_income + self_emp_income
original_earnings = earnings - total_lsr_hh
substitution_lsr_hh = MicroSeries(
Expand All @@ -79,8 +85,11 @@
relative_lsr = dict(
income=(income_lsr_hh.sum() / original_earnings.sum()),
substitution=(substitution_lsr_hh.sum() / original_earnings.sum()),
all=(total_lsr_hh.sum() / original_earnings.sum()),
)

fte_change = total_ftes * relative_lsr["all"]

Check warning on line 91 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L91

Added line #L91 was not covered by tests

decile_rel["income"] = {
int(k): v for k, v in decile_rel["income"].items() if k > 0
}
Expand All @@ -104,6 +113,11 @@
relative_lsr=relative_lsr,
total_change=total_change,
revenue_change=revenue_change,
ftes=dict(
baseline=total_ftes,
change=fte_change,
reform=total_ftes + fte_change,
),
decile=dict(
average=decile_avg,
relative=decile_rel,
Expand Down Expand Up @@ -539,6 +553,7 @@
class UKConstituencyBreakdownByConstituency(BaseModel):
average_household_income_change: float
relative_household_income_change: float
fte_labor_supply_change: float
x: int
y: int

Expand Down Expand Up @@ -568,6 +583,8 @@
}
baseline_hnet = baseline["household_net_income"]
reform_hnet = reform["household_net_income"]
baseline_earnings = baseline["employment_income_hh"]
reform_earnings = reform["employment_income_hh"]

Check warning on line 587 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L586-L587

Added lines #L586 - L587 were not covered by tests

constituency_weights_path = download_huggingface_dataset(
repo="policyengine/policyengine-uk-data",
Expand All @@ -592,6 +609,18 @@
weight: np.ndarray = weights[i]
baseline_income = MicroSeries(baseline_hnet, weights=weight)
reform_income = MicroSeries(reform_hnet, weights=weight)
baseline_employment_income = MicroSeries(

Check warning on line 612 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L612

Added line #L612 was not covered by tests
baseline_earnings, weights=weight
)
reform_employment_income = MicroSeries(reform_earnings, weights=weight)
rel_change_earnings = (

Check warning on line 616 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L615-L616

Added lines #L615 - L616 were not covered by tests
reform_employment_income.sum() / baseline_employment_income.sum()
- 1
)
total_ftes = (

Check warning on line 620 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L620

Added line #L620 was not covered by tests
MicroSeries(baseline["weekly_hours_hh"], weights=weight).sum() / 40
)
fte_change = total_ftes * rel_change_earnings

Check warning on line 623 in policyengine_api/endpoints/economy/compare.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/endpoints/economy/compare.py#L623

Added line #L623 was not covered by tests
average_household_income_change: float = (
reform_income.sum() - baseline_income.sum()
) / baseline_income.count()
Expand All @@ -601,6 +630,7 @@
output["by_constituency"][name] = {
"average_household_income_change": average_household_income_change,
"relative_household_income_change": percent_household_income_change,
"fte_labor_supply_change": fte_change,
"x": int(constituency_names.iloc[i]["x"]), # Geographic positions
"y": int(constituency_names.iloc[i]["y"]),
}
Expand Down
6 changes: 6 additions & 0 deletions policyengine_api/jobs/tasks/compute_general_economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,14 @@
return person_weight, household_weight

def calculate_labor_supply_responses(self):
if self.country_id == "us":
weekly_hours_hh = self.simulation.calculate("weekly_hours_worked")

Check warning on line 204 in policyengine_api/jobs/tasks/compute_general_economy.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/jobs/tasks/compute_general_economy.py#L204

Added line #L204 was not covered by tests
else:
weekly_hours_hh = self.simulation.calculate("hours_worked") / 52

Check warning on line 206 in policyengine_api/jobs/tasks/compute_general_economy.py

View check run for this annotation

Codecov / codecov/patch

policyengine_api/jobs/tasks/compute_general_economy.py#L206

Added line #L206 was not covered by tests

result = {
"substitution_lsr": 0,
"weekly_hours_hh": list(weekly_hours_hh),
"income_lsr": 0,
"budgetary_impact_lsr": 0,
"income_lsr_hh": (self.household_count_people * 0)
Expand Down
Loading