diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/us/state_dependent_exemptions/repeal_state_dependent_exemptions.ipynb b/us/state_dependent_exemptions/repeal_state_dependent_exemptions.ipynb index 86c5a09..b2c8a7e 100644 --- a/us/state_dependent_exemptions/repeal_state_dependent_exemptions.ipynb +++ b/us/state_dependent_exemptions/repeal_state_dependent_exemptions.ipynb @@ -2,9 +2,18 @@ "cells": [ { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/pavelmakarchuk/anaconda3/envs/pe/lib/python3.10/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" + ] + } + ], "source": [ "import numpy as np\n", "import pandas as pd\n", @@ -14,36 +23,56 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "\n", "reform = Reform.from_dict({\n", " \"gov.contrib.repeal_state_dependent_exemptions.in_effect\": {\n", - " \"2024-01-01.2100-12-31\": True\n", + " \"2025-01-01.2100-12-31\": True\n", " }\n", "}, country_id=\"us\")\n", "\n", "\n", "baseline = Microsimulation(dataset='pooled_3_year_cps_2023')\n", "reformed = Microsimulation(reform=reform, dataset='pooled_3_year_cps_2023')\n", - "baseline_income = baseline.calculate(\"household_net_income\", period=2024)\n", - "reformed_income = reformed.calculate(\"household_net_income\", period=2024)\n", + "baseline_income = baseline.calculate(\"household_net_income\", period=2025)\n", + "reformed_income = reformed.calculate(\"household_net_income\", period=2025)\n", "difference_income = reformed_income - baseline_income" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-6091587854.847457" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "difference_income.sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Get state codes\n", - "state_code = baseline.calculate(\"state_code\", period=2024)\n", + "state_code = baseline.calculate(\"state_code\", period=2025)\n", "\n", "# Get household weights for accurate aggregation\n", - "weights = baseline.calculate(\"household_weight\", period=2024)\n", + "weights = baseline.calculate(\"household_weight\", period=2025)\n", "\n", "# Create a DataFrame with the results\n", "results_df = pd.DataFrame({\n", @@ -66,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -75,59 +104,59 @@ "text": [ "\n", "State-by-State Impact Analysis:\n", - " state_code total_households avg_income_change_per_household total_state_income_impact households_affected percent_households_affected\n", - "4 CA 14365824.0 -161.660004 -2.322313e+09 NaN NaN\n", - "22 MI 4228719.0 -113.089996 -4.782457e+08 NaN NaN\n", - "10 GA 4348380.0 -94.570000 -4.112280e+08 NaN NaN\n", - "23 MN 2344873.0 -166.809998 -3.911444e+08 NaN NaN\n", - "14 IL 5187204.0 -61.619999 -3.196205e+08 NaN NaN\n", - "34 NY 7896529.0 -28.510000 -2.251366e+08 NaN NaN\n", - "40 SC 2221951.0 -100.739998 -2.238372e+08 NaN NaN\n", - "31 NJ 3578201.0 -44.169998 -1.580493e+08 NaN NaN\n", - "20 MD 2319566.0 -55.279999 -1.282159e+08 NaN NaN\n", - "35 OH 4992720.0 -23.680000 -1.182335e+08 NaN NaN\n", - "45 VA 3492310.0 -26.049999 -9.097714e+07 NaN NaN\n", - "29 NE 799766.0 -97.879997 -7.828219e+07 NaN NaN\n", - "15 IN 2804274.0 -18.070000 -5.068625e+07 NaN NaN\n", - "36 OK 1626192.0 -23.270000 -3.784758e+07 NaN NaN\n", - "39 RI 463160.0 -79.510002 -3.682365e+07 NaN NaN\n", - "25 MS 1201572.0 -29.100000 -3.496678e+07 NaN NaN\n", - "46 VT 292460.0 -107.150002 -3.133655e+07 NaN NaN\n", - "12 IA 1364209.0 -22.860001 -3.118891e+07 NaN NaN\n", - "49 WV 750805.0 -39.840000 -2.991399e+07 NaN NaN\n", - "1 AL 2120076.0 -12.520000 -2.653426e+07 NaN NaN\n", - "11 HI 500921.0 -46.590000 -2.333804e+07 NaN NaN\n", - "18 LA 1870034.0 -9.250000 -1.730031e+07 NaN NaN\n", - "19 MA 2817993.0 -0.360000 -1.003168e+06 NaN NaN\n", - "16 KS 1215639.0 -0.040000 -4.977200e+04 NaN NaN\n", - "38 PA 5365676.0 0.000000 0.000000e+00 NaN NaN\n", - "42 TN 2986816.0 0.000000 0.000000e+00 NaN NaN\n", - "37 OR 1752219.0 0.000000 0.000000e+00 NaN NaN\n", - "43 TX 11362365.0 0.000000 0.000000e+00 NaN NaN\n", - "44 UT 1150286.0 0.000000 0.000000e+00 NaN NaN\n", - "47 WA 3185000.0 0.000000 0.000000e+00 NaN NaN\n", - "48 WI 2559938.0 0.000000 0.000000e+00 NaN NaN\n", - "41 SD 385189.0 0.000000 0.000000e+00 NaN NaN\n", - "33 NV 1265835.0 0.000000 0.000000e+00 NaN NaN\n", - "0 AK 275571.0 0.000000 0.000000e+00 NaN NaN\n", - "30 NH 591239.0 0.000000 0.000000e+00 NaN NaN\n", - "2 AR 1279007.0 0.000000 0.000000e+00 NaN NaN\n", - "3 AZ 2941938.0 0.000000 0.000000e+00 NaN NaN\n", - "5 CO 2440251.0 0.000000 0.000000e+00 NaN NaN\n", - "6 CT 1503523.0 0.000000 0.000000e+00 NaN NaN\n", - "7 DC 330109.0 0.000000 0.000000e+00 NaN NaN\n", - "8 DE 410404.0 0.000000 0.000000e+00 NaN NaN\n", - "32 NM 882902.0 0.000000 0.000000e+00 NaN NaN\n", - "9 FL 9323535.0 0.000000 0.000000e+00 NaN NaN\n", - "17 KY 1886632.0 0.000000 0.000000e+00 NaN NaN\n", - "21 ME 608698.0 0.000000 0.000000e+00 NaN NaN\n", - "24 MO 2570655.0 0.000000 0.000000e+00 NaN NaN\n", - "26 MT 494750.0 0.000000 0.000000e+00 NaN NaN\n", - "27 NC 4553814.0 0.000000 0.000000e+00 NaN NaN\n", - "28 ND 338181.0 0.000000 0.000000e+00 NaN NaN\n", - "13 ID 769370.0 0.000000 0.000000e+00 NaN NaN\n", - "50 WY 242744.0 0.000000 0.000000e+00 NaN NaN\n", - "0 TOTAL 134260032.0 -39.224422 -5.266272e+09 0.0 0.0\n" + " state_code total_households avg_income_change_per_household total_state_income_impact\n", + "4 CA 14531141.0 -168.119995 -2442.917\n", + "22 MI 4277382.0 -113.279999 -484.533\n", + "10 GA 4398419.0 -94.610001 -416.124\n", + "23 MN 2371857.0 -172.839996 -409.952\n", + "14 IL 5246896.0 -61.740002 -323.962\n", + "34 NY 7987400.0 -28.860001 -230.489\n", + "40 SC 2247520.0 -101.629997 -228.414\n", + "31 NJ 3619377.0 -45.480000 -164.620\n", + "20 MD 2346259.0 -53.090000 -124.572\n", + "35 OH 5050174.0 -24.020000 -121.291\n", + "3 AZ 2975793.0 -35.650002 -106.090\n", + "45 VA 3532498.0 -26.370001 -93.138\n", + "27 NC 4606217.0 -18.680000 -86.054\n", + "44 UT 1163523.0 -70.320000 -81.815\n", + "13 ID 778224.0 -105.120003 -81.810\n", + "29 NE 808970.0 -101.089996 -81.779\n", + "21 ME 615702.0 -130.309998 -80.230\n", + "36 OK 1644905.0 -47.430000 -78.016\n", + "15 IN 2836545.0 -17.780001 -50.446\n", + "48 WI 2589397.0 -17.920000 -46.391\n", + "26 MT 500444.0 -86.610001 -43.344\n", + "39 RI 468489.0 -82.699997 -38.743\n", + "17 KY 1908343.0 -19.610001 -37.423\n", + "25 MS 1215399.0 -27.450001 -33.367\n", + "46 VT 295826.0 -111.870003 -33.095\n", + "12 IA 1379908.0 -22.940001 -31.649\n", + "49 WV 759445.0 -40.330002 -30.626\n", + "1 AL 2144474.0 -12.310000 -26.406\n", + "32 NM 893062.0 -28.639999 -25.582\n", + "8 DE 415126.0 -51.410000 -21.344\n", + "11 HI 506686.0 -40.430000 -20.484\n", + "2 AR 1293726.0 -12.240000 -15.839\n", + "19 MA 2850422.0 -0.350000 -0.994\n", + "16 KS 1229628.0 -0.040000 -0.050\n", + "43 TX 11493119.0 0.000000 0.000\n", + "42 TN 3021187.0 0.000000 0.000\n", + "41 SD 389622.0 0.000000 0.000\n", + "47 WA 3221652.0 0.000000 0.000\n", + "0 AK 278742.0 0.000000 0.000\n", + "37 OR 1772383.0 0.000000 0.000\n", + "33 NV 1280402.0 0.000000 0.000\n", + "30 NH 598043.0 0.000000 0.000\n", + "28 ND 342073.0 0.000000 0.000\n", + "24 MO 2600237.0 0.000000 0.000\n", + "18 LA 1891554.0 0.000000 0.000\n", + "9 FL 9430827.0 0.000000 0.000\n", + "7 DC 333908.0 0.000000 0.000\n", + "6 CT 1520825.0 0.000000 0.000\n", + "5 CO 2468332.0 0.000000 0.000\n", + "38 PA 5427422.0 0.000000 0.000\n", + "50 WY 245537.0 0.000000 0.000\n", + "0 TOTAL 135805040.0 -0.000045 -6091.589\n" ] } ], @@ -159,7 +188,7 @@ "\n", "# Format the results\n", "state_impacts['avg_income_change'] = state_impacts['income_change'].round(2)\n", - "state_impacts['total_income_impact'] = state_impacts['total_income_impact'].round(0)\n", + "state_impacts['total_income_impact'] = (state_impacts['total_income_impact'] / 1_000_000).round(3)\n", "state_impacts['households_affected'] = state_impacts['households_affected'].round(0)\n", "state_impacts['percent_households_affected'] = state_impacts['percent_households_affected'].round(2)\n", "state_impacts['weight'] = state_impacts['weight'].round(0)\n", @@ -180,10 +209,7 @@ " 'total_households': [state_impacts_sorted['total_households'].sum()],\n", " 'avg_income_change_per_household': [(state_impacts_sorted['total_state_income_impact'].sum() / \n", " state_impacts_sorted['total_households'].sum())],\n", - " 'total_state_income_impact': [state_impacts_sorted['total_state_income_impact'].sum()],\n", - " 'households_affected': [state_impacts_sorted['households_affected'].sum()],\n", - " 'percent_households_affected': [(state_impacts_sorted['households_affected'].sum() / \n", - " state_impacts_sorted['total_households'].sum() * 100)]\n", + " 'total_state_income_impact': [state_impacts_sorted['total_state_income_impact'].sum()]\n", "})\n", "\n", "# Combine state results with national totals\n", @@ -195,21 +221,133 @@ " 'state_code',\n", " 'total_households',\n", " 'avg_income_change_per_household',\n", - " 'total_state_income_impact',\n", - " 'households_affected',\n", - " 'percent_households_affected'\n", + " 'total_state_income_impact'\n", "]].to_string())" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "final_results.to_csv('state_impacts_detailed.csv', index=False)" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Children in households with zero tax in both scenarios (weighted):\n", + " state_code total_children children_zero_tax percent_zero_tax\n", + "2 AR 674,472.9 190,476.5 28.2\n", + "32 NM 460,692.2 129,421.1 28.1\n", + "18 LA 1,041,173.6 287,304.2 27.6\n", + "25 MS 628,728.5 168,819.7 26.9\n", + "1 AL 998,394.1 268,625.9 26.9\n", + "17 KY 1,014,110.9 254,769.5 25.1\n", + "36 OK 959,907.1 240,113.7 25.0\n", + "49 WV 378,390.8 87,248.9 23.1\n", + "40 SC 1,179,198.5 264,245.2 22.4\n", + "27 NC 2,249,389.3 500,394.7 22.2\n", + "43 TX 7,005,303.5 1,511,229.6 21.6\n", + "3 AZ 1,462,526.9 302,195.0 20.7\n", + "7 DC 96,331.9 19,736.5 20.5\n", + "33 NV 673,833.6 137,448.7 20.4\n", + "10 GA 2,362,779.7 472,573.8 20.0\n", + "22 MI 2,146,789.0 426,595.4 19.9\n", + "9 FL 4,147,576.2 820,765.7 19.8\n", + "8 DE 218,417.0 42,714.4 19.6\n", + "34 NY 3,695,491.9 722,195.4 19.5\n", + "21 ME 233,491.6 43,915.7 18.8\n", + "38 PA 2,522,784.9 470,198.3 18.6\n", + "35 OH 2,536,852.3 469,208.6 18.5\n", + "24 MO 1,491,649.4 274,968.5 18.4\n", + "16 KS 724,014.4 126,574.0 17.5\n", + "4 CA 7,696,760.0 1,327,456.8 17.2\n", + "42 TN 1,510,758.1 253,839.9 16.8\n", + "11 HI 293,633.5 48,603.6 16.6\n", + "28 ND 193,633.3 31,849.0 16.4\n", + "48 WI 1,360,253.0 216,446.1 15.9\n", + "45 VA 1,844,934.6 291,574.5 15.8\n", + "0 AK 183,148.1 28,983.4 15.8\n", + "19 MA 1,358,034.5 214,287.2 15.8\n", + "14 IL 2,708,379.5 427,662.1 15.8\n", + "31 NJ 1,897,915.1 274,861.4 14.5\n", + "39 RI 209,629.1 30,411.1 14.5\n", + "15 IN 1,694,145.8 241,712.4 14.3\n", + "46 VT 121,618.4 17,258.6 14.2\n", + "41 SD 211,732.2 29,992.9 14.2\n", + "26 MT 244,193.4 34,073.7 14.0\n", + "6 CT 688,378.7 96,338.9 14.0\n", + "50 WY 138,866.8 19,347.6 13.9\n", + "12 IA 807,211.3 102,575.1 12.7\n", + "20 MD 1,287,321.9 162,304.1 12.6\n", + "30 NH 268,315.1 32,842.4 12.2\n", + "37 OR 857,948.7 103,407.1 12.1\n", + "23 MN 1,286,774.4 155,286.9 12.1\n", + "47 WA 1,706,458.2 204,042.9 12.0\n", + "5 CO 1,192,968.0 139,685.5 11.7\n", + "13 ID 503,665.4 53,597.1 10.6\n", + "44 UT 943,210.6 95,065.9 10.1\n", + "29 NE 506,348.8 39,077.0 7.7\n" + ] + } + ], + "source": [ + "# Get required variables\n", + "state_codes = baseline.calculate(\"state_code\", period=2025)\n", + "num_children = baseline.calculate(\"tax_unit_children\", map_to='household', period=2025)\n", + "baseline_tax = baseline.calculate(\"state_income_tax_before_refundable_credits\", map_to='household', period=2024)\n", + "reformed_tax = reformed.calculate(\"state_income_tax_before_refundable_credits\", map_to='household', period=2024)\n", + "\n", + "# Create results DataFrame\n", + "results = pd.DataFrame({\n", + " 'state_code': state_codes,\n", + " 'num_children': num_children,\n", + " 'zero_tax_both': (np.abs(baseline_tax) < 0.01) & (np.abs(reformed_tax) < 0.01)\n", + "})\n", + "\n", + "# Get household weights\n", + "weights = baseline.calculate(\"household_weight\", period=2024)\n", + "\n", + "# Add weights to results DataFrame\n", + "results['weight'] = weights\n", + "\n", + "# Calculate weighted total children by state\n", + "total_children = (\n", + " results\n", + " .groupby('state_code')\n", + " .apply(lambda x: np.sum(x['num_children'] * x['weight']))\n", + " .reset_index(name='total_children')\n", + ")\n", + "\n", + "# Calculate weighted children with zero tax in both scenarios\n", + "zero_tax_children = (\n", + " results[results['zero_tax_both']]\n", + " .groupby('state_code')\n", + " .apply(lambda x: np.sum(x['num_children'] * x['weight']))\n", + " .reset_index(name='children_zero_tax')\n", + ")\n", + "\n", + "# Rest of the code remains the same\n", + "state_results = total_children.merge(zero_tax_children, on='state_code', how='left')\n", + "state_results['percent_zero_tax'] = (\n", + " state_results['children_zero_tax'] / state_results['total_children'] * 100\n", + ").round(1)\n", + "\n", + "state_results = state_results.sort_values('percent_zero_tax', ascending=False)\n", + "print(\"\\nChildren in households with zero tax in both scenarios (weighted):\")\n", + "print(state_results.to_string(float_format=lambda x: f\"{x:,.1f}\"))\n", + "\n" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/us/state_dependent_exemptions/state_impacts_detailed.csv b/us/state_dependent_exemptions/state_impacts_detailed.csv index d25815e..5e949e4 100644 --- a/us/state_dependent_exemptions/state_impacts_detailed.csv +++ b/us/state_dependent_exemptions/state_impacts_detailed.csv @@ -1,26 +1,53 @@ state_code,income_change,total_households,total_state_income_impact,households_affected,percent_households_affected,avg_income_change_per_household -CA,-161.65538,14365824.0,-2322312700.0,,,-161.66 -MI,-113.0947,4228719.0,-478245730.0,,,-113.09 -GA,-94.5704,4348380.0,-411227970.0,,,-94.57 -MN,-166.80835,2344873.0,-391144400.0,,,-166.81 -IL,-61.617107,5187204.0,-319620480.0,,,-61.62 -NY,-28.510832,7896529.0,-225136600.0,,,-28.51 -SC,-100.73903,2221951.0,-223837170.0,,,-100.74 -NJ,-44.170063,3578201.0,-158049340.0,,,-44.17 -MD,-55.2758,2319566.0,-128215890.0,,,-55.28 -OH,-23.681173,4992720.0,-118233464.0,,,-23.68 -VA,-26.05071,3492310.0,-90977144.0,,,-26.05 -NE,-97.881355,799766.0,-78282190.0,,,-97.88 -IN,-18.07464,2804274.0,-50686250.0,,,-18.07 -OK,-23.273746,1626192.0,-37847576.0,,,-23.27 -RI,-79.50533,463160.0,-36823652.0,,,-79.51 -MS,-29.100868,1201572.0,-34966784.0,,,-29.1 -VT,-107.14814,292460.0,-31336546.0,,,-107.15 -IA,-22.862263,1364209.0,-31188908.0,,,-22.86 -WV,-39.842545,750805.0,-29913988.0,,,-39.84 -AL,-12.515711,2120076.0,-26534264.0,,,-12.52 -HI,-46.590252,500921.0,-23338042.0,,,-46.59 -LA,-9.251335,1870034.0,-17300312.0,,,-9.25 -MA,-0.35598665,2817993.0,-1003168.0,,,-0.36 -KS,-0.040942732,1215639.0,-49772.0,,,-0.04 -TOTAL,,134260030.0,-5266272000.0,0.0,0.0,-39.224422 +CA,-168.11597,14531141.0,-2442.917,,,-168.1199951171875 +MI,-113.27784,4277382.0,-484.533,,,-113.27999877929688 +GA,-94.607544,4398419.0,-416.124,,,-94.61000061035156 +MN,-172.84001,2371857.0,-409.952,,,-172.83999633789062 +IL,-61.743633,5246896.0,-323.962,,,-61.7400016784668 +NY,-28.856606,7987400.0,-230.489,,,-28.860000610351562 +SC,-101.62947,2247520.0,-228.414,,,-101.62999725341797 +NJ,-45.482822,3619377.0,-164.62,,,-45.47999954223633 +MD,-53.093952,2346259.0,-124.572,,,-53.09000015258789 +OH,-24.017212,5050174.0,-121.291,,,-24.020000457763672 +AZ,-35.651062,2975793.0,-106.09,,,-35.650001525878906 +VA,-26.366024,3532498.0,-93.138,,,-26.3700008392334 +NC,-18.682053,4606217.0,-86.054,,,-18.68000030517578 +UT,-70.31669,1163523.0,-81.815,,,-70.31999969482422 +ID,-105.1243,778224.0,-81.81,,,-105.12000274658203 +NE,-101.090546,808970.0,-81.779,,,-101.08999633789062 +ME,-130.30594,615702.0,-80.23,,,-130.30999755859375 +OK,-47.42907,1644905.0,-78.016,,,-47.43000030517578 +IN,-17.78423,2836545.0,-50.446,,,-17.780000686645508 +WI,-17.915783,2589397.0,-46.391,,,-17.920000076293945 +MT,-86.611115,500444.0,-43.344,,,-86.61000061035156 +RI,-82.698135,468489.0,-38.743,,,-82.69999694824219 +KY,-19.610373,1908343.0,-37.423,,,-19.610000610351562 +MS,-27.453508,1215399.0,-33.367,,,-27.450000762939453 +VT,-111.872406,295826.0,-33.095,,,-111.87000274658203 +IA,-22.93527,1379908.0,-31.649,,,-22.940000534057617 +WV,-40.327354,759445.0,-30.626,,,-40.33000183105469 +AL,-12.313282,2144474.0,-26.406,,,-12.3100004196167 +NM,-28.644913,893062.0,-25.582,,,-28.639999389648438 +DE,-51.414593,415126.0,-21.344,,,-51.40999984741211 +HI,-40.427452,506686.0,-20.484,,,-40.43000030517578 +AR,-12.242687,1293726.0,-15.839,,,-12.239999771118164 +MA,-0.348893,2850422.0,-0.994,,,-0.3499999940395355 +KS,-0.04094273,1229628.0,-0.05,,,-0.03999999910593033 +TX,0.0,11493119.0,0.0,,,0.0 +TN,0.0,3021187.0,0.0,,,0.0 +SD,0.0,389622.0,0.0,,,0.0 +WA,0.0,3221652.0,0.0,,,0.0 +AK,0.0,278742.0,0.0,,,0.0 +OR,0.0,1772383.0,0.0,,,0.0 +NV,0.0,1280402.0,0.0,,,0.0 +NH,0.0,598043.0,0.0,,,0.0 +ND,0.0,342073.0,0.0,,,0.0 +MO,0.0,2600237.0,0.0,,,0.0 +LA,0.0,1891554.0,0.0,,,0.0 +FL,0.0,9430827.0,0.0,,,0.0 +DC,0.0,333908.0,0.0,,,0.0 +CT,0.0,1520825.0,0.0,,,0.0 +CO,0.0,2468332.0,0.0,,,0.0 +PA,0.0,5427422.0,0.0,,,0.0 +WY,0.0,245537.0,0.0,,,0.0 +TOTAL,,135805040.0,-6091.589,,,-4.485539711928217e-05