Skip to content

OBBB Notebook #54

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

Open
wants to merge 16 commits into
base: main
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
375 changes: 187 additions & 188 deletions household_net_income_breakdown.ipynb

Large diffs are not rendered by default.

1,427 changes: 1,427 additions & 0 deletions test.ipynb

Large diffs are not rendered by default.

48 changes: 28 additions & 20 deletions us/congress/fisc_10_year.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
" },\n",
" \"gov.contrib.congress.golden.fisc_act.in_effect\": {\n",
" \"2026-01-01.2100-12-31\": True\n",
" }\n",
" },\n",
" },\n",
" country_id=\"us\",\n",
")"
Expand All @@ -86,14 +86,23 @@
"outputs": [],
"source": [
"def calculate_budgetary_impact(reform, year):\n",
" baseline = Microsimulation(dataset=\"hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5\")\n",
" baseline_income = baseline.calculate(\"income_tax\", map_to=\"household\", period=year).sum()\n",
" baseline = Microsimulation(\n",
" dataset=\"hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5\"\n",
" )\n",
" baseline_income = baseline.calculate(\n",
" \"income_tax\", map_to=\"household\", period=year\n",
" ).sum()\n",
"\n",
" reformed = Microsimulation(reform=reform, dataset=\"hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5\")\n",
" reformed_income = reformed.calculate(\"income_tax\", map_to=\"household\", period=year).sum()\n",
" reformed = Microsimulation(\n",
" reform=reform,\n",
" dataset=\"hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5\",\n",
" )\n",
" reformed_income = reformed.calculate(\n",
" \"income_tax\", map_to=\"household\", period=year\n",
" ).sum()\n",
"\n",
" impact = reformed_income - baseline_income\n",
" return impact "
" return impact"
]
},
{
Expand Down Expand Up @@ -342,19 +351,20 @@
" static_impact = calculate_budgetary_impact(reform_static, year)\n",
" df.loc[year, \"Static Impact\"] = static_impact\n",
" print(f\" Done: ${static_impact:,.0f}\")\n",
" \n",
"\n",
" # Calculate dynamic impact\n",
" print(f\"Calculating dynamic impact for {year}...\", end=\"\")\n",
" dynamic_impact = calculate_budgetary_impact(reform_dynamic, year)\n",
" df.loc[year, \"Dynamic Impact\"] = dynamic_impact\n",
" print(f\" Done: ${dynamic_impact:,.0f}\")\n",
" \n",
"\n",
" # Print the results for this year\n",
" print(f\"{year} | ${static_impact:,.0f} | ${dynamic_impact:,.0f}\")\n",
" print(\"-\" * 45)\n",
" \n",
"\n",
" # Optional: Clear memory after each year\n",
" import gc\n",
"\n",
" gc.collect()"
]
},
Expand All @@ -381,23 +391,21 @@
"# Visualize the 10-year impact\n",
"fig = go.Figure()\n",
"\n",
"fig.add_trace(go.Bar(\n",
" x=df.index,\n",
" y=df[\"Static Impact\"],\n",
" name=\"Static Impact\"\n",
"))\n",
"fig.add_trace(go.Bar(x=df.index, y=df[\"Static Impact\"], name=\"Static Impact\"))\n",
"\n",
"fig.add_trace(go.Bar(\n",
" x=df.index,\n",
" y=df[\"Dynamic Impact\"],\n",
" name=\"Dynamic Impact with Behavioral Responses\"\n",
"))\n",
"fig.add_trace(\n",
" go.Bar(\n",
" x=df.index,\n",
" y=df[\"Dynamic Impact\"],\n",
" name=\"Dynamic Impact with Behavioral Responses\",\n",
" )\n",
")\n",
"\n",
"fig.update_layout(\n",
" title=\"10-Year Budgetary Impact of FISC Act\",\n",
" xaxis_title=\"Year\",\n",
" yaxis_title=\"Impact ($)\",\n",
" barmode=\"group\"\n",
" barmode=\"group\",\n",
")\n",
"\n",
"fig.show()"
Expand Down
11 changes: 7 additions & 4 deletions us/congress/fisc_debug.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
"metadata": {},
"outputs": [],
"source": [
"adjusted_gross_income = baseline.calculate(\"adjusted_gross_income\", map_to=\"household\", period=2026)"
"adjusted_gross_income = baseline.calculate(\n",
" \"adjusted_gross_income\", map_to=\"household\", period=2026\n",
")"
]
},
{
Expand All @@ -115,7 +117,9 @@
"metadata": {},
"outputs": [],
"source": [
"fisc_credit = reformed.calculate(\"family_income_supplement_credit\", map_to=\"household\", period=2026)"
"fisc_credit = reformed.calculate(\n",
" \"family_income_supplement_credit\", map_to=\"household\", period=2026\n",
")"
]
},
{
Expand Down Expand Up @@ -748,8 +752,7 @@
"with pd.option_context(\n",
" \"display.max_rows\", None, \"display.max_columns\", None\n",
"): # more options can be specified also\n",
" print(diff_pd)\n",
" "
" print(diff_pd)"
]
},
{
Expand Down
119 changes: 62 additions & 57 deletions us/harris/niit_medicare_10_year.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,48 @@
"metadata": {},
"outputs": [],
"source": [
"niit_reform = Reform.from_dict({\n",
" \"gov.contrib.biden.budget_2025.net_investment_income.rate\": {\n",
" \"2024-01-01.2100-12-31\": 0.012\n",
"niit_reform = Reform.from_dict(\n",
" {\n",
" \"gov.contrib.biden.budget_2025.net_investment_income.rate\": {\n",
" \"2024-01-01.2100-12-31\": 0.012\n",
" },\n",
" \"gov.contrib.biden.budget_2025.net_investment_income.threshold\": {\n",
" \"2025-01-01.2025-12-31\": 411000,\n",
" \"2026-01-01.2026-12-31\": 418450,\n",
" \"2027-01-01.2027-12-31\": 427500,\n",
" \"2028-01-01.2028-12-31\": 435950,\n",
" \"2029-01-01.2029-12-31\": 444275,\n",
" \"2030-01-01.2030-12-31\": 453025,\n",
" \"2031-01-01.2031-12-31\": 461975,\n",
" \"2032-01-01.2032-12-31\": 471175,\n",
" \"2033-01-01.2033-12-31\": 480625,\n",
" \"2034-01-01.2034-12-31\": 490300,\n",
" \"2035-01-01.2100-12-31\": 500200,\n",
" },\n",
" },\n",
" \"gov.contrib.biden.budget_2025.net_investment_income.threshold\": {\n",
" \"2025-01-01.2025-12-31\": 411000,\n",
" \"2026-01-01.2026-12-31\": 418450,\n",
" \"2027-01-01.2027-12-31\": 427500,\n",
" \"2028-01-01.2028-12-31\": 435950,\n",
" \"2029-01-01.2029-12-31\": 444275,\n",
" \"2030-01-01.2030-12-31\": 453025,\n",
" \"2031-01-01.2031-12-31\": 461975,\n",
" \"2032-01-01.2032-12-31\": 471175,\n",
" \"2033-01-01.2033-12-31\": 480625,\n",
" \"2034-01-01.2034-12-31\": 490300,\n",
" \"2035-01-01.2100-12-31\": 500200\n",
" }\n",
"}, country_id=\"us\")\n",
" country_id=\"us\",\n",
")\n",
"\n",
"# Medicare Reform\n",
"medicare_reform = Reform.from_dict({\n",
" \"gov.contrib.biden.budget_2025.medicare.rate\": {\n",
" \"2024-01-01.2100-12-31\": 0.012\n",
"medicare_reform = Reform.from_dict(\n",
" {\n",
" \"gov.contrib.biden.budget_2025.medicare.rate\": {\"2024-01-01.2100-12-31\": 0.012},\n",
" \"gov.contrib.biden.budget_2025.medicare.threshold\": {\n",
" \"2025-01-01.2025-12-31\": 411000,\n",
" \"2026-01-01.2026-12-31\": 418450,\n",
" \"2027-01-01.2027-12-31\": 427500,\n",
" \"2028-01-01.2028-12-31\": 435950,\n",
" \"2029-01-01.2029-12-31\": 444275,\n",
" \"2030-01-01.2030-12-31\": 453025,\n",
" \"2031-01-01.2031-12-31\": 461975,\n",
" \"2032-01-01.2032-12-31\": 471175,\n",
" \"2033-01-01.2033-12-31\": 480625,\n",
" \"2034-01-01.2034-12-31\": 490300,\n",
" \"2035-01-01.2100-12-31\": 500200,\n",
" },\n",
" },\n",
" \"gov.contrib.biden.budget_2025.medicare.threshold\": {\n",
" \"2025-01-01.2025-12-31\": 411000,\n",
" \"2026-01-01.2026-12-31\": 418450,\n",
" \"2027-01-01.2027-12-31\": 427500,\n",
" \"2028-01-01.2028-12-31\": 435950,\n",
" \"2029-01-01.2029-12-31\": 444275,\n",
" \"2030-01-01.2030-12-31\": 453025,\n",
" \"2031-01-01.2031-12-31\": 461975,\n",
" \"2032-01-01.2032-12-31\": 471175,\n",
" \"2033-01-01.2033-12-31\": 480625,\n",
" \"2034-01-01.2034-12-31\": 490300,\n",
" \"2035-01-01.2100-12-31\": 500200\n",
" }\n",
"}, country_id=\"us\")"
" country_id=\"us\",\n",
")"
]
},
{
Expand All @@ -67,65 +71,66 @@
"def analyze_reforms():\n",
" # Set up years to analyze\n",
" years = range(2025, 2035)\n",
" \n",
"\n",
" # Define reforms dictionary\n",
" reforms = {\n",
" 'NIIT': niit_reform,\n",
" 'Medicare': medicare_reform\n",
" }\n",
" \n",
" reforms = {\"NIIT\": niit_reform, \"Medicare\": medicare_reform}\n",
"\n",
" # Create or load results dataframe\n",
" csv_path = 'tax_reform_impacts.csv'\n",
" csv_path = \"tax_reform_impacts.csv\"\n",
" if os.path.exists(csv_path):\n",
" results = pd.read_csv(csv_path, index_col=0)\n",
" print(\"Loaded existing results from CSV\")\n",
" else:\n",
" results = pd.DataFrame(index=list(years), columns=reforms.keys())\n",
" print(\"Created new results DataFrame\")\n",
" \n",
"\n",
" # Initialize baseline simulation\n",
" baseline = Microsimulation(dataset='enhanced_cps_2024')\n",
" \n",
" baseline = Microsimulation(dataset=\"enhanced_cps_2024\")\n",
"\n",
" # Process each reform\n",
" for reform_name, reform_policy in reforms.items():\n",
" print(f\"\\nProcessing {reform_name} reform...\")\n",
" \n",
"\n",
" # Initialize reform simulation\n",
" reform_sim = Microsimulation(reform=reform_policy, dataset='enhanced_cps_2024')\n",
" \n",
" reform_sim = Microsimulation(reform=reform_policy, dataset=\"enhanced_cps_2024\")\n",
"\n",
" # Calculate impacts for each year\n",
" for year in years:\n",
" # Skip if already calculated\n",
" if year in results.index and pd.notna(results.at[year, reform_name]):\n",
" print(f\"Skipping {reform_name} year {year} - already calculated\")\n",
" continue\n",
" \n",
"\n",
" print(f\"Processing {reform_name} year {year}\")\n",
" try:\n",
" baseline_income = baseline.calculate(\"household_net_income\", period=year).sum()\n",
" reformed_income = reform_sim.calculate(\"household_net_income\", period=year).sum()\n",
" \n",
" baseline_income = baseline.calculate(\n",
" \"household_net_income\", period=year\n",
" ).sum()\n",
" reformed_income = reform_sim.calculate(\n",
" \"household_net_income\", period=year\n",
" ).sum()\n",
"\n",
" # Calculate impact in billions\n",
" impact = (reformed_income - baseline_income) / 1e9\n",
" d.at[year, reform_name] = round(impact, 1)\n",
" \n",
"\n",
" # Save after each calculation\n",
" results.to_csv(csv_path)\n",
" print(f\"Saved results for {reform_name} year {year}\")\n",
" \n",
"\n",
" except Exception as e:\n",
" print(f\"Error processing {reform_name} year {year}: {str(e)}\")\n",
" # Save progress even if there's an error\n",
" results.to_csv(csv_path)\n",
" continue\n",
" \n",
"\n",
" # Calculate 2025-34 total if we have all years for both reforms\n",
" if all(pd.notna(results.loc[2025:2034].values.flatten())):\n",
" results.loc['2025-34'] = results.loc[2025:2034].sum()\n",
" results.loc[\"2025-34\"] = results.loc[2025:2034].sum()\n",
" results.to_csv(csv_path)\n",
" print(\"Added 2025-34 total\")\n",
" \n",
" return results\n"
"\n",
" return results"
]
},
{
Expand Down
Loading