How to use the Tax Calculator

This guide teaches you how to use the Open Source Policy Center's Tax Calculator. To follow along you will need the following:

  1. A copy of the taxcalc package installed on your local machine.
  2. A copy of the 2008 IRS public use file.

Import taxcalc package and other useful packages


In [1]:
import sys
sys.path.append("../../")
import taxcalc
from taxcalc import *
import pandas as pd
from pandas import DataFrame

Create a 'Plan X' calculator using the default parameters


In [2]:
# Default Plans
#Create a Public Use File object
tax_dta = pd.read_csv("../../puf.csv")
# Create a default Parameters object
params1 = Parameters(start_year=2013)
records1 = Records(tax_dta)
# Create a Calculator
calcX = Calculator(records=records1, params=params1)


You loaded data for 2008.
Your data have beeen extrapolated to 2013.

Calculate taxes for your Plan X


In [3]:
calcX.calc_all()

Now create an output table with intermediate and final tax variables broken down by income decile


In [4]:
tX = create_distribution_table(calcX, groupby="weighted_deciles", result_type="weighted_sum")

In [5]:
DIST_LABELS = ['Returns', 'AGI', 'Standard Deduction Filers',
                'Standard Deduction', 'Itemizers',
                'Itemized Deduction', 'Personal Exemption',
                'Taxable Income', 'Regular Tax', 'AMTI', 'AMT Filers', 'AMT',
                'Tax before Credits', 'Non-refundable Credits',
                'Tax before Refundable Credits', 'Refundable Credits',
                'Revenue']

In [6]:
tX.columns = DIST_LABELS

In [7]:
tX


Out[7]:
Returns AGI Standard Deduction Filers Standard Deduction Itemizers Itemized Deduction Personal Exemption Taxable Income Regular Tax AMTI AMT Filers AMT Tax before Credits Non-refundable Credits Tax before Refundable Credits Refundable Credits Revenue
(0, 14670155.836] 14,670,113 -114,498,590,791 9,035,754 73,539,571,201 405,178 6,651,590,837 52,654,187,580 752,634,497 75,263,450 -110,850,793,825 8,388 2,331,984,279 2,363,057,898 4,657,508 3,659,263,725 4,437,567,728 -778,304,003
(14670155.836, 29340311.672] 14,669,507 123,815,090,766 13,904,819 102,531,131,901 671,196 11,229,238,701 72,852,234,928 7,334,745,578 734,130,319 115,780,240,235 681 75,869,639 754,376,916 14,645,549 2,569,855,186 16,130,905,378 -13,561,050,192
(29340311.672, 44010467.509] 14,670,315 219,559,116,870 13,680,811 110,324,246,846 961,866 16,120,712,493 100,519,737,311 37,933,250,695 3,815,259,908 207,414,488,758 653 62,230,403 3,762,424,838 338,588,983 6,621,478,824 27,046,597,934 -20,425,119,110
(44010467.509, 58680623.345] 14,669,705 318,600,970,871 13,294,056 111,244,750,194 1,361,136 21,982,915,136 109,776,319,921 94,441,125,623 10,344,965,609 303,708,542,362 1,939 75,404,630 10,246,544,523 1,576,117,287 11,221,235,393 23,740,600,163 -12,519,364,770
(58680623.345, 73350779.181] 14,668,004 436,131,583,837 12,278,098 104,257,665,011 2,379,474 36,111,728,594 112,597,631,843 189,329,903,021 22,626,512,121 413,083,135,178 3,015 81,857,344 22,387,725,133 3,560,713,767 21,544,515,350 16,484,241,386 5,060,273,963
(73350779.181, 88020935.0171] 14,672,820 580,546,331,235 10,868,164 97,549,990,910 3,793,912 58,628,959,084 114,859,749,423 312,600,325,907 39,092,165,104 544,931,269,332 3,344 155,396,879 38,643,524,208 5,172,257,142 36,643,626,546 8,158,156,561 28,485,469,985
(88020935.0171, 102691090.853] 14,669,154 774,124,638,787 9,170,779 89,832,361,446 5,498,365 92,041,835,171 121,974,397,317 472,587,352,722 64,124,627,425 719,385,847,792 13,703 154,199,238 63,308,286,155 7,341,831,336 59,897,962,377 3,759,156,371 56,138,806,006
(102691090.853, 117361246.69] 14,671,492 1,044,821,495,561 7,420,493 82,808,521,081 7,249,717 137,511,324,755 137,749,204,722 688,310,065,511 100,723,259,929 965,902,749,789 68,369 300,251,121 99,215,347,794 9,734,578,367 94,479,701,071 1,989,258,026 92,490,443,045
(117361246.69, 132031402.526] 14,668,264 1,457,239,098,273 4,888,618 58,464,953,859 9,779,135 214,428,524,221 151,246,962,807 1,034,201,060,972 160,603,197,543 1,337,436,470,828 140,679 730,549,443 158,338,761,804 10,857,533,237 155,023,503,473 1,076,266,562 153,947,236,912
(132031402.526, 146701558.362] 14,672,184 4,439,063,165,896 1,965,831 23,943,914,321 12,705,858 560,104,872,987 140,137,815,380 3,722,781,238,298 1,039,016,602,393 4,175,620,057,585 3,620,379 29,337,960,298 981,348,831,303 30,576,949,530 1,026,300,166,375 555,549,883 1,025,744,616,492
sums 146,701,558 9,279,402,901,304 96,507,423 854,497,106,770 44,805,837 1,154,811,701,978 1,114,368,241,232 6,560,271,702,825 1,441,155,983,801 8,672,412,008,034 3,861,149 33,305,703,273 1,380,368,880,573 69,177,872,706 1,417,961,308,319 103,378,299,991 1,314,583,008,328

