Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial 40% with funding raised #4

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 295 additions & 0 deletions blank_slate/blank_slate.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "OpenFiscaUS-blankSlate.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"id": "v-FZwIiWh_kx",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "aad1d442-8d98-4297-92b6-7466b72f1f57"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: openfisca-us in /usr/local/lib/python3.7/dist-packages (0.66.1)\n",
"Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (1.3.5)\n",
"Requirement already satisfied: h5py in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (3.1.0)\n",
"Requirement already satisfied: tables in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (3.7.0)\n",
"Requirement already satisfied: pathlib in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (1.0.1)\n",
"Requirement already satisfied: pytest in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (5.4.3)\n",
"Requirement already satisfied: pytest-dependency in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.5.1)\n",
"Requirement already satisfied: synthimpute in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.1)\n",
"Requirement already satisfied: OpenFisca-Core[web-api]>=35.0.0 in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (35.8.1)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (3.13)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (4.64.0)\n",
"Requirement already satisfied: OpenFisca-Tools<1.0.0,>=0.8.0 in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.10.4)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (2.23.0)\n",
"Requirement already satisfied: microdf-python in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.3.0)\n",
"Requirement already satisfied: numpy<1.21,>=1.11 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.20.3)\n",
"Requirement already satisfied: numexpr<=3.0,>=2.7.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.8.1)\n",
"Requirement already satisfied: typing-extensions==3.10.0.2 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.10.0.2)\n",
"Requirement already satisfied: nptyping==1.4.4 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.4.4)\n",
"Requirement already satisfied: sortedcontainers==2.2.2 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.2.2)\n",
"Requirement already satisfied: dpath<3.0.0,>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.0.6)\n",
"Requirement already satisfied: psutil<6.0.0,>=5.4.7 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (5.4.8)\n",
"Requirement already satisfied: markupsafe==2.0.1 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.0.1)\n",
"Requirement already satisfied: flask-cors==3.0.10 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.0.10)\n",
"Requirement already satisfied: werkzeug<2.0.0,>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.0.1)\n",
"Requirement already satisfied: gunicorn<21.0.0,>=20.0.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (20.1.0)\n",
"Requirement already satisfied: flask==1.1.4 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.1.4)\n",
"Requirement already satisfied: click<8.0,>=5.1 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (7.1.2)\n",
"Requirement already satisfied: Jinja2<3.0,>=2.10.1 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.11.3)\n",
"Requirement already satisfied: itsdangerous<2.0,>=0.24 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.1.0)\n",
"Requirement already satisfied: Six in /usr/local/lib/python3.7/dist-packages (from flask-cors==3.0.10->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.15.0)\n",
"Requirement already satisfied: typish>=1.7.0 in /usr/local/lib/python3.7/dist-packages (from nptyping==1.4.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.9.3)\n",
"Requirement already satisfied: setuptools>=3.0 in /usr/local/lib/python3.7/dist-packages (from gunicorn<21.0.0,>=20.0.0->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (57.4.0)\n",
"Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from numexpr<=3.0,>=2.7.0->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (21.3)\n",
"Requirement already satisfied: google-cloud-storage in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (1.18.1)\n",
"Requirement already satisfied: wheel in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (0.37.1)\n",
"Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (8.13.0)\n",
"Requirement already satisfied: pluggy<1.0,>=0.12 in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (0.13.1)\n",
"Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (1.11.0)\n",
"Requirement already satisfied: importlib-metadata>=0.12 in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (4.11.3)\n",
"Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (21.4.0)\n",
"Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from pytest->openfisca-us) (0.2.5)\n",
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=0.12->pytest->openfisca-us) (3.8.0)\n",
"Requirement already satisfied: google-resumable-media<0.5.0dev,>=0.3.1 in /usr/local/lib/python3.7/dist-packages (from google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (0.4.1)\n",
"Requirement already satisfied: google-cloud-core<2.0dev,>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (1.0.3)\n",
"Requirement already satisfied: google-auth>=1.2.0 in /usr/local/lib/python3.7/dist-packages (from google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (1.35.0)\n",
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.7/dist-packages (from google-auth>=1.2.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (0.2.8)\n",
"Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from google-auth>=1.2.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (4.2.4)\n",
"Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.7/dist-packages (from google-auth>=1.2.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (4.8)\n",
"Requirement already satisfied: google-api-core<2.0.0dev,>=1.14.0 in /usr/local/lib/python3.7/dist-packages (from google-cloud-core<2.0dev,>=1.0.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (1.31.5)\n",
"Requirement already satisfied: googleapis-common-protos<2.0dev,>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from google-api-core<2.0.0dev,>=1.14.0->google-cloud-core<2.0dev,>=1.0.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (1.56.1)\n",
"Requirement already satisfied: protobuf>=3.12.0 in /usr/local/lib/python3.7/dist-packages (from google-api-core<2.0.0dev,>=1.14.0->google-cloud-core<2.0dev,>=1.0.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (3.17.3)\n",
"Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from google-api-core<2.0.0dev,>=1.14.0->google-cloud-core<2.0dev,>=1.0.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (2022.1)\n",
"Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->numexpr<=3.0,>=2.7.0->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.0.9)\n",
"Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.7/dist-packages (from pyasn1-modules>=0.2.1->google-auth>=1.2.0->google-cloud-storage->OpenFisca-Tools<1.0.0,>=0.8.0->openfisca-us) (0.4.8)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (2022.5.18.1)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (3.0.4)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (2.10)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (1.24.3)\n",
"Requirement already satisfied: cached-property in /usr/local/lib/python3.7/dist-packages (from h5py->openfisca-us) (1.5.2)\n",
"Requirement already satisfied: seaborn in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (0.11.2)\n",
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (3.2.2)\n",
"Requirement already satisfied: matplotlib-label-lines in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (0.5.1)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (1.4.2)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (0.11.0)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (2.8.2)\n",
"Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.7/dist-packages (from seaborn->microdf-python->openfisca-us) (1.4.1)\n",
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from synthimpute->openfisca-us) (1.0.2)\n",
"Requirement already satisfied: statsmodels in /usr/local/lib/python3.7/dist-packages (from synthimpute->openfisca-us) (0.10.2)\n",
"Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->synthimpute->openfisca-us) (1.1.0)\n",
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->synthimpute->openfisca-us) (3.1.0)\n",
"Requirement already satisfied: patsy>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from statsmodels->synthimpute->openfisca-us) (0.5.2)\n"
]
}
],
"source": [
"!pip install openfisca-us"
]
},
{
"cell_type": "code",
"source": [
"from openfisca_us import Microsimulation\n",
"\n",
"sim = Microsimulation()\n",
"\n",
"sim.calc(\"spm_unit_net_income\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MUJcLnWYiKZ_",
"outputId": "f5edca88-1fd6-4579-92b2-baf78ffb1f26"
},
"execution_count": 57,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" value weight\n",
"0 28327.0 687.710022\n",
"1 76811.0 1516.949951\n",
"2 15350.0 1483.560059\n",
"3 54856.0 928.729980\n",
"4 27050.0 1467.910034\n",
"... ... ...\n",
"65615 152253.0 470.359985\n",
"65616 44606.0 312.350006\n",
"65617 17282.0 514.109985\n",
"65618 78821.0 516.250000\n",
"65619 53152.0 386.369995\n",
"\n",
"[65620 rows x 2 columns]"
]
},
"metadata": {},
"execution_count": 57
}
]
},
{
"cell_type": "code",
"source": [
"from openfisca_us.api import *\n",
"from openfisca_us.model_api import *\n",
"\n",
"BENEFITS = [\n",
" \"snap\",\n",
" \"wic\",\n",
" \"ssi\",\n",
"]\n",
"\n",
"class spm_unit_federal_tax(Variable):\n",
" value_type = float\n",
" entity = SPMUnit\n",
" label = \"Federal income tax\"\n",
" definition_period = YEAR\n",
" unit = USD\n",
"\n",
" def formula(spm_unit, period, parameters):\n",
" total_income = add(spm_unit, period, [\"taxable_income\"])\n",
" return 0.4 * total_income\n",
"\n",
"class flat_tax_reform(Reform):\n",
" def apply(self):\n",
" self.update_variable(spm_unit_federal_tax)\n",
" self.neutralize_variable(\"ssi\")\n",
" #self.neutralize_variable(\"wic\")\n",
" #self.neutralize_variable(\"snap\")\n",
" #for removed in BENEFITS: \n",
" #self.neutralize_variable(removed)\n",
" \n",
"\n",
"# By default, OpenFisca-US uses reported net income in order to exactly match poverty rates.\n",
"# This reform defined on the next three lines disables that behaviour, by removing the reported \n",
"# net income values. We apply this 'reform' to both the baseline and reformed simulations.\n",
"\n",
"class turn_on_benefits_simulation(Reform):\n",
" def apply(self):\n",
" self.neutralize_variable(\"spm_unit_net_income_reported\")\n",
"\n",
"baseline = Microsimulation(turn_on_benefits_simulation)\n",
"reformed = Microsimulation((turn_on_benefits_simulation, flat_tax_reform))"
],
"metadata": {
"id": "cLHwKKoIpdNL",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "e490ca6e-a4c8-4adf-ec87-85227b4eb12c"
},
"execution_count": 68,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/openfisca_core/holders/holder.py:169: Warning: You cannot set a value for the variable spm_unit_net_income_reported, as it has been neutralized. The value you provided ([28327. 76811. 15350. ... 17282. 78821. 53152.]) will be ignored.\n",
" Warning\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# total funding raised: 2375.0273671257964\n",
"reformed.calc(\"spm_unit_net_income\").sum() / 1e9 - baseline.calc(\"spm_unit_net_income\").sum() / 1e9"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zbR2dpxltON0",
"outputId": "dd251df2-d103-42cd-a534-3b2bd21294fc"
},
"execution_count": 69,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"-2146.056116657607"
]
},
"metadata": {},
"execution_count": 69
}
]
},
{
"cell_type": "code",
"source": [
"# total funding raised Flat Tax (no repeal of benefits): 2096.010503288724 \n",
"# additional revenue generated by neutralizing benefits: 2375.0273671257964 - 2096.010503288724 = 279.016864 "
],
"metadata": {
"id": "Le_vSm6C3iEt"
},
"execution_count": 63,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# total funding raised by the SNAP Abolition + Flat tax: 2327.931632698561\n",
"# additional revenue generated by neutralizing SNAP: 2327.931632698561 - 2096.010503288724 = 231.921129 \n"
],
"metadata": {
"id": "glFVox_c3poK"
},
"execution_count": 53,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# total funding raised by the WIC Abolition + Flat tax: 2100.433048614732\n",
"# additional revenue generated by neutralizing WIC: 2100.433048614732 - 2096.010503288724 = 4.42254533"
],
"metadata": {
"id": "SfrbI-eU3stY"
},
"execution_count": 46,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# total funding raised by SSI Abolition + Flat tax: 2146.056116657607\n",
"# additioanl revenue generated by neutralizing SSI: 2146.056116657607 - 2096.010503288724 = 50.0456134"
],
"metadata": {
"id": "EVb_Gn_m3xvm"
},
"execution_count": null,
"outputs": []
}
]
}