Skip to content

Commit

Permalink
feat: Add capability of loading data on structural reforms
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Jan 24, 2025
1 parent 0587a47 commit 8742d73
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 40 deletions.
231 changes: 231 additions & 0 deletions api_us_budgetary_impact.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/miniconda3/envs/us-3.11/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"16518726942.615528\n"
]
}
],
"source": [
"from policyengine_us import Microsimulation\n",
"from policyengine_core.reforms import Reform\n",
"\n",
"reform = Reform.from_dict({\n",
" \"gov.contrib.congress.romney.family_security_act.remove_head_of_household\": {\n",
" \"2024-01-01.2039-12-31\": True\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2024.pregnant_mothers_credit.amount[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 2800\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2024.pregnant_mothers_credit.income_phase_in_end\": {\n",
" \"2026-01-01.2039-12-31\": 10000\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.ctc.apply_ctc_structure\": {\n",
" \"2024-01-01.2039-12-31\": True\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.ctc.base[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 4200\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.ctc.base[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 3000\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.ctc.child_cap\": {\n",
" \"2026-01-01.2039-12-31\": 6\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.ctc.phase_in.income_phase_in_end\": {\n",
" \"2026-01-01.2039-12-31\": 20000\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.eitc.amount.joint[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 1400\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.eitc.amount.joint[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 5000\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.eitc.amount.single[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 700\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.eitc.amount.single[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 4300\n",
" },\n",
" \"gov.contrib.congress.romney.family_security_act_2_0.eitc.apply_eitc_structure\": {\n",
" \"2024-01-01.2039-12-31\": True\n",
" },\n",
" \"gov.contrib.treasury.repeal_dependent_exemptions\": {\n",
" \"2024-01-01.2039-12-31\": True\n",
" },\n",
" \"gov.irs.credits.cdcc.eligibility.child_age\": {\n",
" \"2026-01-01.2039-12-31\": 0\n",
" },\n",
" \"gov.irs.credits.ctc.phase_out.threshold.HEAD_OF_HOUSEHOLD\": {\n",
" \"2026-01-01.2039-12-31\": 200000\n",
" },\n",
" \"gov.irs.credits.ctc.phase_out.threshold.JOINT\": {\n",
" \"2026-01-01.2039-12-31\": 400000\n",
" },\n",
" \"gov.irs.credits.ctc.phase_out.threshold.SEPARATE\": {\n",
" \"2026-01-01.2039-12-31\": 200000\n",
" },\n",
" \"gov.irs.credits.ctc.phase_out.threshold.SINGLE\": {\n",
" \"2026-01-01.2039-12-31\": 200000\n",
" },\n",
" \"gov.irs.credits.ctc.phase_out.threshold.SURVIVING_SPOUSE\": {\n",
" \"2026-01-01.2039-12-31\": 200000\n",
" },\n",
" \"gov.irs.credits.ctc.refundable.fully_refundable\": {\n",
" \"2024-01-01.2039-12-31\": True\n",
" },\n",
" \"gov.irs.credits.eitc.phase_in_rate[2].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.34\n",
" },\n",
" \"gov.irs.credits.eitc.phase_in_rate[3].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.34\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.joint_bonus[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 10000\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.joint_bonus[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 10000\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.rate[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.1\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.rate[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.25\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.rate[2].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.25\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.rate[3].amount\": {\n",
" \"2026-01-01.2039-12-31\": 0.25\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.start[0].amount\": {\n",
" \"2026-01-01.2039-12-31\": 10000\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.start[1].amount\": {\n",
" \"2026-01-01.2039-12-31\": 33000\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.start[2].amount\": {\n",
" \"2026-01-01.2039-12-31\": 33000\n",
" },\n",
" \"gov.irs.credits.eitc.phase_out.start[3].amount\": {\n",
" \"2026-01-01.2039-12-31\": 33000\n",
" },\n",
" \"gov.irs.deductions.itemized.salt_and_real_estate.cap.HEAD_OF_HOUSEHOLD\": {\n",
" \"2026-01-01.2039-12-31\": 30000\n",
" },\n",
" \"gov.irs.deductions.itemized.salt_and_real_estate.cap.JOINT\": {\n",
" \"2026-01-01.2039-12-31\": 30000\n",
" },\n",
" \"gov.irs.deductions.itemized.salt_and_real_estate.cap.SEPARATE\": {\n",
" \"2026-01-01.2039-12-31\": 15000\n",
" },\n",
" \"gov.irs.deductions.itemized.salt_and_real_estate.cap.SINGLE\": {\n",
" \"2026-01-01.2039-12-31\": 30000\n",
" },\n",
" \"gov.irs.deductions.itemized.salt_and_real_estate.cap.SURVIVING_SPOUSE\": {\n",
" \"2026-01-01.2039-12-31\": 30000\n",
" }\n",
"}, country_id=\"us\")\n",
"\n",
"\n",
"baseline = Microsimulation(dataset=\"enhanced_cps_2024\")\n",
"reformed = Microsimulation(reform=reform, dataset=\"enhanced_cps_2024\")\n",
"baseline_income = baseline.calculate(\"household_net_income\", period=2026)\n",
"reformed_income = reformed.calculate(\"household_net_income\", period=2026)\n",
"difference_income = reformed_income - baseline_income\n",
"\n",
"# This we equate with budgetary impacts in the Reproduce in Python\n",
"print(difference_income.sum())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"budgetary_impact: -16518718731.085938\n",
"tax_revenue_impact -16518718731.085938\n",
"state_tax_revenue_impact 2949016097.914917\n"
]
}
],
"source": [
"# policyengine_api.jobs.tasks.compute_general_economy.GeneralEconomyTask.calculate_tax_and_spending\n",
"\n",
"baseline_total_tax = baseline.calculate(\"household_tax\", period=2026).sum()\n",
"baseline_total_spending = baseline.calculate(\n",
" \"household_benefits\",\n",
" period=2026\n",
").sum()\n",
"baseline_total_state_tax = baseline.calculate(\"household_state_income_tax\", period=2026).sum()\n",
"\n",
"reformed_total_tax = reformed.calculate(\"household_tax\", period=2026).sum()\n",
"reformed_total_spending = reformed.calculate(\n",
" \"household_benefits\",\n",
" period=2026\n",
").sum()\n",
"reformed_total_state_tax = reformed.calculate(\"household_state_income_tax\", period=2026).sum()\n",
"\n",
"# policyengine_api.jobs.tasks.compute_general_economy.compute_general_economy\n",
"\n",
"baseline_total_benefits = baseline_total_spending\n",
"reformed_total_benefits = reformed_total_spending\n",
"\n",
"# policyengine_api.endpoints.economy.compare.budgetary_impact\n",
"\n",
"tax_revenue_impact = reformed_total_tax - baseline_total_tax\n",
"state_tax_revenue_imapct = reformed_total_state_tax - baseline_total_state_tax\n",
"benefit_spending_impact = reformed_total_benefits - baseline_total_benefits\n",
"\n",
"budgetary_impact = tax_revenue_impact - benefit_spending_impact\n",
"\n",
"# This is what the API treats as budgetary impact\n",
"print(\"budgetary_impact:\", budgetary_impact)\n",
"print(\"tax_revenue_impact\", tax_revenue_impact)\n",
"print(\"state_tax_revenue_impact\", state_tax_revenue_imapct)\n",
"\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "us-3.11",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 8742d73

Please sign in to comment.