Then create a 'Plan Y' calculator using a parameter file that contains plan Y tax law.

In this case, we are using an example param file in which the state and local deduction haircut has been set to 100%, effectively repealing the deduction for state and local taxes.

In [9]:
# User specified Plans
params2 = Parameters(start_year=2013)
#Create a Public Use File object
tax_dta = pd.read_csv("../../puf.csv")
# Create a default Parameters object
records2 = Records(tax_dta)

myvars = {}
myvars['_ID_StateLocalTax_HC'] = [1]
user_mods = {2013: myvars}

# Create a Calculator
calcY = calculator(params=params2, records=records2, mods=user_mods)


Modifications are for year 2013 and Records are for year 2008. Records will be advanced to year 2013

In [10]:
calcY.calc_all()

Create an output table with intermediate and final tax variables broken down by income decile


In [11]:
tY = create_distribution_table(calcY, groupby="weighted_deciles", result_type="weighted_sum")

In [12]:
tY.columns = DIST_LABELS

In [13]:
tY


Out[13]:
Returns AGI Standard Deduction Filers Standard Deduction Itemizers Itemized Deduction Personal Exemption Taxable Income Regular Tax AMTI AMT Filers AMT Tax before Credits Non-refundable Credits Tax before Refundable Credits Refundable Credits Revenue
(0, 14670155.836] 14,670,113 -114,498,590,791 9,143,117 74,862,625,114 292,694 4,570,484,402 52,654,187,580 766,337,461 76,633,746 -108,568,635,418 8,548 2,332,731,198 2,363,949,359 4,699,356 3,660,113,338 4,437,577,997 -777,464,659
(14670155.836, 29340311.672] 14,669,507 123,815,090,766 14,101,790 104,219,572,745 461,948 7,617,859,392 72,852,234,928 7,367,509,982 737,494,576 118,092,303,887 712 76,796,728 757,386,239 15,082,498 2,572,427,560 16,130,874,696 -13,558,447,136
(29340311.672, 44010467.509] 14,670,315 219,559,116,870 13,951,833 112,755,105,893 686,175 11,219,030,646 100,519,737,311 38,546,497,866 3,876,979,295 210,649,549,090 663 62,625,728 3,816,924,138 340,275,902 6,674,291,205 27,045,893,965 -20,371,602,760
(44010467.509, 58680623.345] 14,669,705 318,600,970,871 13,748,640 115,246,745,365 900,967 14,031,268,892 109,776,319,921 96,347,183,287 10,564,718,076 308,428,982,134 2,110 80,116,307 10,456,238,609 1,594,339,683 11,412,707,083 23,726,723,139 -12,314,016,056
(58680623.345, 73350779.181] 14,668,004 436,131,583,837 13,158,042 111,838,086,417 1,492,777 22,055,460,646 112,597,631,843 194,142,420,511 23,238,097,832 421,414,804,659 3,025 84,089,585 22,972,649,158 3,630,626,720 22,059,526,421 16,427,197,129 5,632,329,292
(73350779.181, 88020935.0171] 14,672,820 580,546,331,235 12,369,054 110,509,799,678 2,272,490 33,716,339,572 114,859,749,423 323,280,210,886 40,516,864,131 559,126,763,974 3,812 158,175,266 40,036,477,291 5,346,449,903 37,862,386,869 8,007,939,442 29,854,447,427
(88020935.0171, 102691090.853] 14,669,154 774,124,638,787 11,414,870 109,710,079,168 3,242,861 51,604,935,293 121,974,397,317 492,391,291,024 67,511,371,839 740,622,090,036 13,809 160,252,454 66,658,281,908 7,540,661,574 63,049,127,891 3,591,439,398 59,457,688,494
(102691090.853, 117361246.69] 14,671,492 1,044,821,495,561 10,693,951 116,615,789,576 3,963,655 68,620,101,658 137,749,204,722 722,570,842,019 107,233,912,429 1,000,261,023,147 49,785 299,814,725 105,676,959,663 9,874,055,429 100,801,835,877 1,867,515,947 98,934,319,931
(117361246.69, 132031402.526] 14,668,264 1,457,239,098,273 9,637,406 112,593,026,479 5,023,359 98,004,528,359 151,246,962,807 1,095,956,054,026 173,505,762,128 1,390,443,677,087 83,876 629,330,123 171,080,006,660 10,913,057,517 167,709,224,049 1,036,716,498 166,672,507,552
(132031402.526, 146701558.362] 14,672,184 4,439,063,165,896 7,088,444 84,261,884,504 7,578,797 237,567,973,277 140,137,815,380 3,979,187,270,154 1,121,912,513,442 4,253,071,956,165 1,542,019 12,732,072,659 1,045,065,419,409 30,671,170,234 1,089,922,533,778 551,601,538 1,089,370,932,240
sums 146,701,558 9,279,402,901,304 115,307,148 1,052,612,714,940 25,915,722 549,007,982,137 1,114,368,241,232 6,950,555,617,217 1,549,174,347,493 8,893,542,514,761 1,708,358 16,616,004,773 1,468,884,292,434 69,930,418,815 1,505,724,174,071 102,823,479,748 1,402,900,694,323

