Giter Site home page Giter Site logo

policyengine / policyengine-us Goto Github PK

View Code? Open in Web Editor NEW
94.0 7.0 159.0 676.06 MB

The PolicyEngine US Python package contains a rules engine of the US tax-benefit system, and microdata generation for microsimulation analysis.

Home Page: https://policyengine.org/us

License: GNU Affero General Public License v3.0

Makefile 0.05% Python 99.73% Jupyter Notebook 0.22%
economics policy python tax united-states economic-policy poverty public-policy inequality

policyengine-us's Introduction

PolicyEngine US

codecov PyPI version Code style: black

PolicyEngine US is a microsimulation model of the US state and federal tax and benefit system.

To install, run pip install policyengine-us.

policyengine-us's People

Contributors

calebpena avatar dianashi5083 avatar eleanor-zhu avatar fedderw avatar hua7450 avatar jingj-wang avatar jnaux avatar judyz13 avatar kiki-67 avatar leogoldman avatar linfeng-ll avatar martinholmer avatar matthjensen avatar maxghenis avatar mshuning avatar mzx-4real avatar nikhilwoodruff avatar nmrodelo avatar pavelmakarchuk avatar phywzc avatar qingqiuzhang avatar shuyu7zhan avatar tolaouk avatar vrathi101 avatar xinyi-shao avatar xz-mabel avatar yedeer12 avatar yvvijay121 avatar yy3187 avatar ziqiancui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

policyengine-us's Issues

Add "personal_income" as a layer to parameters/tax/

This might be premature and introduce a lot of extra typing, but in case we want other tax types down the road (corporate, employer, consumption, carbon, etc.), we may want to add a layer after parameters/tax, e.g. parameters/tax/personal_income or parameters/tax/pit (a common abbreviation referring to Personal Income Tax), or parameters/pit.

Add tax output variables

We need to add the following output variables from tax-calculator:

  • niit
  • combined
  • earned
  • earned_p
  • earned_s
  • was_plus_sey_p
  • was_plus_sey_s
  • eitc
  • rptc
  • rptc_p
  • rptc_s
  • exact
  • expanded_income
  • iitax
  • num
  • othertaxes
  • payrolltax
  • refund
  • sep
  • sey
  • standard
  • surtax
  • taxbc
  • c00100
  • c01000
  • c02500
  • c02900
  • c03260
  • c04470
  • c04600
  • qbided
  • c04800
  • c05200
  • c05700
  • c05800
  • c07100
  • c07180
  • CDCC_refund
  • c07200
  • c07220
  • c07230
  • c07240
  • c07260
  • c07300
  • c07400
  • c07600
  • c08000
  • c09200
  • c09600
  • c10960
  • c11070
  • c17000
  • e17500_capped
  • c18300
  • e18400_capped
  • e18500_capped
  • c19200
  • e19200_capped
  • c19700
  • e19800_capped
  • e20100_capped
  • c20500
  • g20500_capped
  • c20800
  • e20400_capped
  • c21040
  • c21060
  • c23650
  • c59660
  • c62100
  • c87668
  • care_deduction
  • ctc_new
  • odc
  • personal_refundable_credit
  • recovery_rebate_credit
  • personal_nonrefundable_credit
  • charity_credit
  • dwks10
  • dwks13
  • dwks14
  • dwks19
  • fstax
  • invinc_agi_ec
  • invinc_ec_base
  • lumpsum_tax
  • pre_c04600
  • codtc_limited
  • ptax_amc
  • ptax_oasdi
  • ptax_was
  • setax
  • ymod
  • ymod1
  • ubi
  • taxable_ubi
  • nontaxable_ubi
  • mtr_paytax
  • mtr_inctax
  • aftertax_income
  • benefit_cost_total
  • benefit_value_total

Add inputs for tax variables

On the microdata side, we're going to need survey inputs for the different tax variables used as input to tax logic. This will involve essentially trying to replicate taxdata's process for the CPS. taxdata uses the same input dataset as us (the CPS), so to do this, we'll need to do the following for every variable in the output dataset:

  1. Look at the source code and understand the process of creating it from CPS variables
  2. For every CPS variable used, add an OpenFisca variable to openfisca-data in survey_input_variables.py like this.
  3. Add a variable to model_input_variables.py like this.

