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

Update Medicare and Medicaid values in cps.csv.gz file #185

Merged
merged 10 commits into from
Aug 10, 2018
Binary file modified cps_data/cps.csv.gz
Binary file not shown.
19 changes: 18 additions & 1 deletion cps_data/finalprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,25 @@ def adjust(data, targets):
def benefits(data, other_ben):
"""
Distribute benefits from non-models benefit programs and create total
benefits variable
benefits variable.
Replaces Medicare and Medicaid values with set amounts
"""
# replace medicare and medicaid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should run faster than lines 348-354:

medicare_cols = 'MCARE_VAL' + pd.Series((np.arange(16) + 1).astype(str))
medicaid_cols = 'MCAID_VAL' + pd.Series((np.arange(16) + 1).astype(str))

count_medicare = data[medicare_cols].astype(bool).sum(axis=1)
count_medicaid = data[medicaid_cols].astype(bool).sum(axis=1)

See https://drive.google.com/file/d/1Fw8rcvcERKs9llMf6dfOVAPuqwuqUUah for an example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip!

medicare_cols = 'MCARE_VAL' + pd.Series((np.arange(15) + 1).astype(str))
medicaid_cols = 'MCAID_VAL' + pd.Series((np.arange(15) + 1).astype(str))
count_medicare = data[medicare_cols].astype(bool).sum(axis=1)
count_medicaid = data[medicaid_cols].astype(bool).sum(axis=1)
weighted_count_mcare = (count_medicare * data['s006']).sum()
weighted_count_mcaid = (count_medicaid * data['s006']).sum()
weighted_mcare = (data['mcare_ben'] * data['s006']).sum()
weighted_mcaid = (data['mcaid_ben'] * data['s006']).sum()
mcare_amt = weighted_mcare / weighted_count_mcare
mcaid_amt = weighted_mcaid / weighted_count_mcaid
data[medicare_cols] = data[medicare_cols].astype(bool) * mcare_amt
data[medicaid_cols] = data[medicaid_cols].astype(bool) * mcaid_amt
data['mcare_ben'] = data[medicare_cols].sum(axis=1)
data['mcaid_ben'] = data[medicaid_cols].sum(axis=1)

other_ben['2014_cost'] *= 1e6

# Distribute other benefits
Expand Down
6 changes: 3 additions & 3 deletions tests/cps_agg_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ n21 711316
ssi_ben 103019670
vet_ben 469788696
snap_ben 141713659
mcare_ben 1700697749
mcaid_ben 904042846
mcare_ben 1778073024
mcaid_ben 888211102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two the total amounts of benefits for medicare and medicaid respectively?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the unweighted totals, yes. The weighted totals didn't change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got you.

e02400 2738889560
tanf_ben 92081596
housing_ben 60379435
Expand Down Expand Up @@ -63,6 +63,6 @@ e20100 199686582
e03210 38819641
e03150 51971620
agi_bin 3920421
other_ben 512349609
other_ben 507328438
e00200 33983727450
e02100 9875430753