Git Product home page Git Product logo

us-calc's Introduction

UBI Center analysis template

Template for UBI Center analyses, including Jupyter-Book and GitHub Action files.

Instructions:

  • Replace reponame with the name of the repo in environment.yml, jb/_config.yml, and the files in .github/workflows/*.
  • Add data generation .py script and data files to jb/data folder. Store files in .csv.gz format and load them as local files in analysis notebooks.
  • Add all necessary packages to environment.yml.
  • Use pull requests to make changes; the workflows will trigger and alert you of any errors.

us-calc's People

Contributors

fedderw avatar hdoupe avatar maxghenis avatar ngpsu22 avatar nikhilwoodruff avatar yuchida522 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

us-calc's Issues

Run all calculations at the SPM unit level first, then map to person

Suggested flow:

  1. Remove taxes and transfers from SPM units, tallying up the total revenue from doing so
  2. Add UBIs to SPM units based on revenue and total population
  3. Calculate poverty gap by SPM unit
  4. Map down change in SPM resources to the person level
  5. Calculate poverty rate (by demographic) and share better off at the person level

See e.g. this will produce the incorrect result since taxes are by person but liabilities affect the full SPM unit:

us-calc/funding.py

Lines 238 to 240 in 36e9e34

if 'income_taxes' in taxes:
funding -= (target_persons.fedtaxac * target_persons.asecwt).sum()
target_persons.new_spm_resources += target_persons.fedtaxac

Fix design

Make the actual Dash app look better. Probably the final step.

Remove multiplications by 100

Currently causing an off-by-100 error, and confusing. Instead keep everything as 0-1 proportions, and use fig.update_layout(yaxis_tickformat="%") instead of suffix="%" to show proportions as proper percentages.

Provide data on hover charts

Customize the hover charts so that it shows the original number and the change. Not sure how to do this on bar charts yet. without adding each bar separately.

Application error on heroku: Error R14 (Memory quota exceeded)

https://dashboard.heroku.com/apps/us-ubi-calculator/logs

Nothing is very big here, the CPS file is about 10MB.

@yuchida522 @ngpsu22

2021-01-28T21:17:42.597570+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-28T21:17:56.928860+00:00 heroku[web.1]: Starting process with command `gunicorn funding:server`
2021-01-28T21:18:00.301970+00:00 app[web.1]: [2021-01-28 21:18:00 +0000] [4] [INFO] Starting gunicorn 20.0.4
2021-01-28T21:18:00.303024+00:00 app[web.1]: [2021-01-28 21:18:00 +0000] [4] [INFO] Listening at: http://0.0.0.0:56215 (4)
2021-01-28T21:18:00.303180+00:00 app[web.1]: [2021-01-28 21:18:00 +0000] [4] [INFO] Using worker: sync
2021-01-28T21:18:00.310506+00:00 app[web.1]: [2021-01-28 21:18:00 +0000] [10] [INFO] Booting worker with pid: 10
2021-01-28T21:18:00.348731+00:00 app[web.1]: [2021-01-28 21:18:00 +0000] [11] [INFO] Booting worker with pid: 11
2021-01-28T21:18:01.396240+00:00 heroku[web.1]: State changed from starting to up
2021-01-28T21:18:16.246762+00:00 heroku[web.1]: Process running mem=592M(115.8%)
2021-01-28T21:18:16.248864+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2021-01-28T21:18:31.597593+00:00 app[web.1]: [2021-01-28 21:18:31 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:10)
2021-01-28T21:18:31.602269+00:00 app[web.1]: [2021-01-28 21:18:31 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:11)
2021-01-28T21:18:31.746444+00:00 app[web.1]: [2021-01-28 21:18:31 +0000] [10] [INFO] Worker exiting (pid: 10)
2021-01-28T21:18:31.786460+00:00 app[web.1]: [2021-01-28 21:18:31 +0000] [11] [INFO] Worker exiting (pid: 11)
2021-01-28T21:18:32.705257+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico" host=us-ubi-calculator.herokuapp.com request_id=31a11c22-1469-4b03-8d06-26a06a26690b fwd="47.155.227.254" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2021-01-28T21:18:32.728554+00:00 app[web.1]: [2021-01-28 21:18:32 +0000] [48] [INFO] Booting worker with pid: 48
2021-01-28T21:18:32.798500+00:00 app[web.1]: [2021-01-28 21:18:32 +0000] [49] [INFO] Booting worker with pid: 49
2021-01-28T21:18:34.151024+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico" host=us-ubi-calculator.herokuapp.com request_id=d6767ec4-5a3e-4f0d-98fd-fc4d3f948603 fwd="76.21.110.99" dyno=web.1 connect=5000ms service=30001ms status=503 bytes=0 protocol=https
2021-01-28T21:18:57.136725+00:00 heroku[web.1]: Process running mem=971M(189.8%)
2021-01-28T21:18:57.139495+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2021-01-28T21:19:03.068085+00:00 app[web.1]: [2021-01-28 21:19:03 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:48)
2021-01-28T21:19:03.070676+00:00 app[web.1]: [2021-01-28 21:19:03 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:49)
2021-01-28T21:19:03.168249+00:00 app[web.1]: [2021-01-28 21:19:03 +0000] [49] [INFO] Worker exiting (pid: 49)
2021-01-28T21:19:03.182359+00:00 app[web.1]: [2021-01-28 21:19:03 +0000] [48] [INFO] Worker exiting (pid: 48)
2021-01-28T21:19:04.131108+00:00 app[web.1]: [2021-01-28 21:19:04 +0000] [80] [INFO] Booting worker with pid: 80
2021-01-28T21:19:04.187324+00:00 app[web.1]: [2021-01-28 21:19:04 +0000] [81] [INFO] Booting worker with pid: 81
2021-01-28T21:19:18.384942+00:00 heroku[web.1]: Process running mem=651M(127.3%)
2021-01-28T21:19:18.387169+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2021-01-28T21:19:34.477825+00:00 app[web.1]: [2021-01-28 21:19:34 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:80)
2021-01-28T21:19:34.501329+00:00 app[web.1]: [2021-01-28 21:19:34 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:81)
2021-01-28T21:19:34.585942+00:00 app[web.1]: [2021-01-28 21:19:34 +0000] [81] [INFO] Worker exiting (pid: 81)
2021-01-28T21:19:34.590370+00:00 app[web.1]: [2021-01-28 21:19:34 +0000] [80] [INFO] Worker exiting (pid: 80)
2021-01-28T21:19:35.616296+00:00 app[web.1]: [2021-01-28 21:19:35 +0000] [112] [INFO] Booting worker with pid: 112
2021-01-28T21:19:35.702181+00:00 app[web.1]: [2021-01-28 21:19:35 +0000] [113] [INFO] Booting worker with pid: 113
2021-01-28T21:20:00.144148+00:00 heroku[web.1]: Process running mem=1088M(212.6%)
2021-01-28T21:20:00.146071+00:00 heroku[web.1]: Error R15 (Memory quota vastly exceeded)
2021-01-28T21:20:00.147704+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-01-28T21:20:00.361480+00:00 heroku[web.1]: Process exited with status 137
2021-01-28T21:20:00.402385+00:00 heroku[web.1]: State changed from up to crashed

Use a for loop for repealing benefits

To condense these if statements:

us-calc/funding.py

Lines 214 to 236 in 36e9e34

if 'ssi' in benefits:
funding += (target_persons.incssi * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.incssi
if 'unemp' in benefits:
funding += (target_persons.incunemp * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.incunemp
if 'eitc' in benefits:
funding += (target_persons.eitcred * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.spmeitc
if 'ctc' in benefits:
funding += (target_persons.ctc * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.spmctc
if 'snap' in benefits:
funding += (target_persons.snap_pp * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.snap_pp
if 'energy' in benefits:
funding += (target_persons.energy_pp * target_persons.asecwt).sum()
target_persons.new_spm_resources -= target_persons.energy_pp

Load csv file locally

Currently loads from the GitHub URL, should be able to do locally to save some time

us-calc/funding.py

Lines 13 to 14 in 84817f4

person_raw = pd.read_csv(
'https://github.com/UBICenter/us-calc/raw/main/cps_00041.csv.gz')

Add TANF cash assistance

Could be tricky since it includes state and federal funding, would have to claw back the MOE to fund UBI

Use a function to reduce code duplication when creating initial poverty rates

Condense this section:

us-calc/funding.py

Lines 18 to 55 in 36e9e34

population = person.asecwt.sum()
original_total_poor = (person.original_poor * person.asecwt).sum()
original_poverty_rate = (original_total_poor / population) * 100
spmu = person.drop_duplicates(subset=['spmfamunit'])
spmu['original_poverty_gap'] = person.spmthresh - person.spmtotres
original_poverty_gap = (((spmu.original_poor * spmu.original_poverty_gap *
spmu.asecwth).sum()))
# Calculate original child poverty
child_population = (person.child * person.asecwt).sum()
original_child_poor = (person.child * person.original_poor * person.asecwt).sum()
original_child_poverty_rate = (original_child_poor / child_population) * 100
# Calculate original adult poverty
adult_population = (person.adult * person.asecwt).sum()
original_adult_poor = (person.adult * person.original_poor * person.asecwt).sum()
original_adult_poverty_rate = (original_adult_poor / adult_population) * 100
# Calculate original pwb poverty
pwb_population = (person.pwb * person.asecwt).sum()
original_pwb_poor = (person.pwb * person.original_poor * person.asecwt).sum()
original_pwb_poverty_rate = (original_pwb_poor / pwb_population) * 100
# Calculate original White poverty
white_population = (person.white_non_hispanic * person.asecwt).sum()
original_white_poor = (person.white_non_hispanic * person.original_poor * person.asecwt).sum()
original_white_poverty_rate = (original_white_poor / white_population) * 100
# Calculate original Black poverty
black_population = (person.black * person.asecwt).sum()
original_black_poor = (person.black * person.original_poor * person.asecwt).sum()
original_black_poverty_rate = (original_black_poor / black_population) * 100
# Calculate original Hispanic poverty
hispanic_population = (person.hispanic * person.asecwt).sum()
original_hispanic_poor = (person.hispanic * person.original_poor * person.asecwt).sum()
original_hispanic_poverty_rate = (original_hispanic_poor / hispanic_population) * 100

Add deep poverty to both charts

Poverty rate breakdown could make each current bar a set of two bars, like in the FSA post
image

Rationale being that it is directionally similar to the poverty gap, which is more responsive to universal transfers, but more comprehensible.

Separate out a MECE race/ethnicity chart

This would also clear up some potentially confusing results like this (California state level, 1% flat tax, excludes adults (i.e. child allowance)). So White Non-Hispanic, Black Non-Hispanic, Hispanic, Other Non-Hispanic. Presumably the Other Non Hispanic group has a higher poverty impact than the others, bringing the overall poverty impact to 9.2%.

image

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.