Create a difference table between plan X and plan Y


In [14]:
tdiff2013 = create_difference_table(calcX, calcY, groupby="weighted_deciles")

In [15]:
DIFF_TABLE_LABELS = ["Inds. w/ Tax Cut", "Inds. w/ Tax Increase", "Count",
                     "Mean Tax Difference", "Total Tax Difference",
                     "%age Tax Increase", "%age Tax Decrease",
                     "Share of Overall Change"]
tdiff2013.columns = DIFF_TABLE_LABELS

In [16]:
tdiff2013


Out[16]:
Inds. w/ Tax Cut Inds. w/ Tax Increase Count Mean Tax Difference Total Tax Difference %age Tax Increase %age Tax Decrease Share of Overall Change
(0, 14670155.836] 20 5,511 14,670,113 0 839,344 0.04% 0.00% 0.00%
(14670155.836, 29340311.672] 0 43,018 14,669,507 0 2,603,056 0.29% 0.00% 0.00%
(29340311.672, 44010467.509] 0 389,716 14,670,315 4 53,516,350 2.66% 0.00% 0.06%
(44010467.509, 58680623.345] 0 868,478 14,669,705 14 205,348,713 5.92% 0.00% 0.23%
(58680623.345, 73350779.181] 376 2,003,839 14,668,004 39 572,055,329 13.66% 0.00% 0.65%
(73350779.181, 88020935.0171] 42 3,541,485 14,672,820 93 1,368,977,441 24.14% 0.00% 1.55%
(88020935.0171, 102691090.853] 21 5,321,181 14,669,154 226 3,318,882,487 36.27% 0.00% 3.76%
(102691090.853, 117361246.69] 989 7,150,398 14,671,492 439 6,443,876,886 48.74% 0.01% 7.30%
(117361246.69, 132031402.526] 2,443 9,695,682 14,668,264 868 12,725,270,640 66.10% 0.02% 14.41%
(132031402.526, 146701558.362] 228,502 12,377,419 14,672,184 4,337 63,626,315,748 84.36% 1.56% 72.04%
sums 232,393 41,396,727 146,701,558 n/a 88,317,685,996 n/a n/a 100.00%

Increment years to 2016 and create another difference table


In [17]:
for i in range(3):
    calcX.increment_year()
    calcY.increment_year()

print calcX.current_year
print calcY.current_year
calcX.calc_all()
calcY.calc_all()


2016
2016

In [18]:
tdiff2016 = create_difference_table(calcX, calcY, groupby="weighted_deciles")
tdiff2016.columns = DIFF_TABLE_LABELS
tdiff2016


Out[18]:
Inds. w/ Tax Cut Inds. w/ Tax Increase Count Mean Tax Difference Total Tax Difference %age Tax Increase %age Tax Decrease Share of Overall Change
(0, 15271290.822] 76 5,791 15,270,892 0 912,766 0.04% 0.00% 0.00%
(15271290.822, 30542581.643] 0 56,393 15,270,779 0 4,406,457 0.37% 0.00% 0.00%
(30542581.643, 45813872.465] 0 433,838 15,270,329 5 74,766,325 2.84% 0.00% 0.07%
(45813872.465, 61085163.286] 32 994,234 15,271,562 17 259,512,661 6.51% 0.00% 0.24%
(61085163.286, 76356454.108] 402 2,336,250 15,269,499 50 769,816,486 15.30% 0.00% 0.72%
(76356454.108, 91627744.93] 87 3,959,723 15,272,293 116 1,777,394,991 25.93% 0.00% 1.67%
(91627744.93, 106899035.751] 66 5,779,484 15,271,485 283 4,317,872,123 37.84% 0.00% 4.05%
(106899035.751, 122170326.573] 1,018 7,847,062 15,273,010 527 8,046,876,927 51.38% 0.01% 7.55%
(122170326.573, 137441617.395] 6,103 10,390,689 15,271,454 1,056 16,121,981,222 68.04% 0.04% 15.13%
(137441617.395, 152712908.216] 235,231 13,043,926 15,271,605 4,922 75,169,687,114 85.41% 1.54% 70.55%
sums 243,016 44,847,390 152,712,908 n/a 106,543,227,071 n/a n/a 100.00%

In [ ]:


In [19]: