Title: | Calculate Federal and State Income Taxes in the United States |
Version: | 0.7.1 |
Description: | Calculates federal and state income taxes in the United States. It acts as a wrapper to the NBER's TAXSIM 35 (http://taxsim.nber.org/taxsim35/) tax simulator. TAXSIM 35 conducts the calculations, while 'usincometaxes' prepares the data for TAXSIM 35, sends the data to TAXSIM 35's server or communicates with the Web Assembly file, retrieves the data, and places it into a data frame. All without the user worrying about this process. |
License: | MIT + file LICENSE |
URL: | https://github.com/shanejorr/usincometaxes, https://shaneorr.io/r/usincometaxes |
BugReports: | https://github.com/shanejorr/usincometaxes/issues |
Depends: | R (≥ 3.1) |
Imports: | datasets, vroom, tibble, utils, V8 |
Suggests: | dplyr, ggplot2, knitr, rmarkdown, scales, testthat (≥ 3.0.0), tidyr, tools |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2024-01-11 23:24:19 UTC; shaneorr |
Author: | Shane Orr [aut, cre, cph], Thomas Wells [ctb] |
Maintainer: | Shane Orr <shane.j.orr@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-01-11 23:40:03 UTC |
usincometaxes: A package for calculating state and federal income taxes in the United States.
Description
The usincometaxes
package is a single function packages that calculates state and federal income
taxes in the United State. It relies on the NBER's TAXSIM 35 tax calculator for the calculations.
See https://taxsim.nber.org/taxsim35/ for more information on TAXSIM 35.
Author(s)
Maintainer: Shane Orr shane.j.orr@gmail.com [copyright holder]
Other contributors:
Thomas Wells thomascwells@gmail.com [contributor]
See Also
Useful links:
Report bugs at https://github.com/shanejorr/usincometaxes/issues
Use WASM to calculate taxes locally
Description
Use WASM to calculate taxes locally
Usage
calculate_taxes_wasm(.data)
Arguments
.data |
Dataset that can be sent to WASM. |
Ensure input data set has required fields and data types are correct
Description
Check to ensure all the required column are present and data types are correct. This function binds all the checks through helper functions.
Usage
check_data(.data, cols, state_column_name)
Arguments
.data |
A data frame containing the input parameters for the TAXSIM 35 program. The column names of the input parameters are below. The column can be in any order. |
cols |
The column names, as a string, in the data set |
state_column_name |
The column name of the state column. |
Value
The function does not return a value. It either produces a stop message with the error or prints that all checks were successful.
Ensure values for filing status 'mstat' are proper.
Description
Ensure values for filing status 'mstat' are proper.
Usage
check_filing_status(filing_status_vector)
Arguments
filing_status_vector |
Column, as a vector, containing filing status |
Check that columns are greater than zero
Description
Some columns must have all values greater than zero. Check to make sure this is true.
Usage
check_greater_zero(.data, cols)
Arguments
.data |
A data frame containing the input parameters for the TAXSIM 35 program. The column names of the input parameters are below. The column can be in any order. |
cols |
The column names, as a string, in the data set |
Check numeric columns
Description
Checks that each column which should be numeric or integer is numeric or integer.
Usage
check_numeric(.data, cols)
Arguments
.data |
A data frame containing the input parameters for the TAXSIM 35 program. The column names of the input parameters are below. The column can be in any order. |
cols |
The column names, as a string, in the data set |
Check input parameters
Description
Check that the input parameters to taxsim_calculate_taxes
are of the proper type
The parameters to this function should be the same as those to taxsim_calculate_taxes
Usage
check_parameters(.data, marginal_tax_rates, return_all_information)
Ensure the required columns are present
Description
Ensure the required columns are present
Usage
check_required_cols(cols)
Arguments
cols |
The column names, as a string, in the data set |
Ensure single taxpayers do not have spouse ages or income
Description
Ensure single taxpayers do not have spouse ages or income
Usage
check_spouse(.data, cols)
Arguments
.data |
A data frame containing the input parameters for the TAXSIM 35 program. The column names of the input parameters are below. The column can be in any order. |
cols |
The column names, as a string, in the data set |
Check state column
Description
State should be either a two letter abbreviation or full state name. Check to make sure this is true.
Usage
check_state(.data, cols, state_column_name)
Arguments
.data |
A data frame containing the input parameters for the TAXSIM 35 program. The column names of the input parameters are below. The column can be in any order. |
cols |
The column names, as a string, in the data set |
state_column_name |
The column name of the state column. |
Check that the taxsimid
column is an integer and every value is unique.
Description
The taxsimid
column requires a whole number and unique value. Check to make sure this is true.
Usage
check_taxsimid(taxsimid_col)
Arguments
taxsimid_col |
Vector that id the |
Clean final TAXSIM data set.
Description
Clean the data set received from TAXSIM by renaming columns and removing columns not needed in the final output.
Usage
clean_from_taxsim(from_taxsim)
Arguments
from_taxsim |
The data set received from TAXSIM. |
Value
Data frame containing the row's taxsimid
and tax calculations. This data frame can be
merged with the original input data frame by taxsimid
.
Recode marginal tax rates.
Description
Marginal tax rates are specified with the marginal_tax_rates
parameter. The possible values are
descriptive strings. But,TAXSIM requires integers. Convert descriptive strings to integers.
Usage
convert_marginal_tax_rates(marginal_tax_rate)
Arguments
marginal_tax_rate |
String representing the |
Convert NA values to either 0 or the proper state value
Description
Convert NA values to either 0 or the proper state value
Usage
convert_na(.data, cols_to_convert)
Convert a data frame to the TAXSIM 35 output.
Description
This function takes a data set that is in the format required for taxsim_calculate_taxes
,
checks it to make sure it is in the proper format for TAXSIM 35, and then cleans so it can be sent to TAXSIM 35.
This function is useful for troubleshooting. It is not needed to calculate taxes. The function is useful
if you continue receiving unreasonable errors from taxsim_calculate_taxes
. In such as case,
you can run this function on your data set. You should then save the resulting
data frame as a csv file. Then, upload the file to TAXSIM 35.
Usage
create_dataset_for_taxsim(.data)
Arguments
.data |
Data frame containing the information that will be used to calculate taxes. This data set will be sent to TAXSIM. Data frame must have specified column names and data types. |
Details
create_dataset_for_taxsim
takes the same columns as column names as TAXSIM 35.
Value
A data frame that that can be manually uploaded to TAXSIM 35.
Examples
family_income <- data.frame(
taxsimid = c(1, 2),
state = c('North Carolina', 'NY'),
year = c(2015, 2015),
mstat = c('single', 'married, jointly'),
pwages = c(10000, 100000),
page = c(26, 36)
)
family_taxes <- create_dataset_for_taxsim(family_income)
Map output column names.
Description
Map the output column names required in this package to the input column names required by TAXSIM.
Usage
from_taxsim_cols()
Get state SOI from state name.
Description
Converts state names or state abbreviations to numeric SOI codes, which are required for TAXSIM.
Usage
get_state_soi(state_column)
Arguments
state_column |
Vectors containing the states to calculate taxes for. Generally, this is the state column from the data set that will be sent to TAXSIM. |
Value
Named integer vector with each number between 1 and 51 representing the state's SOI. Names are the state's two letter abbreviation.
Financial and household characteristics of 1,000 taxpayer units.
Description
A data set containing financial and household characteristics of 1,000 taxpayer units.
The data set was randomly generated and does not reflect real data.
It is formatted and ready for use in the usincometaxes
package.
Usage
taxpayer_finances
Format
A data frame with 1,000 rows and 16 variables. Variable definitions can be found in the following article: https://www.shaneorr.io/r/usincometaxes/articles/taxsim-input.html
Source
Created through random data generation.
Calculate state and federal taxes using TASXSIM 35.
Description
This function calculates state and federal income taxes using the TAXSIM 35 tax simulator. See http://taxsim.nber.org/taxsim35/ for more information on TAXSIM 35. The function uses a compiled WebAssembly (wasm) version of the TAXSIM app that is part of the package to calculate taxes. Details about generating the wasm file can be found here: https://github.com/tmm1/taxsim.js
Usage
taxsim_calculate_taxes(
.data,
marginal_tax_rates = "Wages",
return_all_information = FALSE
)
Arguments
.data |
Data frame containing the information that will be used to calculate taxes. This data set will be sent to TAXSIM. Data frame must have specified column names and data types. |
marginal_tax_rates |
Variable to use when calculating marginal tax rates. One of 'Wages', 'Long Term Capital Gains', 'Primary Wage Earner', or 'Secondary Wage Earner'. Default is 'Wages'. |
return_all_information |
Boolean (TRUE or FALSE). Whether to return all information from TAXSIM (TRUE), or only key information (FALSE). Returning all information returns 42 columns of output, while only returning key information returns 9 columns. It is faster to download results with only key information. |
Value
The output data set contains all the information returned by TAXSIM 35, using the same column names. Descriptions of these columns can be found at the bottom of the page containing TAXSIM 35's documentation.
Formatting your data
In the input data set, .data
, each column is a tax characteristic (year, filing status, income, etc.)
and each row is a tax filing unit.
Columns should take the same names, and fulfill the same requirements, as those needed for TAXSIM 35. Potential columns, with there names and descriptions, can be found at: http://taxsim.nber.org/taxsim35/.
The following columns are required: taxsimid
, year
, mstat
, and state
.
There are two points where taxsim_calculate_taxes
departs from TAXSIM 35.
For filing status,
mstat
, users can either enter the number allowed by TAXSIM 35 or one of the following descriptions:
"single"
"married, jointly"
"married, separately"
"dependent child"
"head of household"
For
state
, users can either enter the SOI code, as required by TAXSIM 35, the two-letter state abbreviation, or the full name of the state.
It is OK if the input data set, .data
, contains columns in addition to the ones that are used by TAXSIM 35.
Giving credit where it is due
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 TASXSIM 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.
Examples
family_income <- data.frame(
taxsimid = c(1, 2),
state = c('North Carolina', 'NY'),
year = c(2015, 2015),
mstat = c('single', 'married, jointly'),
pwages = c(10000, 100000),
page = c(26, 36)
)
family_taxes <- taxsim_calculate_taxes(family_income)
merge(family_income, family_taxes, by = 'taxsimid')
Map input column names.
Description
Map the input column names required in this package to the input column names required by TAXSIM.
Usage
taxsim_cols()