This should be fairly procedural, but since taxdata iterates over rows rather than using Pandas (we're using Pandas), there might be instances where iterative approaches might be hard to replicate using vectorised functions: I'd advise to just skip those variables for now, and come back later to think about them.

Add tax input variables

We need to add the following input variables from tax-calculator:

  • DSI
  • EIC
  • FLPDYR
  • MARS
  • MIDR
  • RECID
  • XTOT
  • age_head
  • age_spouse
  • agi_bin
  • blind_head
  • blind_spouse
  • cmbtp
  • e00200
  • e00200p
  • e00200s
  • pencon_p
  • pencon_s
  • e00300
  • e00400
  • e00600
  • e00650
  • e00700
  • e00800
  • e00900
  • e00900p
  • e00900s
  • e01100
  • e01200
  • e01400
  • e01500
  • e01700
  • e02000
  • e02100
  • e02100p
  • e02100s
  • e02300
  • e02400
  • e03150
  • e03210
  • e03220
  • e03230
  • e03240
  • e03270
  • e03290
  • e03300
  • e03400
  • e03500
  • e07240
  • e07260
  • e07300
  • e07400
  • e07600
  • e09700
  • e09800
  • e09900
  • e11200
  • e17500
  • e18400
  • e18500
  • e19200
  • e19800
  • e20100
  • e20400
  • g20500
  • e24515
  • e24518
  • e26270
  • e27200
  • e32800
  • e58990
  • e62900
  • e87530
  • elderly_dependents
  • f2441
  • f6251
  • a_lineno
  • ffpos
  • fips
  • h_seq
  • data_source
  • k1bx14p
  • k1bx14s
  • mcaid_ben
  • mcare_ben
  • n24
  • nu06
  • nu13
  • nu18
  • n1820
  • n21
  • other_ben
  • p08000
  • p22250
  • p23250
  • e87521
  • s006
  • snap_ben
  • housing_ben
  • ssi_ben
  • tanf_ben
  • vet_ben
  • wic_ben
  • PT_SSTB_income
  • PT_binc_w2_wages
  • PT_ubia_property

Implement `calcfunctions` from Tax-Calculator

Implementing the logic and parameters from calcfunctions.py in tax-calculator. Each function needs to:

  • Have input and output parameters and variables present in openfisca-us
  • Be decomposed into a set of many-in, one-out functions, preserving the logic (tax-calculator functions can be many-in, many-out), by adding intermediate variables as OpenFisca variables
  • Have iterative logic re-implemented in vectorised form in each formula
  • Have any unit tests from test_calcfunctions.py re-implemented in openfisca-us

Add AGI logic

Add parameters and logic from the AGI function in tax-calculator.

Translate tax formulas

Translating tax formulas from tax-calculator will require converting compiled functions to vectorized functions and multi-output functions to single-output functions, using parameters where necessary.

Add Adj

Add the tax policy logic from the Adj function in tax-calculator, including parameters, intermediate and output variables.

Document parameter organization and naming conventions

See for example #41 (comment)

For example, one specific question: Should parameters include the attribute by which it's segmented? e.g. the standard deduction amount is currently named filer as that's what it's specified by. If not (e.g. if we called it amount) is there another way to hint the breakdown? We would ideally hint both the quantity type (e.g. amount vs thresholds) and the breakdown.

It'd probably be good to spec out the tree we're planning to fill in at the first ~3 levels of depth.

Add tax parameters

All parameters from tax-calculator will need to be added as parameters.

The full list is:

  • parameter_indexing_CPI_offset
  • AMEDT_ec
  • AMEDT_rt
  • FICA_mc_trt
  • FICA_ss_trt
  • SS_Earnings_c
  • SS_Earnings_thd
  • SS_thd50
  • SS_percentage1
  • SS_thd85
  • SS_percentage2
  • ALD_Dependents_hc
  • ALD_Dependents_Child_c
  • ALD_Dependents_Elder_c
  • ALD_Dependents_thd
  • ALD_StudentLoan_hc
  • ALD_SelfEmploymentTax_hc
  • ALD_SelfEmp_HealthIns_hc
  • ALD_KEOGH_SEP_hc
  • ALD_EarlyWithdraw_hc
  • ALD_AlimonyPaid_hc
  • ALD_AlimonyReceived_hc
  • ALD_EducatorExpenses_hc
  • ALD_HSADeduction_hc
  • ALD_IRAContributions_hc
  • ALD_DomesticProduction_hc
  • ALD_Tuition_hc
  • ALD_InvInc_ec_rt
  • ALD_BusinessLosses_c
  • II_em
  • II_prt
  • II_no_em_nu18
  • STD_Aged
  • STD
  • CDCC_c
  • CDCC_ps
  • CDCC_ps2
  • CDCC_crt
  • CDCC_frt
  • CDCC_prt
  • CDCC_refundable
  • CR_RetirementSavings_hc
  • CR_ForeignTax_hc
  • CR_ResidentialEnergy_hc
  • CR_GeneralBusiness_hc
  • CR_MinimumTax_hc
  • CR_AmOppRefundable_hc
  • CR_AmOppNonRefundable_hc
  • CR_SchR_hc
  • CR_OtherCredits_hc
  • CR_Education_hc
  • II_credit_nr
  • II_credit_nr_ps
  • II_credit_nr_prt
  • ACTC_c
  • ACTC_rt
  • ACTC_rt_bonus_under6family
  • ACTC_Income_thd
  • ACTC_ChildNum
  • CTC_c
  • CTC_c_under6_bonus
  • CTC_include17
  • CTC_refundable
  • CTC_ps
  • CTC_prt
  • ODC_c
  • ID_Casualty_frt
  • ID_Casualty_hc
  • ID_Casualty_c
  • ID_c
  • ID_AmountCap_rt
  • ID_AmountCap_Switch
  • ID_BenefitCap_rt
  • ID_BenefitCap_Switch
  • ID_Charity_crt_all
  • ID_Charity_crt_noncash
  • ID_Charity_frt
  • ID_Charity_hc
  • ID_Charity_c
  • ID_Charity_f
  • ID_InterestPaid_hc
  • ID_InterestPaid_c
  • ID_ps
  • ID_prt
  • ID_crt
  • ID_Medical_frt
  • ID_Medical_frt_add4aged
  • ID_Medical_hc
  • ID_Medical_c
  • ID_Miscellaneous_frt
  • ID_Miscellaneous_hc
  • ID_Miscellaneous_c
  • ID_StateLocalTax_hc
  • ID_StateLocalTax_crt
  • ID_StateLocalTax_c
  • ID_AllTaxes_hc
  • ID_AllTaxes_c
  • ID_RealEstate_hc
  • ID_RealEstate_crt
  • ID_RealEstate_c
  • ID_BenefitSurtax_trt
  • ID_BenefitSurtax_crt
  • ID_BenefitSurtax_em
  • ID_BenefitSurtax_Switch
  • AMT_CG_rt1
  • AMT_CG_brk1
  • AMT_CG_rt2
  • AMT_CG_brk2
  • AMT_CG_rt3
  • AMT_CG_brk3
  • AMT_CG_rt4
  • CG_rt1
  • CG_brk1
  • CG_rt2
  • CG_brk2
  • CG_rt3
  • CG_brk3
  • CG_rt4
  • CG_nodiff
  • CG_ec
  • CG_reinvest_ec_rt
  • AMT_em
  • AMT_prt
  • AMT_em_ps
  • AMT_rt1
  • AMT_brk1
  • AMT_rt2
  • PT_rt1
  • PT_brk1
  • PT_rt2
  • PT_brk2
  • PT_rt3
  • PT_brk3
  • PT_rt4
  • PT_brk4
  • PT_rt5
  • PT_brk5
  • PT_rt6
  • PT_brk6
  • PT_rt7
  • PT_brk7
  • PT_rt8
  • PT_EligibleRate_active
  • PT_EligibleRate_passive
  • PT_wages_active_income
  • PT_top_stacking
  • PT_qbid_rt
  • PT_qbid_taxinc_thd
  • PT_qbid_taxinc_gap
  • PT_qbid_w2_wages_rt
  • PT_qbid_alt_w2_wages_rt
  • PT_qbid_alt_property_rt
  • PT_qbid_limit_switch
  • PT_qbid_ps
  • PT_qbid_prt
  • II_rt1
  • II_brk1
  • II_rt2
  • II_brk2
  • II_rt3
  • II_brk3
  • II_rt4
  • II_brk4
  • II_rt5
  • II_brk5
  • II_rt6
  • II_brk6
  • II_rt7
  • II_brk7
  • II_rt8
  • NIIT_thd
  • NIIT_PT_taxed
  • NIIT_rt
  • EITC_c
  • EITC_rt
  • EITC_basic_frac
  • EITC_prt
  • EITC_ps
  • EITC_ps_MarriedJ
  • EITC_MinEligAge
  • EITC_MaxEligAge
  • EITC_InvestIncome_c
  • EITC_excess_InvestIncome_rt
  • EITC_indiv
  • EITC_sep_filers_elig
  • CTC_new_c
  • CTC_new_c_under6_bonus
  • CTC_new_for_all
  • CTC_new_rt
  • CTC_new_ps
  • CTC_new_prt
  • CTC_new_refund_limited
  • CTC_new_refund_limit_payroll_rt
  • CTC_new_refund_limited_all_payroll
  • II_credit
  • II_credit_ps
  • II_credit_prt
  • RRC_c
  • RRC_ps
  • RRC_pe
  • RRC_prt
  • RRC_c_unit
  • RRC_c_kids
  • RPTC_c
  • RPTC_rt
  • LST
  • AGI_surtax_trt
  • AGI_surtax_thd
  • FST_AGI_trt
  • FST_AGI_thd_lo
  • FST_AGI_thd_hi
  • UBI_u18
  • UBI_1820
  • UBI_21
  • UBI_ecrt
  • BEN_ssi_repeal
  • BEN_housing_repeal
  • BEN_snap_repeal
  • BEN_tanf_repeal
  • BEN_vet_repeal
  • BEN_wic_repeal
  • BEN_mcare_repeal
  • BEN_mcaid_repeal
  • BEN_oasdi_repeal
  • BEN_ui_repeal
  • BEN_other_repeal
  • II_em_ps
  • STD_Dep
  • STD_allow_charity_ded_nonitemizers
  • STD_charity_ded_nonitemizers_max
  • UI_em
  • UI_thd
  • AMT_child_em
  • AMT_child_em_c_age
  • AMT_em_pe
  • LLC_Expense_c
  • ETC_pe_Single
  • ETC_pe_Married
  • CR_Charity_rt
  • CR_Charity_f
  • CR_Charity_frt

Document the data extraction routine

User Story:
As a developer, I want to know the input, output and logic of converting raw data into taxdata.

AC:

  1. steps to set up local development
  2. definitions and links for input, output sample data
  3. notes for parsing logic

Add CPS module to `openfisca-data`

We'll use the existing infrastructure in openfisca-data (along with potentially a rename) to maintain the standardised dataset generation procedure. This will involve:

  • Creating a new @dataset-decorated class for BaseCPS
  • Adding the survey variables as OpenFisca variables
  • Adding the model input variables
  • Adding a new dataset class with the survey variables skipped - CPS

This structure follows almost exactly the process for FRS and SPI in the UK model.

Consider autopep8 in addition to black

Autopep8 does some comment formatting that black doesn't do, such as splitting long comment lines and ensuring a space follows the #. Should we run it prior to black?

Policy Parameter to take into account elderly or disabled individual status in SNAP receiving households

There are significant differences between calculating benefits for households with and without at least one elderly and/or disabled person. For example, for most states the standard shelter deduction is capped at 569 per month, unless the household has an elderly or disabled individual living in it, in which case there is no cap.

Additionally, on the income eligibility page, there is a separate table for such households, with more generous income limits:
https://fns-prod.azureedge.net/sites/default/files/media/file/FY21-Income-Eligibility-Standards.pdf

Per the USDA, in 2018 roughly 23% of SNAP receiving households met this criteria, meaning it is not a fringe population.

https://www.fns.usda.gov/snap/characteristics-households-fy-2018#:~:text=Seven%20percent%20of%20all%20participants,households%20had%20earnings%20in%20FY2018.

Document variable translation from taxdata to cps_us data

Story:
As a developer, to make the raw cps us variables ready to use for modeling, I need to

  1. understand how the variables are translated from survey to model
  2. a way to test if my translation is correct

Acceptance Criteria:

  1. Document the following information in openfisca-data repo in markdown
    (1) Variables name mapping (raw name, family/household/person, mapped output name)
    (2) Logic for each variable translation (just renaming or steps to process)
    (3) Prioritization groups:
    a. [important+easy]: Variables that are ready to translate with clear processing steps
    b. [important+hard]: Variables that are important in the future but needs more efforts to clarify the processing steps
    c. [not important]: Variables that are not important at the moment because it is not used in taxdata.
    (4) Any reference and unanswered questions
  2. Create Google Doc to organize links of all docs and share it with us developer group

Add administrative totals for benefit programs

We can then use these to augment the data via synthimpute. @nikhilwoodruff would these belong in the standard benefit path, or somewhere else since they're not policy parameters?

If the standard path, it could be something like:

parameters/benefit/{benefit}/admin/{totals,overhead}.yaml

(totals could have subcomponents for spending and participation)

Implement policy parameter for % of poverty line below which gross monthly income must be for SNAP

Currently 1.3 (130%) per https://www.cbpp.org/research/food-assistance/a-quick-guide-to-snap-eligibility-and-benefits

Gross monthly income — that is, household income before any of the program’s deductions are applied — generally must be at or below 130 percent of the poverty line. For a family of three, the poverty line used to calculate SNAP benefits in federal fiscal year 2021 is $1,810 a month. Thus, 130 percent of the poverty line for a three-person family is $2,353 a month, or about $28,200 a year. The poverty level is higher for bigger families and lower for smaller families

Basic prototype

@MaxGhenis

For a basic proof-of-concept, with the standard deduction and rates, we could ideally have:

  • Standard deduction, rates added to parameters
  • Variables for the inputs and after-tax income variable
  • Microdata loading function (CPS/PUF)
  • At least 5 tests (tax-calculator tests)
  • A Jupyter Book with some explanation and a demo (some Plotly graph output)

Add documentation on how to test

After running pip install -e . from root and pytest I get this error:

(base) mghenis@penguin:~/UBICenter/openfisca-us$ pytest
=== test session starts ===
platform linux -- Python 3.7.7, pytest-5.4.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/mghenis/UBICenter/openfisca-us, inifile: setup.cfg, testpaths: openfisca_country_template/tests
plugins: anyio-3.0.1, dash-1.20.0
collected 0 items

=== no tests ran in 0.02s ===
ERROR: file not found: openfisca_country_template/tests

What am I missing? Let's add the installation and testing procedure to the docs.

Create CPS input file

We need to effectively reproduce the taxdata method of creating tax units with all required variables, and at the same time also create person, family, household, and later SPM unit entities. This will involve adding a few modules to openfisca-data.

test issue moon

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

Here is what I expected to happen:

Here is what actually happened:

Here is data (or links to it) that can help you reproduce this issue:

Context

I identify more as a:

  • Analyst (I make macroscopic computations on real populations).
  • Business expert (I create tests and model legislation).
  • Commenter (I make data visualisations).
  • Developer (I create tools that use the existing OpenFisca code).
  • Historian (I accumulate data based on past legislation values).
  • Lobbyist (I model reforms to make them exist).
  • Producer (I make computations on individual situations).

(remove this line as well as all items in the list that don't fit your situation)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.