diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 00000000..f8c8dec2
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,36 @@
+# Claude Development Guidelines for microdf
+
+## Code Style
+- All files must end with a newline character
+- Run `make lint` before committing to catch style issues
+
+## Changelog Requirements
+- Every PR must include a `changelog_entry.yaml` file at the root
+- Format:
+ ```yaml
+ - bump: patch|minor|major
+ changes:
+ added|changed|removed|fixed:
+ - Description of change
+ ```
+- The file must not be empty and must end with a newline
+
+## Testing
+- Run tests with: `python3 -m pytest microdf/tests/ -v`
+- Ensure all tests pass before creating a PR
+
+## Pull Request Process
+1. Create a feature branch from master
+2. Make changes and ensure they follow code style guidelines
+3. Add a changelog entry
+4. Create PR with descriptive title and body
+5. PRs should close related issues using "Closes #XXX" in the body
+
+## Dependencies
+- Dependencies are managed in `pyproject.toml`
+- Optional dependencies go in `[project.optional-dependencies]`
+- When removing dependencies, also remove from `microdf/_optional.py` VERSIONS dict
+
+## Documentation
+- Documentation notebooks are in `docs/` directory
+- When removing functionality, consider impact on documentation examples
\ No newline at end of file
diff --git a/changelog_entry.yaml b/changelog_entry.yaml
index e69de29b..ce5c4f79 100644
--- a/changelog_entry.yaml
+++ b/changelog_entry.yaml
@@ -0,0 +1,7 @@
+- bump: minor
+ changes:
+ removed:
+ - Remove all taxcalc functionality and dependencies from the package.
+ - Delete taxcalc.py module and associated test file.
+ - Remove taxcalc from optional dependencies in pyproject.toml.
+ - Remove documentation notebooks that depend on taxcalc functionality.
diff --git a/docs/_toc.yml b/docs/_toc.yml
index 0ba84085..d7ff41ff 100644
--- a/docs/_toc.yml
+++ b/docs/_toc.yml
@@ -3,9 +3,4 @@ root: home
sections:
- file: examples
sections:
- - file: agg
- - file: custom_taxes
- - file: demo
- file: gini
- - file: income_measures
- - file: weighting
diff --git a/docs/agg.ipynb b/docs/agg.ipynb
deleted file mode 100644
index 76e250ba..00000000
--- a/docs/agg.ipynb
+++ /dev/null
@@ -1,417 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# The `agg` function\n",
- "\n",
- "Use `agg` to see the effect of a $10,000 UBI by marital status.\n",
- "\n",
- "## Setup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import taxcalc as tc\n",
- "import microdf as mdf"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'5.0.4'"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "tc.__version__"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Load data\n",
- "\n",
- "Start with a standard `DataFrame`, then add a UBI manually in a reform copy."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "base = mdf.calc_df(group_vars=['expanded_income', 'MARS', 'XTOT'],\n",
- " metric_vars='aftertax_income')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "reform = base.copy(deep=True)\n",
- "UBI_PP = 10000\n",
- "reform['ubi'] = reform.XTOT * UBI_PP\n",
- "reform['aftertax_income'] = reform.aftertax_income + reform.ubi\n",
- "mdf.add_weighted_metrics(reform, 'aftertax_income')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## `agg`\n",
- "\n",
- "### Change in aftertax income by marital status."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " aftertax_income_m_base | \n",
- " aftertax_income_m_reform | \n",
- " aftertax_income_pctchg | \n",
- "
\n",
- " \n",
- " | MARS | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 1.0 | \n",
- " 4.454948e+06 | \n",
- " 5.692781e+06 | \n",
- " 0.277856 | \n",
- "
\n",
- " \n",
- " | 2.0 | \n",
- " 8.086353e+06 | \n",
- " 1.007139e+07 | \n",
- " 0.245480 | \n",
- "
\n",
- " \n",
- " | 3.0 | \n",
- " 1.747066e+05 | \n",
- " 2.200549e+05 | \n",
- " 0.259568 | \n",
- "
\n",
- " \n",
- " | 4.0 | \n",
- " 1.082960e+06 | \n",
- " 1.584130e+06 | \n",
- " 0.462778 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " aftertax_income_m_base aftertax_income_m_reform aftertax_income_pctchg\n",
- "MARS \n",
- "1.0 4.454948e+06 5.692781e+06 0.277856\n",
- "2.0 8.086353e+06 1.007139e+07 0.245480\n",
- "3.0 1.747066e+05 2.200549e+05 0.259568\n",
- "4.0 1.082960e+06 1.584130e+06 0.462778"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.agg(base, reform, 'MARS', 'aftertax_income')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Also sum baseline `expanded_income`"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " aftertax_income_m_base | \n",
- " expanded_income | \n",
- " aftertax_income_m_reform | \n",
- " aftertax_income_pctchg | \n",
- "
\n",
- " \n",
- " | MARS | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 1.0 | \n",
- " 4.454948e+06 | \n",
- " 6.176263e+09 | \n",
- " 5.692781e+06 | \n",
- " 0.277856 | \n",
- "
\n",
- " \n",
- " | 2.0 | \n",
- " 8.086353e+06 | \n",
- " 1.429634e+10 | \n",
- " 1.007139e+07 | \n",
- " 0.245480 | \n",
- "
\n",
- " \n",
- " | 3.0 | \n",
- " 1.747066e+05 | \n",
- " 2.233541e+08 | \n",
- " 2.200549e+05 | \n",
- " 0.259568 | \n",
- "
\n",
- " \n",
- " | 4.0 | \n",
- " 1.082960e+06 | \n",
- " 1.362624e+09 | \n",
- " 1.584130e+06 | \n",
- " 0.462778 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " aftertax_income_m_base expanded_income aftertax_income_m_reform \\\n",
- "MARS \n",
- "1.0 4.454948e+06 6.176263e+09 5.692781e+06 \n",
- "2.0 8.086353e+06 1.429634e+10 1.007139e+07 \n",
- "3.0 1.747066e+05 2.233541e+08 2.200549e+05 \n",
- "4.0 1.082960e+06 1.362624e+09 1.584130e+06 \n",
- "\n",
- " aftertax_income_pctchg \n",
- "MARS \n",
- "1.0 0.277856 \n",
- "2.0 0.245480 \n",
- "3.0 0.259568 \n",
- "4.0 0.462778 "
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.agg(base, reform, 'MARS', 'aftertax_income', 'expanded_income')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Also sum UBI amount"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " aftertax_income_m_base | \n",
- " aftertax_income_m_reform | \n",
- " ubi_m | \n",
- " aftertax_income_pctchg | \n",
- "
\n",
- " \n",
- " | MARS | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 1.0 | \n",
- " 4.454948e+06 | \n",
- " 5.692781e+06 | \n",
- " 1.237833e+06 | \n",
- " 0.277856 | \n",
- "
\n",
- " \n",
- " | 2.0 | \n",
- " 8.086353e+06 | \n",
- " 1.007139e+07 | \n",
- " 1.985039e+06 | \n",
- " 0.245480 | \n",
- "
\n",
- " \n",
- " | 3.0 | \n",
- " 1.747066e+05 | \n",
- " 2.200549e+05 | \n",
- " 4.534831e+04 | \n",
- " 0.259568 | \n",
- "
\n",
- " \n",
- " | 4.0 | \n",
- " 1.082960e+06 | \n",
- " 1.584130e+06 | \n",
- " 5.011703e+05 | \n",
- " 0.462778 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " aftertax_income_m_base aftertax_income_m_reform ubi_m \\\n",
- "MARS \n",
- "1.0 4.454948e+06 5.692781e+06 1.237833e+06 \n",
- "2.0 8.086353e+06 1.007139e+07 1.985039e+06 \n",
- "3.0 1.747066e+05 2.200549e+05 4.534831e+04 \n",
- "4.0 1.082960e+06 1.584130e+06 5.011703e+05 \n",
- "\n",
- " aftertax_income_pctchg \n",
- "MARS \n",
- "1.0 0.277856 \n",
- "2.0 0.245480 \n",
- "3.0 0.259568 \n",
- "4.0 0.462778 "
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.add_weighted_metrics(reform, 'ubi') # Creates ubi_m = ubi * s006 / 1e6.\n",
- "\n",
- "mdf.agg(base, reform, 'MARS', 'aftertax_income', reform_metrics='ubi_m')"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "pe",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.11"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/docs/custom_taxes.ipynb b/docs/custom_taxes.ipynb
deleted file mode 100644
index e697e8a2..00000000
--- a/docs/custom_taxes.ipynb
+++ /dev/null
@@ -1,1053 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Custom taxes\n",
- "\n",
- "## Setup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import taxcalc as tc\n",
- "import microdf as mdf"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'5.0.4'"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "tc.__version__"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Load data\n",
- "\n",
- "Start with a `DataFrame` with `aftertax_income` and necessary ingredients of `tpc_eci`. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n",
- " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n",
- " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n",
- " 's006_m', 'XTOT_m'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df = mdf.calc_df(group_vars=['expanded_income', 'aftertax_income'] +\n",
- " mdf.ECI_REMOVE_COLS,\n",
- " metric_vars=['XTOT'])\n",
- "df.columns"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Calculate Tax Policy Center's Expanded Cash Income measure, used for the analysis."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "df['tpc_eci'] = mdf.tpc_eci(df)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Incidence of a VAT per Tax Policy Center."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n",
- " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n",
- " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n",
- " 's006_m', 'XTOT_m', 'tpc_eci', 'vat'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.add_vat(df)\n",
- "df.columns"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " mcaid_ben | \n",
- " tanf_ben | \n",
- " expanded_income | \n",
- " XTOT | \n",
- " snap_ben | \n",
- " s006 | \n",
- " vet_ben | \n",
- " e02400 | \n",
- " ssi_ben | \n",
- " mcare_ben | \n",
- " ... | \n",
- " aftertax_income | \n",
- " wic_ben | \n",
- " e02300 | \n",
- " market_income | \n",
- " bens | \n",
- " tax | \n",
- " s006_m | \n",
- " XTOT_m | \n",
- " tpc_eci | \n",
- " vat | \n",
- "
\n",
- " \n",
- " | RECID | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 192722 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " -303140.163141 | \n",
- " 2.0 | \n",
- " 0.0 | \n",
- " 381.90 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " ... | \n",
- " -299540.163141 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " -303140.163141 | \n",
- " 0.000000 | \n",
- " -3600.0 | \n",
- " 0.000382 | \n",
- " 0.000764 | \n",
- " -303140.163141 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " | 166558 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " -235938.542464 | \n",
- " 2.0 | \n",
- " 0.0 | \n",
- " 501.66 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " ... | \n",
- " -232338.542464 | \n",
- " 0.0 | \n",
- " 5188.764042 | \n",
- " -241127.306506 | \n",
- " 5188.764042 | \n",
- " -3600.0 | \n",
- " 0.000502 | \n",
- " 0.001003 | \n",
- " -235938.542464 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " | 12643 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " -169432.325500 | \n",
- " 1.0 | \n",
- " 0.0 | \n",
- " 414.87 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " ... | \n",
- " -167632.325500 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " -169432.325500 | \n",
- " 0.000000 | \n",
- " -1800.0 | \n",
- " 0.000415 | \n",
- " 0.000415 | \n",
- " -169432.325500 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " | 262111 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " -166304.985475 | \n",
- " 2.0 | \n",
- " 0.0 | \n",
- " 585.69 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " ... | \n",
- " -162704.985475 | \n",
- " 0.0 | \n",
- " 5724.820074 | \n",
- " -172029.805549 | \n",
- " 5724.820074 | \n",
- " -3600.0 | \n",
- " 0.000586 | \n",
- " 0.001171 | \n",
- " -166304.985475 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " | 12729 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " -158776.447320 | \n",
- " 1.0 | \n",
- " 0.0 | \n",
- " 304.88 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " 0.0 | \n",
- " ... | \n",
- " -156976.447320 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " -158776.447320 | \n",
- " 0.000000 | \n",
- " -1800.0 | \n",
- " 0.000305 | \n",
- " 0.000305 | \n",
- " -158776.447320 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
5 rows × 22 columns
\n",
- "
"
- ],
- "text/plain": [
- " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 vet_ben \\\n",
- "RECID \n",
- "192722 0.0 0.0 -303140.163141 2.0 0.0 381.90 0.0 \n",
- "166558 0.0 0.0 -235938.542464 2.0 0.0 501.66 0.0 \n",
- "12643 0.0 0.0 -169432.325500 1.0 0.0 414.87 0.0 \n",
- "262111 0.0 0.0 -166304.985475 2.0 0.0 585.69 0.0 \n",
- "12729 0.0 0.0 -158776.447320 1.0 0.0 304.88 0.0 \n",
- "\n",
- " e02400 ssi_ben mcare_ben ... aftertax_income wic_ben \\\n",
- "RECID ... \n",
- "192722 0.0 0.0 0.0 ... -299540.163141 0.0 \n",
- "166558 0.0 0.0 0.0 ... -232338.542464 0.0 \n",
- "12643 0.0 0.0 0.0 ... -167632.325500 0.0 \n",
- "262111 0.0 0.0 0.0 ... -162704.985475 0.0 \n",
- "12729 0.0 0.0 0.0 ... -156976.447320 0.0 \n",
- "\n",
- " e02300 market_income bens tax s006_m XTOT_m \\\n",
- "RECID \n",
- "192722 0.000000 -303140.163141 0.000000 -3600.0 0.000382 0.000764 \n",
- "166558 5188.764042 -241127.306506 5188.764042 -3600.0 0.000502 0.001003 \n",
- "12643 0.000000 -169432.325500 0.000000 -1800.0 0.000415 0.000415 \n",
- "262111 5724.820074 -172029.805549 5724.820074 -3600.0 0.000586 0.001171 \n",
- "12729 0.000000 -158776.447320 0.000000 -1800.0 0.000305 0.000305 \n",
- "\n",
- " tpc_eci vat \n",
- "RECID \n",
- "192722 -303140.163141 0.0 \n",
- "166558 -235938.542464 0.0 \n",
- "12643 -169432.325500 0.0 \n",
- "262111 -166304.985475 0.0 \n",
- "12729 -158776.447320 0.0 \n",
- "\n",
- "[5 rows x 22 columns]"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.head() # Note these are zero because we block negative tax liability."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " mcaid_ben | \n",
- " tanf_ben | \n",
- " expanded_income | \n",
- " XTOT | \n",
- " snap_ben | \n",
- " s006 | \n",
- " vet_ben | \n",
- " e02400 | \n",
- " ssi_ben | \n",
- " mcare_ben | \n",
- " ... | \n",
- " aftertax_income | \n",
- " wic_ben | \n",
- " e02300 | \n",
- " market_income | \n",
- " bens | \n",
- " tax | \n",
- " s006_m | \n",
- " XTOT_m | \n",
- " tpc_eci | \n",
- " vat | \n",
- "
\n",
- " \n",
- " | RECID | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 121269 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 91950.879154 | \n",
- " 2.0 | \n",
- " 0.000000 | \n",
- " 1030.13 | \n",
- " 0.0 | \n",
- " 39477.851082 | \n",
- " 8136.356254 | \n",
- " 14469.708379 | \n",
- " ... | \n",
- " 91695.524384 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 24687.942237 | \n",
- " 67262.936917 | \n",
- " 255.354770 | \n",
- " 0.001030 | \n",
- " 0.002060 | \n",
- " 77481.170775 | \n",
- " 3301.038878 | \n",
- "
\n",
- " \n",
- " | 113379 | \n",
- " 8801.561911 | \n",
- " 0.0 | \n",
- " 13400.315817 | \n",
- " 1.0 | \n",
- " 0.000000 | \n",
- " 1260.65 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 15200.315817 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 13400.315817 | \n",
- " -1800.000000 | \n",
- " 0.001261 | \n",
- " 0.001261 | \n",
- " 4598.753905 | \n",
- " 592.812317 | \n",
- "
\n",
- " \n",
- " | 263725 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 130030.151888 | \n",
- " 2.0 | \n",
- " 0.000000 | \n",
- " 408.48 | \n",
- " 0.0 | \n",
- " 59718.562813 | \n",
- " 0.000000 | \n",
- " 28940.650007 | \n",
- " ... | \n",
- " 132584.497393 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 41370.939069 | \n",
- " 88659.212820 | \n",
- " -2554.345505 | \n",
- " 0.000408 | \n",
- " 0.000817 | \n",
- " 101089.501882 | \n",
- " 4507.872911 | \n",
- "
\n",
- " \n",
- " | 50399 | \n",
- " 8801.561911 | \n",
- " 0.0 | \n",
- " 32464.654558 | \n",
- " 2.0 | \n",
- " 0.000000 | \n",
- " 457.48 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 38029.671397 | \n",
- " 0.0 | \n",
- " 2748.094474 | \n",
- " 16316.244268 | \n",
- " 16148.410290 | \n",
- " -5565.016839 | \n",
- " 0.000457 | \n",
- " 0.000915 | \n",
- " 23663.092647 | \n",
- " 1369.068170 | \n",
- "
\n",
- " \n",
- " | 220548 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 25110.711217 | \n",
- " 1.0 | \n",
- " 3234.713349 | \n",
- " 581.98 | \n",
- " 0.0 | \n",
- " 5513.641949 | \n",
- " 0.000000 | \n",
- " 14469.708379 | \n",
- " ... | \n",
- " 26910.711217 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 25110.711217 | \n",
- " -1800.000000 | \n",
- " 0.000582 | \n",
- " 0.000582 | \n",
- " 10641.002838 | \n",
- " 1049.517737 | \n",
- "
\n",
- " \n",
- "
\n",
- "
5 rows × 22 columns
\n",
- "
"
- ],
- "text/plain": [
- " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 \\\n",
- "RECID \n",
- "121269 0.000000 0.0 91950.879154 2.0 0.000000 1030.13 \n",
- "113379 8801.561911 0.0 13400.315817 1.0 0.000000 1260.65 \n",
- "263725 0.000000 0.0 130030.151888 2.0 0.000000 408.48 \n",
- "50399 8801.561911 0.0 32464.654558 2.0 0.000000 457.48 \n",
- "220548 0.000000 0.0 25110.711217 1.0 3234.713349 581.98 \n",
- "\n",
- " vet_ben e02400 ssi_ben mcare_ben ... \\\n",
- "RECID ... \n",
- "121269 0.0 39477.851082 8136.356254 14469.708379 ... \n",
- "113379 0.0 0.000000 0.000000 0.000000 ... \n",
- "263725 0.0 59718.562813 0.000000 28940.650007 ... \n",
- "50399 0.0 0.000000 0.000000 0.000000 ... \n",
- "220548 0.0 5513.641949 0.000000 14469.708379 ... \n",
- "\n",
- " aftertax_income wic_ben e02300 market_income bens \\\n",
- "RECID \n",
- "121269 91695.524384 0.0 0.000000 24687.942237 67262.936917 \n",
- "113379 15200.315817 0.0 0.000000 0.000000 13400.315817 \n",
- "263725 132584.497393 0.0 0.000000 41370.939069 88659.212820 \n",
- "50399 38029.671397 0.0 2748.094474 16316.244268 16148.410290 \n",
- "220548 26910.711217 0.0 0.000000 0.000000 25110.711217 \n",
- "\n",
- " tax s006_m XTOT_m tpc_eci vat \n",
- "RECID \n",
- "121269 255.354770 0.001030 0.002060 77481.170775 3301.038878 \n",
- "113379 -1800.000000 0.001261 0.001261 4598.753905 592.812317 \n",
- "263725 -2554.345505 0.000408 0.000817 101089.501882 4507.872911 \n",
- "50399 -5565.016839 0.000457 0.000915 23663.092647 1369.068170 \n",
- "220548 -1800.000000 0.000582 0.000582 10641.002838 1049.517737 \n",
- "\n",
- "[5 rows x 22 columns]"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.sample(5)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Add carbon tax and financial transaction tax."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n",
- " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n",
- " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n",
- " 's006_m', 'XTOT_m', 'tpc_eci', 'vat', 'carbon_tax', 'ftt'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.add_carbon_tax(df)\n",
- "mdf.add_ftt(df)\n",
- "df.columns"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " mcaid_ben | \n",
- " tanf_ben | \n",
- " expanded_income | \n",
- " XTOT | \n",
- " snap_ben | \n",
- " s006 | \n",
- " vet_ben | \n",
- " e02400 | \n",
- " ssi_ben | \n",
- " mcare_ben | \n",
- " ... | \n",
- " e02300 | \n",
- " market_income | \n",
- " bens | \n",
- " tax | \n",
- " s006_m | \n",
- " XTOT_m | \n",
- " tpc_eci | \n",
- " vat | \n",
- " carbon_tax | \n",
- " ftt | \n",
- "
\n",
- " \n",
- " | RECID | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 90662 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 28793.150170 | \n",
- " 1.0 | \n",
- " 0.000000 | \n",
- " 549.21 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 2.879315e+04 | \n",
- " 0.000000 | \n",
- " 3563.937374 | \n",
- " 0.000549 | \n",
- " 0.000549 | \n",
- " 28793.150170 | \n",
- " 908.251661 | \n",
- " 353.208979 | \n",
- " 25.229213 | \n",
- "
\n",
- " \n",
- " | 65944 | \n",
- " 8801.561911 | \n",
- " 0.0 | \n",
- " 53460.313714 | \n",
- " 1.0 | \n",
- " 434.350848 | \n",
- " 487.52 | \n",
- " 0.0 | \n",
- " 11987.175218 | \n",
- " 2992.95945 | \n",
- " 14469.708379 | \n",
- " ... | \n",
- " 0.0 | \n",
- " -7.275958e-12 | \n",
- " 53460.313714 | \n",
- " -1800.000000 | \n",
- " 0.000488 | \n",
- " 0.000488 | \n",
- " 22172.972610 | \n",
- " 2155.152235 | \n",
- " 663.123765 | \n",
- " 55.260314 | \n",
- "
\n",
- " \n",
- " | 71166 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 32369.951771 | \n",
- " 2.0 | \n",
- " 0.000000 | \n",
- " 706.99 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 3.236995e+04 | \n",
- " 0.000000 | \n",
- " -2521.089362 | \n",
- " 0.000707 | \n",
- " 0.001414 | \n",
- " 32369.951771 | \n",
- " 1256.077481 | \n",
- " 488.474576 | \n",
- " 34.891041 | \n",
- "
\n",
- " \n",
- " | 2393 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 31734.531431 | \n",
- " 1.0 | \n",
- " 0.000000 | \n",
- " 220.26 | \n",
- " 0.0 | \n",
- " 16905.662709 | \n",
- " 0.00000 | \n",
- " 14469.708379 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 3.591603e+02 | \n",
- " 31375.371088 | \n",
- " -1800.000000 | \n",
- " 0.000220 | \n",
- " 0.000220 | \n",
- " 17264.823052 | \n",
- " 1307.846726 | \n",
- " 402.414377 | \n",
- " 33.534531 | \n",
- "
\n",
- " \n",
- " | 10731 | \n",
- " 0.000000 | \n",
- " 0.0 | \n",
- " 131398.237894 | \n",
- " 2.0 | \n",
- " 0.000000 | \n",
- " 458.54 | \n",
- " 0.0 | \n",
- " 72074.842999 | \n",
- " 0.00000 | \n",
- " 28940.650007 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 3.038274e+04 | \n",
- " 101015.493006 | \n",
- " -3600.000000 | \n",
- " 0.000459 | \n",
- " 0.000917 | \n",
- " 102457.587887 | \n",
- " 4589.940088 | \n",
- " 2429.968282 | \n",
- " 269.996476 | \n",
- "
\n",
- " \n",
- "
\n",
- "
5 rows × 24 columns
\n",
- "
"
- ],
- "text/plain": [
- " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 \\\n",
- "RECID \n",
- "90662 0.000000 0.0 28793.150170 1.0 0.000000 549.21 \n",
- "65944 8801.561911 0.0 53460.313714 1.0 434.350848 487.52 \n",
- "71166 0.000000 0.0 32369.951771 2.0 0.000000 706.99 \n",
- "2393 0.000000 0.0 31734.531431 1.0 0.000000 220.26 \n",
- "10731 0.000000 0.0 131398.237894 2.0 0.000000 458.54 \n",
- "\n",
- " vet_ben e02400 ssi_ben mcare_ben ... e02300 \\\n",
- "RECID ... \n",
- "90662 0.0 0.000000 0.00000 0.000000 ... 0.0 \n",
- "65944 0.0 11987.175218 2992.95945 14469.708379 ... 0.0 \n",
- "71166 0.0 0.000000 0.00000 0.000000 ... 0.0 \n",
- "2393 0.0 16905.662709 0.00000 14469.708379 ... 0.0 \n",
- "10731 0.0 72074.842999 0.00000 28940.650007 ... 0.0 \n",
- "\n",
- " market_income bens tax s006_m XTOT_m \\\n",
- "RECID \n",
- "90662 2.879315e+04 0.000000 3563.937374 0.000549 0.000549 \n",
- "65944 -7.275958e-12 53460.313714 -1800.000000 0.000488 0.000488 \n",
- "71166 3.236995e+04 0.000000 -2521.089362 0.000707 0.001414 \n",
- "2393 3.591603e+02 31375.371088 -1800.000000 0.000220 0.000220 \n",
- "10731 3.038274e+04 101015.493006 -3600.000000 0.000459 0.000917 \n",
- "\n",
- " tpc_eci vat carbon_tax ftt \n",
- "RECID \n",
- "90662 28793.150170 908.251661 353.208979 25.229213 \n",
- "65944 22172.972610 2155.152235 663.123765 55.260314 \n",
- "71166 32369.951771 1256.077481 488.474576 34.891041 \n",
- "2393 17264.823052 1307.846726 402.414377 33.534531 \n",
- "10731 102457.587887 4589.940088 2429.968282 269.996476 \n",
- "\n",
- "[5 rows x 24 columns]"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.sample(5)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "VAT with a custom amount generated."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Multiplying tax by 1.08.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n",
- " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n",
- " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n",
- " 's006_m', 'XTOT_m', 'tpc_eci', 'vat', 'carbon_tax', 'ftt', 'vat2'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.add_vat(df, total=500e9, name='vat2')\n",
- "df.columns"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "464.5240745518526"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.weighted_sum(df, 'vat', 's006') / 1e9"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "500.0000000000001"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.weighted_sum(df, 'vat2', 's006') / 1e9"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Calculate by hand using `add_custom_tax`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Multiplying tax by 2.15.\n"
- ]
- }
- ],
- "source": [
- "mdf.add_custom_tax(df, 'tpc_eci', 'XTOT_m', 'aftertax_income', \n",
- " mdf.VAT_INCIDENCE, 'vat3', 1e12)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "1000.0000000000002"
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.weighted_sum(df, 'vat3', 's006') / 1e9"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "pe",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.11"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}
diff --git a/docs/demo.ipynb b/docs/demo.ipynb
deleted file mode 100644
index b9d10f1a..00000000
--- a/docs/demo.ipynb
+++ /dev/null
@@ -1,381 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# `microdf` demo"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Setup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import taxcalc as tc\n",
- "import microdf as mdf"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Generate data"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "base = mdf.calc_df(group_vars=['expanded_income', 'MARS'],\n",
- " metric_vars=['aftertax_income', 'XTOT'])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['vet_ben', 's006', 'tanf_ben', 'e02400', 'expanded_income', 'ssi_ben',\n",
- " 'wic_ben', 'aftertax_income', 'housing_ben', 'e02300', 'mcare_ben',\n",
- " 'XTOT', 'snap_ben', 'MARS', 'other_ben', 'mcaid_ben', 'market_income',\n",
- " 'bens', 'tax', 's006_m', 'XTOT_m', 'aftertax_income_m'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "base.columns"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Define a reform that treats capital gains as ordinary income and sets the top marginal rate to 70%."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "CG_REFORM = {\n",
- " 'CG_nodiff': {2019: True},\n",
- " 'II_rt7': {2019: 0.7}\n",
- "}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "reform = mdf.calc_df(reform=CG_REFORM, group_vars=['MARS'], group_n65=True, \n",
- " metric_vars=['aftertax_income', 'XTOT'])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['s006', 'ssi_ben', 'e02300', 'aftertax_income', 'mcare_ben',\n",
- " 'expanded_income', 'wic_ben', 'XTOT', 'MARS', 'mcaid_ben', 'vet_ben',\n",
- " 'tanf_ben', 'e02400', 'housing_ben', 'snap_ben', 'other_ben',\n",
- " 'market_income', 'bens', 'tax', 'n65', 's006_m', 'XTOT_m',\n",
- " 'aftertax_income_m'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "reform.columns"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Calculate senior UBI.\n",
- "\n",
- "Start with total revenue ($ billions)."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "337.44427805705"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "new_rev_m = base.aftertax_income_m.sum() - reform.aftertax_income_m.sum()\n",
- "new_rev_m / 1e3"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "How many seniors are there?"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "60.66105169000002"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.add_weighted_metrics(reform, 'n65')\n",
- "\n",
- "n65_total_m = reform.n65_m.sum()\n",
- "n65_total_m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Divide."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "5562.7831805738"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "senior_ubi = new_rev_m / reform.n65_m.sum()\n",
- "senior_ubi"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Add senior UBI to `aftertax_income` and recalculate"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [],
- "source": [
- "reform['ubi'] = senior_ubi * reform.n65\n",
- "reform['aftertax_income'] = reform.aftertax_income + reform.ubi\n",
- "mdf.add_weighted_metrics(reform, 'aftertax_income')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "True"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "np.allclose(base.aftertax_income_m.sum(), reform.aftertax_income_m.sum())"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Analyze\n",
- "\n",
- "Gini, FPL, distributional impact chart\n",
- "\n",
- "### Change to Gini index"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.4810691765589658"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.gini(base, 'aftertax_income', 's006')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.464648453442316"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.gini(reform, 'aftertax_income', 's006')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Change to poverty rate\n",
- "\n",
- "Add federal poverty line with `mdf.fpl`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [],
- "source": [
- "base['fpl'] = mdf.fpl(base.XTOT)\n",
- "reform['fpl'] = mdf.fpl(reform.XTOT)\n",
- "\n",
- "base['fpl_XTOT_m'] = np.where(base.aftertax_income < base.fpl,\n",
- " base.XTOT_m, 0)\n",
- "reform['fpl_XTOT_m'] = np.where(reform.aftertax_income < reform.fpl,\n",
- " reform.XTOT_m, 0)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "-0.04505398741648947"
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "reform.fpl_XTOT_m.sum() / base.fpl_XTOT_m.sum() - 1"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "pe",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.11"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/docs/income_measures.ipynb b/docs/income_measures.ipynb
deleted file mode 100644
index 65e7339c..00000000
--- a/docs/income_measures.ipynb
+++ /dev/null
@@ -1,360 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Income measures\n",
- "\n",
- "## Setup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import taxcalc as tc\n",
- "import microdf as mdf"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'2.3.0'"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "tc.__version__"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Load data\n",
- "\n",
- "Start with a `DataFrame` with `expanded_income` and the variables in `expanded_income` excluded from `tpc_eci`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "df = mdf.calc_df(group_vars=['expanded_income', 'wic_ben', 'housing_ben', \n",
- " 'vet_ben', 'mcare_ben', 'mcaid_ben'],\n",
- " metric_vars=['XTOT'])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Calculate `tpc_eci`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "df['tpc_eci'] = mdf.tpc_eci(df)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " snap_ben | \n",
- " vet_ben | \n",
- " mcaid_ben | \n",
- " mcare_ben | \n",
- " aftertax_income | \n",
- " e02300 | \n",
- " ssi_ben | \n",
- " wic_ben | \n",
- " s006 | \n",
- " expanded_income | \n",
- " ... | \n",
- " tanf_ben | \n",
- " other_ben | \n",
- " e02400 | \n",
- " XTOT | \n",
- " market_income | \n",
- " bens | \n",
- " tax | \n",
- " s006_m | \n",
- " XTOT_m | \n",
- " tpc_eci | \n",
- "
\n",
- " \n",
- " | RECID | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 1 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 43371.012504 | \n",
- " 0.0 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 250.14 | \n",
- " 53636.919015 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 2.0 | \n",
- " 53636.919015 | \n",
- " 0.000000 | \n",
- " 10265.906511 | \n",
- " 0.000250 | \n",
- " 0.000500 | \n",
- " 53636.919015 | \n",
- "
\n",
- " \n",
- " | 2 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 20937.886511 | \n",
- " 0.0 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 211.63 | \n",
- " 18650.034959 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- " 3.0 | \n",
- " 18650.034959 | \n",
- " 0.000000 | \n",
- " -2287.851553 | \n",
- " 0.000212 | \n",
- " 0.000635 | \n",
- " 18650.034959 | \n",
- "
\n",
- " \n",
- " | 3 | \n",
- " 1734.12939 | \n",
- " 0.0 | \n",
- " 8211.593627 | \n",
- " 13640.390612 | \n",
- " 52516.165397 | \n",
- " 0.0 | \n",
- " 3374.52239 | \n",
- " 0.0 | \n",
- " 323.50 | \n",
- " 52516.165397 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 6663.701623 | \n",
- " 13227.079816 | \n",
- " 1.0 | \n",
- " 0.000000 | \n",
- " 52516.165397 | \n",
- " 0.000000 | \n",
- " 0.000324 | \n",
- " 0.000324 | \n",
- " 24999.433219 | \n",
- "
\n",
- " \n",
- " | 4 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 8211.593627 | \n",
- " 0.000000 | \n",
- " 36857.709188 | \n",
- " 0.0 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 186.32 | \n",
- " 37764.286717 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 3906.542368 | \n",
- " 0.000000 | \n",
- " 2.0 | \n",
- " 25646.150723 | \n",
- " 12118.135995 | \n",
- " 906.577529 | \n",
- " 0.000186 | \n",
- " 0.000373 | \n",
- " 29552.693091 | \n",
- "
\n",
- " \n",
- " | 5 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 27280.781223 | \n",
- " 63941.158283 | \n",
- " 0.0 | \n",
- " 0.00000 | \n",
- " 0.0 | \n",
- " 343.08 | \n",
- " 63941.158283 | \n",
- " ... | \n",
- " 0.0 | \n",
- " 0.000000 | \n",
- " 35560.553286 | \n",
- " 2.0 | \n",
- " 1099.823774 | \n",
- " 62841.334509 | \n",
- " 0.000000 | \n",
- " 0.000343 | \n",
- " 0.000686 | \n",
- " 36660.377060 | \n",
- "
\n",
- " \n",
- "
\n",
- "
5 rows × 21 columns
\n",
- "
"
- ],
- "text/plain": [
- " snap_ben vet_ben mcaid_ben mcare_ben aftertax_income \\\n",
- "RECID \n",
- "1 0.00000 0.0 0.000000 0.000000 43371.012504 \n",
- "2 0.00000 0.0 0.000000 0.000000 20937.886511 \n",
- "3 1734.12939 0.0 8211.593627 13640.390612 52516.165397 \n",
- "4 0.00000 0.0 8211.593627 0.000000 36857.709188 \n",
- "5 0.00000 0.0 0.000000 27280.781223 63941.158283 \n",
- "\n",
- " e02300 ssi_ben wic_ben s006 expanded_income ... tanf_ben \\\n",
- "RECID ... \n",
- "1 0.0 0.00000 0.0 250.14 53636.919015 ... 0.0 \n",
- "2 0.0 0.00000 0.0 211.63 18650.034959 ... 0.0 \n",
- "3 0.0 3374.52239 0.0 323.50 52516.165397 ... 0.0 \n",
- "4 0.0 0.00000 0.0 186.32 37764.286717 ... 0.0 \n",
- "5 0.0 0.00000 0.0 343.08 63941.158283 ... 0.0 \n",
- "\n",
- " other_ben e02400 XTOT market_income bens \\\n",
- "RECID \n",
- "1 0.000000 0.000000 2.0 53636.919015 0.000000 \n",
- "2 0.000000 0.000000 3.0 18650.034959 0.000000 \n",
- "3 6663.701623 13227.079816 1.0 0.000000 52516.165397 \n",
- "4 3906.542368 0.000000 2.0 25646.150723 12118.135995 \n",
- "5 0.000000 35560.553286 2.0 1099.823774 62841.334509 \n",
- "\n",
- " tax s006_m XTOT_m tpc_eci \n",
- "RECID \n",
- "1 10265.906511 0.000250 0.000500 53636.919015 \n",
- "2 -2287.851553 0.000212 0.000635 18650.034959 \n",
- "3 0.000000 0.000324 0.000324 24999.433219 \n",
- "4 906.577529 0.000186 0.000373 29552.693091 \n",
- "5 0.000000 0.000343 0.000686 36660.377060 \n",
- "\n",
- "[5 rows x 21 columns]"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.head()"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.7.3"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/docs/weighting.ipynb b/docs/weighting.ipynb
deleted file mode 100644
index e7c71b72..00000000
--- a/docs/weighting.ipynb
+++ /dev/null
@@ -1,482 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Weighting in taxcalc_helpers\n",
- "\n",
- "## Setup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import taxcalc as tc\n",
- "import microdf as mdf"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'3.0.0'"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "tc.__version__"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Load data\n",
- "\n",
- "Start with a `DataFrame` with `nu18` and `XTOT`, and also calculate `XTOT_m`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Index(['s006', 'other_ben', 'snap_ben', 'aftertax_income', 'mcaid_ben',\n",
- " 'mcare_ben', 'ssi_ben', 'e02300', 'nu18', 'expanded_income',\n",
- " 'housing_ben', 'vet_ben', 'wic_ben', 'e02400', 'tanf_ben', 'XTOT',\n",
- " 'market_income', 'bens', 'tax', 's006_m', 'XTOT_m'],\n",
- " dtype='object')"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df = mdf.calc_df(group_vars=['nu18'], metric_vars=['XTOT'])\n",
- "df.columns"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "From this we can calculate the number of people and tax units by the tax unit's number of children."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " s006_m | \n",
- " XTOT_m | \n",
- "
\n",
- " \n",
- " | nu18 | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0.0 | \n",
- " 152.988772 | \n",
- " 209.816367 | \n",
- "
\n",
- " \n",
- " | 1.0 | \n",
- " 22.688253 | \n",
- " 54.115850 | \n",
- "
\n",
- " \n",
- " | 2.0 | \n",
- " 18.859945 | \n",
- " 68.880292 | \n",
- "
\n",
- " \n",
- " | 3.0 | \n",
- " 7.438481 | \n",
- " 34.795527 | \n",
- "
\n",
- " \n",
- " | 4.0 | \n",
- " 2.371111 | \n",
- " 13.539261 | \n",
- "
\n",
- " \n",
- " | 5.0 | \n",
- " 0.744276 | \n",
- " 5.015182 | \n",
- "
\n",
- " \n",
- " | 6.0 | \n",
- " 0.216158 | \n",
- " 1.688063 | \n",
- "
\n",
- " \n",
- " | 7.0 | \n",
- " 0.090332 | \n",
- " 0.790239 | \n",
- "
\n",
- " \n",
- " | 8.0 | \n",
- " 0.026501 | \n",
- " 0.258552 | \n",
- "
\n",
- " \n",
- " | 9.0 | \n",
- " 0.012238 | \n",
- " 0.134320 | \n",
- "
\n",
- " \n",
- " | 10.0 | \n",
- " 0.007196 | \n",
- " 0.084201 | \n",
- "
\n",
- " \n",
- " | 12.0 | \n",
- " 0.000265 | \n",
- " 0.003715 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " s006_m XTOT_m\n",
- "nu18 \n",
- "0.0 152.988772 209.816367\n",
- "1.0 22.688253 54.115850\n",
- "2.0 18.859945 68.880292\n",
- "3.0 7.438481 34.795527\n",
- "4.0 2.371111 13.539261\n",
- "5.0 0.744276 5.015182\n",
- "6.0 0.216158 1.688063\n",
- "7.0 0.090332 0.790239\n",
- "8.0 0.026501 0.258552\n",
- "9.0 0.012238 0.134320\n",
- "10.0 0.007196 0.084201\n",
- "12.0 0.000265 0.003715"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.groupby('nu18')[['s006_m', 'XTOT_m']].sum()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "What if we also want to calculate the total number of *children* by the tax unit's number of children?\n",
- "\n",
- "For this we can use `add_weighted_metrics`, the function called within `calc_df`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "mdf.add_weighted_metrics(df, ['nu18'])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Now we can do the same thing as before, with the new `nu18_m` column."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " nu18_m | \n",
- "
\n",
- " \n",
- " | nu18 | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0.0 | \n",
- " 0.000000 | \n",
- "
\n",
- " \n",
- " | 1.0 | \n",
- " 22.688253 | \n",
- "
\n",
- " \n",
- " | 2.0 | \n",
- " 37.719889 | \n",
- "
\n",
- " \n",
- " | 3.0 | \n",
- " 22.315444 | \n",
- "
\n",
- " \n",
- " | 4.0 | \n",
- " 9.484444 | \n",
- "
\n",
- " \n",
- " | 5.0 | \n",
- " 3.721381 | \n",
- "
\n",
- " \n",
- " | 6.0 | \n",
- " 1.296949 | \n",
- "
\n",
- " \n",
- " | 7.0 | \n",
- " 0.632325 | \n",
- "
\n",
- " \n",
- " | 8.0 | \n",
- " 0.212008 | \n",
- "
\n",
- " \n",
- " | 9.0 | \n",
- " 0.110139 | \n",
- "
\n",
- " \n",
- " | 10.0 | \n",
- " 0.071958 | \n",
- "
\n",
- " \n",
- " | 12.0 | \n",
- " 0.003184 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " nu18_m\n",
- "nu18 \n",
- "0.0 0.000000\n",
- "1.0 22.688253\n",
- "2.0 37.719889\n",
- "3.0 22.315444\n",
- "4.0 9.484444\n",
- "5.0 3.721381\n",
- "6.0 1.296949\n",
- "7.0 0.632325\n",
- "8.0 0.212008\n",
- "9.0 0.110139\n",
- "10.0 0.071958\n",
- "12.0 0.003184"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.groupby('nu18')[['nu18_m']].sum()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We can also calculate weighted sums without adding the weighted metric."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Total children: 98M.'"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "total_children = mdf.weighted_sum(df, 'nu18', 's006')\n",
- "# Fix this decimal.\n",
- "'Total children: ' + str(round(total_children / 1e6)) + 'M.'"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We can also calculate the weighted mean and median."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.4782626894263673"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "mdf.weighted_mean(df, 'nu18', 's006')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "ename": "TypeError",
- "evalue": "weighted_quantile() missing 1 required positional argument: 'quantiles'",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
- "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweighted_median\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'nu18'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m's006'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/microdf/weighted.py\u001b[0m in \u001b[0;36mweighted_median\u001b[0;34m(df, col, w)\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 85\u001b[0m \"\"\"\n\u001b[0;32m---> 86\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mweighted_quantile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcol\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mw\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 87\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;31mTypeError\u001b[0m: weighted_quantile() missing 1 required positional argument: 'quantiles'"
- ]
- }
- ],
- "source": [
- "mdf.weighted_median(df, 'nu18', 's006')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We can also look at more quantiles.\n",
- "\n",
- "*Note that weighted quantiles have a different interface.*"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "decile_bounds = np.arange(0, 1.1, 0.1)\n",
- "deciles = mdf.weighted_quantile(df, 'nu18', 's006', decile_bounds)\n",
- "pd.DataFrame(deciles, index=decile_bounds)"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.7.9"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/microdf/__init__.py b/microdf/__init__.py
index ec8e8585..905bca37 100644
--- a/microdf/__init__.py
+++ b/microdf/__init__.py
@@ -47,13 +47,6 @@
squared_poverty_gap,
)
from .tax import mtr, tax_from_mtrs
-from .taxcalc import (
- add_weighted_metrics,
- calc_df,
- n65,
- recalculate,
- static_baseline_calc,
-)
from .ubi import ubi_or_bens
from .utils import (
cartesian_product,
@@ -129,12 +122,6 @@
# tax.py
"mtr",
"tax_from_mtrs",
- # taxcalc.py
- "static_baseline_calc",
- "add_weighted_metrics",
- "n65",
- "calc_df",
- "recalculate",
# ubi.py
"ubi_or_bens",
# utils.py
diff --git a/microdf/_optional.py b/microdf/_optional.py
index 86ebdf93..3d795745 100644
--- a/microdf/_optional.py
+++ b/microdf/_optional.py
@@ -7,9 +7,7 @@
# Adapted from:
# https://github.com/pandas-dev/pandas/blob/master/pandas/compat/_optional.py
-VERSIONS = {
- "taxcalc": "2.0.0",
-}
+VERSIONS = {}
def _get_version(module: types.ModuleType) -> str:
diff --git a/microdf/taxcalc.py b/microdf/taxcalc.py
deleted file mode 100644
index 84b4ad3b..00000000
--- a/microdf/taxcalc.py
+++ /dev/null
@@ -1,161 +0,0 @@
-from typing import Optional
-
-import pandas as pd
-import taxcalc
-
-import microdf as mdf
-from microdf._optional import import_optional_dependency
-
-
-def static_baseline_calc(
- recs: pd.DataFrame, year: int
-) -> "taxcalc.Calculator":
- """Creates a static Calculator object.
-
- :param recs: Records object.
- :param year: Year to advance to.
- :returns: Calculator object.
- """
- tc = import_optional_dependency("taxcalc")
- calc = tc.Calculator(records=recs, policy=tc.Policy())
- calc.advance_to_year(year)
- calc.calc_all()
- return calc
-
-
-def add_weighted_metrics(
- df: pd.DataFrame,
- metric_vars: list,
- w: str = "s006",
- divisor: float = 1e6,
- suffix: str = "_m",
-) -> None:
- """Adds weighted metrics in millions to a Tax-Calculator pandas DataFrame.
-
- Columns are renamed to *_m.
-
- :param df: A pandas DataFrame containing Tax-Calculator data.
- :param metric_vars: A list of column names to weight, or a single column
- name.
- :param w: Weight column. Defaults to s006.
- :param divisor: Number by which the product is divided. Defaults to 1e6.
- :param suffix: Suffix to add to each weighted total. Defaults to '_m' to
- match divisor default of 1e6.
- :returns: Nothing. Weighted columns are added in place.
- """
- df[w + suffix] = df[w] / divisor
- metric_vars = mdf.listify(metric_vars)
- for metric_var in metric_vars:
- df[metric_var + suffix] = df[metric_var] * df[w + suffix]
-
-
-def n65(
- age_head: pd.Series, age_spouse: pd.Series, elderly_dependents: pd.Series
-) -> pd.Series:
- """Calculates number of people in the tax unit age 65 or older.
-
- :param age_head: Series representing age_head from taxcalc data.
- :param age_spouse: Series representing age_spouse from taxcalc data.
- :param elderly_dependents: Series representing elderly_dependents from
- taxcalc data.
- :returns: Series representing the number of people age 65 or older.
- """
- return (
- (age_head >= 65).astype(int)
- + (age_spouse >= 65).astype(int)
- + elderly_dependents
- )
-
-
-def calc_df(
- records: Optional[pd.DataFrame] = None,
- policy: Optional[taxcalc.Policy] = None,
- year: int = 2020,
- reform: Optional[dict] = None,
- group_vars: Optional[list] = None,
- metric_vars: Optional[list] = None,
- group_n65: Optional[bool] = False,
-) -> pd.DataFrame:
- """Creates a pandas DataFrame for given Tax-Calculator data.
-
- s006 is always included, and RECID is used as an index.
-
- :param records: An optional Records object. If not provided, uses CPS
- records. (Default value = None)
- :param policy: An optional Policy object. If not provided, uses default
- Policy.
- :param year: An optional year to advance to. If not provided, defaults to
- 2020.
- :param reform: An optional reform to implement for the Policy object.
- (Default value = None)
- :param group_vars: An optional list of column names to include in the
- DataFrame. (Default value = None)
- :param metric_vars: An optional list of column names to include and
- calculate weighted sums of (in millions named as *_m) in the DataFrame.
- (Default value = None)
- :param group_n65: Whether to calculate and group by n65. Defaults to False.
- :returns: A pandas DataFrame. market_income is also always calculated.
- """
- tc = import_optional_dependency("taxcalc")
- # Assign defaults.
- if records is None:
- records = tc.Records.cps_constructor()
- if policy is None:
- policy = tc.Policy()
- if reform is not None:
- policy.implement_reform(reform)
- # Calculate.
- calc = tc.Calculator(records=records, policy=policy, verbose=False)
- calc.advance_to_year(year)
- calc.calc_all()
- # Get a deduplicated list of all columns.
- if group_n65:
- group_vars = group_vars + [
- "age_head",
- "age_spouse",
- "elderly_dependents",
- ]
- # Include expanded_income and benefits to produce market_income.
- all_cols = mdf.listify(
- [
- "RECID",
- "s006",
- "expanded_income",
- "aftertax_income",
- mdf.BENS,
- group_vars,
- metric_vars,
- ]
- )
- df = calc.dataframe(all_cols)
- # Create core elements.
- df["market_income"] = mdf.market_income(df)
- df["bens"] = df[mdf.BENS].sum(axis=1)
- df["tax"] = df.expanded_income - df.aftertax_income
- if group_n65:
- df["n65"] = n65(df.age_head, df.age_spouse, df.elderly_dependents)
- df.drop(
- ["age_head", "age_spouse", "elderly_dependents"],
- axis=1,
- inplace=True,
- )
- # Add calculated columns for metrics.
- mdf.add_weighted_metrics(df, metric_vars)
- # Set RECID to int and set it as index before returning.
- df["RECID"] = df.RECID.map(int)
- return df.set_index("RECID")
-
-
-def recalculate(df: pd.DataFrame) -> None:
- """Recalculates fields in the DataFrame for after components have changed.
-
- :param df: DataFrame for use in microdf.
- :returns: Nothing. Updates the DataFrame in place.
- """
- # Recalculate TPC's Expanded Cash Income measure.
- cols = df.columns
- if "tpc_eci" in cols:
- df.tpc_eci = mdf.tpc_eci(df)
- # Recalculate weighted metrics (anything ending in _m).
- mcols = cols[cols.str.endswith("_m")]
- mdf.add_weighted_metrics(df, mcols)
diff --git a/microdf/tests/test_taxcalc.py b/microdf/tests/test_taxcalc.py
deleted file mode 100644
index 96c670ba..00000000
--- a/microdf/tests/test_taxcalc.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import pytest
-
-import microdf as mdf
-
-try:
- import taxcalc as tc
-
- _HAVE_TAXCALC = True
-except ImportError:
- _HAVE_TAXCALC = False
-
-
-def test_calc_df() -> None:
- """"""
- if not _HAVE_TAXCALC:
- pytest.skip("taxcalc is not installed")
- mdf.calc_df()
-
-
-def test_static_baseline_calc() -> None:
- """"""
- if not _HAVE_TAXCALC:
- pytest.skip("taxcalc is not installed")
- recs = tc.Records.cps_constructor()
- mdf.static_baseline_calc(recs, 2020)
diff --git a/pyproject.toml b/pyproject.toml
index 25fc2908..730d755b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -34,9 +34,6 @@ dev = [
docs = [
"jupyter_book",
]
-taxcalc = [
- "taxcalc",
-]
[tool.setuptools.packages.find]
where = ["."]