Learn R Programming

Calculate Federal and State Income Taxes

usincometaxes is an R package that calculates federal and state income taxes in the United States. It relies on the National Bureau of Economic Research’s (NBER) TAXSIM 35 tax simulator for calculations. The package takes care of the behind-the-scenes work of getting the data in the proper format, converting it to the proper file type for uploading to the NBER server, uploading the data, downloading the results, and placing the results into a tidy data frame.

NOTE: This package is not associated with the NBER. It is a private creation that uses their wonderful tax calculator.

Installation

You can install usincometaxes from CRAN:

install.packages('usincometaxes')

Quick example

usincometaxes helps users estimate household income taxes from data sets containing financial and household data. This allows users to estimate income taxes from surveys with financial information, as the United States Census Public Use Micro Data (PUMS).

The short example below uses taxsim_calculate_taxes() to calculate income taxes.

library(dplyr)
library(knitr)
library(usincometaxes)

family_income <- data.frame(
  taxsimid = c(1, 2),
  state = c('North Carolina', 'NY'),
  year = c(2015, 2020),
  mstat = c('married, jointly', 'single'),
  pwages = c(50000, 100000), # primary wages
  page = c(26, 36) # primary age
)

family_taxes <- taxsim_calculate_taxes(
  .data = family_income,
  marginal_tax_rates = 'Wages',
  return_all_information = FALSE
)
kable(family_taxes)
taxsimidfiitaxsiitaxficafratesrateficartfica
13487.52012.507650155.7515.33825
215103.55377.8615300246.4115.37650

Users can use the taxsimid column to join the tax data with the original data set. Every taxsimid in the input data is represented in the output tax data.

family_income %>%
  left_join(family_taxes, by = 'taxsimid') %>%
  kable()
taxsimidstateyearmstatpwagespagefiitaxsiitaxficafratesrateficartfica
1North Carolina2015married, jointly50000263487.52012.507650155.7515.33825
2NY2020single1000003615103.55377.8615300246.4115.37650

Output

taxsim_calculate_taxes() returns a data frame where each row corresponds to a row in .data and each column is a piece of tax information. The output and .data can be linked by the taxsimid column.

The amount of output (tax information) received is controlled by the return_all_information parameter to taxsim_calculate_taxes(). Setting return_all_information to FALSE returns minimal information such as federal and state tax liabilities and FICA taxes. When return_all_information is TRUE 44 different tax items are returned.

usoncometax’s output contains the same information and column names as TAXSIM 35. Therefore, please consult either the Description of Output Columns vignette or TAXSIM 35 documentation for more output information.

family_taxes_full_output <- taxsim_calculate_taxes(
  .data = family_income,
  marginal_tax_rates = 'Wages',
  return_all_information = TRUE
)

kable(family_taxes_full_output)
taxsimidfiitaxsiitaxficafratesrateficartficav10_federal_agiv11_ui_agiv12_soc_sec_agiv13_zero_bracket_amountv14_personal_exemptionsv15_exemption_phaseoutv16_deduction_phaseoutv17_itemized_deductionsv18_federal_taxable_incomev19_tax_on_taxable_incomev20_exemption_surtaxv21_general_tax_creditv22_child_tax_credit_adjustedv23_child_tax_credit_refundablev24_child_care_creditv25_eitcv26_amt_incomev27_amt_liabilityv28_fed_income_tax_before_creditv29_ficav30_state_household_incomev31_state_rent_expensev32_state_agiv33_state_exemption_amountv34_state_std_deduction_amountv35_state_itemized_deductionv36_state_taxable_incomev37_state_property_tax_creditv38_state_child_care_creditv39_state_eitcv40_state_total_creditsv41_state_bracket_ratev42_self_emp_incomev43_medicare_tax_unearned_incomev44_medicare_tax_earned_incomev45_cares_recovery_rebate
13487.52012.507650155.7515.338255000000126008000000294003487.50000005000003487.5765050000.01050000.01015000035000.0100000.0050000000
215103.55377.8615300246.4115.37650100000001240000008760015103.5000000100000015103.515300100001.010100000.0108000092000.0100006.41100000000

Input

Taxes are calculated with taxsim_calculate_taxes() using the financial and household characteristics found in the data frame represented by the .data parameter. Each column is a different piece of information and each row contains a tax payer unit.

All columns must have the column names and data types listed in the Description of Input Columns vignette. These are the same column names found in the TAXSIM 35 documentation. Therefore, you can consult the package documentation or TAXSIM 35 documentation for more information on input columns. There are two differences between usincometaxes and TAXSIM 35:

  1. usincometaxes allows users to specify the state with either the two letter abbreviation or state SOI code. usincometaxes will convert the abbreviation to an SOI code for TAXSIM 35.
  2. For filing status, mstat, users can either use the TAXSIM 35 integer found in TAXSIM 35’s documentation or one of the following descriptions:
    • “single” or 1 for single;
    • “married, jointly” or 2 for married, filing jointly;
    • “married, separately” or 6 for married, filing separately;
    • “dependent child” or 8 for dependent, usually a child with income; or
    • “head of household” or 1 for head of household filing status.

The input data frame, .data, can contain columns beyond those listed in the vignette. The additional columns will be ignored.

Marginal tax rates

By default, marginal tax rates are calculated using wages. The default can be changed with the marginal_tax_rates parameter to taxsim_calculate_taxes(). Possible options are: ‘Wages’ (default), ‘Long Term Capital Gains’, ‘Primary Wage Earner’, or ‘Secondary Wage Earner’.

Giving credit

The NBER’s TAXSIM 35 tax simulator does all tax calculations. This package simply lets users interact with the tax simulator through R. Therefore, users should cite the TAXSIM 35 tax simulator when they use this package in their work:

          Feenberg, Daniel Richard, and Elizabeth Coutts, An Introduction to the TAXSIM Model, Journal of Policy Analysis and Management vol 12 no 1, Winter 1993, pages 189-194.

Aman Gupta Karmani created the WebAssembly / JavaScript files. These files also power his tax calculator web app at taxsim.app.

Copy Link

Version

Install

install.packages('usincometaxes')

Monthly Downloads

195

Version

0.7.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Shane Orr

Last Published

January 11th, 2024

Functions in usincometaxes (0.7.1)

check_spouse

Ensure single taxpayers do not have spouse ages or income
taxsim_cols

Map input column names.
usincometaxes-package

usincometaxes: A package for calculating state and federal income taxes in the United States.
check_greater_zero

Check that columns are greater than zero
check_filing_status

Ensure values for filing status 'mstat' are proper.
create_dataset_for_taxsim

Convert a data frame to the TAXSIM 35 output.
convert_na

Convert NA values to either 0 or the proper state value
from_taxsim_cols

Map output column names.
get_state_soi

Get state SOI from state name.
check_state

Check state column
taxsim_calculate_taxes

Calculate state and federal taxes using TASXSIM 35.
calculate_taxes_wasm

Use WASM to calculate taxes locally
convert_marginal_tax_rates

Recode marginal tax rates.
check_taxsimid

Check that the taxsimid column is an integer and every value is unique.
check_required_cols

Ensure the required columns are present
check_data

Ensure input data set has required fields and data types are correct
check_numeric

Check numeric columns
check_parameters

Check input parameters
taxpayer_finances

Financial and household characteristics of 1,000 taxpayer units.
clean_from_taxsim

Clean final TAXSIM data set.