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

Add factors for eight benefits to growfactors.csv file #271

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion puf_stage1/benefit_growth_rates.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,ssi_participation_growth,ssi_benefit_growth,ssi_average_benefit,snap_participation_growth,snap_benefit_growth,snap_average_benefit,oasdi_participation_growth,oasdi_benefit_growth,oasdi_average_benefit,mcare_participation_growth,mcare_benefit_growth,mcare_average_benefit,mcaid_participation_growth,mcaid_benefit_growth,mcaid_average_benefit,vet_participation_growth,vet_benefit_growth,vet_average_benefit,wic_participation_growth,wic_benefit_growth,wic_average_benefit,housing_participation_growth,housing_benefit_growth,,tanf_participation_growth,tanf_benefit_growth,tanf_average_benefit
YEAR,ssi_participation_growth,ssi_benefit_growth,ssi_average_benefit,snap_participation_growth,snap_benefit_growth,snap_average_benefit,oasdi_participation_growth,oasdi_benefit_growth,oasdi_average_benefit,mcare_participation_growth,mcare_benefit_growth,mcare_average_benefit,mcaid_participation_growth,mcaid_benefit_growth,mcaid_average_benefit,vet_participation_growth,vet_benefit_growth,vet_average_benefit,wic_participation_growth,wic_benefit_growth,wic_average_benefit,housing_participation_growth,housing_benefit_growth,housing_average_benefit,tanf_participation_growth,tanf_benefit_growth,tanf_average_benefit
2014,0,0,6663,0,0,1500,0,0,14848,0,0,11447,0,0,7224,0,0,7394,0,0,770,0,0,3776,0,0,8375
2015,-0.002,0.0124,6792,-0.0192,-0.0051,1654,0.0223,0.0618,15422,0.022,0.0457,11714,0.0753,0.1199,7524,-0.0092,0.0372,7741,-0.028336159,0.008060041,776,0.0019,0.0287,3877,-0.293401457,-0.119066738,9486
2016,-0.002,0.0151,6747,-0.0524,-0.0487,1637,0.0508,0.1016,15566,0.0561,0.0933,11851,0.1091,0.0421,7602,-0.0688,0.0775,8557,-0.040877368,0.003004556,778,-0.005,0.0383,3940,-0.135198968,-0.114219344,7856
Expand Down
68 changes: 45 additions & 23 deletions puf_stage1/factors_finalprep.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
"""
Transform Stage_I_factors.csv (written by stage1.py)
into growfactors.csv (used by Tax-Calculator)
Transform Stage_I_factors.csv (written by the stage1.py script) and
benefit_growth_rates.csv into growfactors.csv (used by Tax-Calculator).
"""

import numpy as np
import pandas as pd

# pylint: disable=invalid-name

first_benefit_year = 2014
inben_filename = 'benefit_growth_rates.csv'
first_data_year = 2011
input_filename = 'Stage_I_factors.csv'
infac_filename = 'Stage_I_factors.csv'
output_filename = 'growfactors.csv'

# --------------------------------------------------------------------------
# read in raw average benefit amounts by year and
# convert into "one plus annual proportion change" factors
bgr_all = pd.read_csv(inben_filename, index_col='YEAR')
bnames = ['mcare', 'mcaid', 'ssi', 'snap', 'wic', 'housing', 'tanf', 'vet']
keep_cols = ['{}_average_benefit'.format(bname) for bname in bnames]
bgr_raw = bgr_all[keep_cols]
gf_bnames = ['ABEN{}'.format(bname.upper()) for bname in bnames]
bgr_raw.columns = gf_bnames
bgf = 1.0 + bgr_raw.astype('float64').pct_change()

# specify first row values because pct_change() leaves first year undefined
for var in list(bgf):
bgf[var][first_benefit_year] = 1.0

# add rows of ones for years from first_data_year thru first_benefit_year-1
ones = [1.0] * len(bnames)
for year in range(first_data_year, first_benefit_year):
row = pd.DataFrame(data=[ones], columns=gf_bnames, index=[year])
bgf = pd.concat([bgf, row], verify_integrity=True)
bgf.sort_index(inplace=True)

# round converted factors to six decimal digits of accuracy
bgf = bgf.round(6)

# --------------------------------------------------------------------------
# read in blowup factors used internally in taxdata repository
data = pd.read_csv(input_filename, index_col='YEAR')
data = pd.read_csv(infac_filename, index_col='YEAR')

# convert some aggregate factors into per-capita factors
elderly_pop = data['APOPSNR']
Expand All @@ -29,30 +58,23 @@
data['ACGNS'] = data['ACGNS'] / pop
data['ABOOK'] = data['ABOOK'] / pop
data['ABENEFITS'] = data['ABENEFITS'] / pop
data.rename(columns={'ABENEFITS': 'ABENOTHER'}, inplace=True)

# convert factors into "one plus annual proportion change" format
data = 1.0 + data.pct_change()

# specify first row values because pct_change() leaves first year undefined
# (these values have been transferred from Tax-Calculator records.py)
for var in list(data):
data[var][first_data_year] = 1.0
"""
Double check that these are still needed
data['ACGNS'][first_data_year] = 1.1781
data['ADIVS'][first_data_year] = 1.0606
data['AINTS'][first_data_year] = 1.0357
data['ASCHCI'][first_data_year] = 1.0041
data['ASCHCL'][first_data_year] = 1.1629
data['ASCHEI'][first_data_year] = 1.1089
data['ASCHEL'][first_data_year] = 1.2953
data['AUCOMP'][first_data_year] = 1.0034
data['AWAGE'][first_data_year] = 1.0053
"""

# round converted factors to six decimal digits of accuracy
data = data.round(6)

# --------------------------------------------------------------------------
# combine data and bgf DataFrames
gfdf = pd.concat([data, bgf], axis='columns', verify_integrity=True)

# --------------------------------------------------------------------------
# delete from data the variables not used by Tax-Calculator (TC)
TC_USED_VARS = set(['ABOOK',
'ACGNS',
Expand All @@ -70,10 +92,10 @@
'ATXPY',
'AUCOMP',
'AWAGE',
'ABENEFITS'])
ALL_VARS = set(list(data))
'ABENOTHER'] + gf_bnames)
ALL_VARS = set(list(gfdf))
TC_UNUSED_VARS = ALL_VARS - TC_USED_VARS
data = data.drop(TC_UNUSED_VARS, axis=1)
gfdf = gfdf.drop(TC_UNUSED_VARS, axis=1)

# write out blowup factors used in Tax-Calculator repository
data.to_csv(output_filename, index='YEAR')
# write out grow factors used in blowup logic in Tax-Calculator repository
gfdf.to_csv(output_filename, index='YEAR')
36 changes: 18 additions & 18 deletions puf_stage1/growfactors.csv
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
YEAR,ATXPY,ASCHF,ABOOK,ACPIU,ACPIM,AWAGE,ASCHCI,ASCHCL,ASCHEI,ASCHEL,AINTS,ADIVS,ACGNS,ASOCSEC,AUCOMP,AIPD,ABENEFITS
2011,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
2012,1.043862,0.950283,1.104992,1.0209,1.0365,1.032649,1.049023,0.956138,1.165922,0.926962,0.923588,1.327776,1.58966,1.02827,0.7711,0.9231,0.992359
2013,1.012518,1.142179,1.033784,1.014791,1.024602,1.019984,0.99505,1.050098,0.997245,1.013128,0.893658,0.819381,0.776217,1.014786,0.728829,0.896219,0.992515
2014,1.029476,0.931683,0.976566,1.015927,0.964218,1.039999,1.040616,1.030349,1.075978,0.991321,0.925886,1.17606,1.387522,1.004801,0.641103,0.970506,0.99257
2015,1.043858,0.508206,0.999544,1.001235,1.010449,1.042272,1.045643,1.045687,0.999528,0.999533,0.992874,1.157209,1.268161,1.015868,0.910908,1.052061,1.053858
2016,1.027314,0.689296,0.990701,1.012621,1.01353,1.03404,1.031041,1.031132,0.990745,0.990685,1.000698,0.989028,0.889463,1.005343,0.782145,1.035752,1.097065
2017,1.033861,0.813631,0.995785,1.022585,1.025269,1.037738,1.041126,1.041095,0.995835,0.995814,1.031828,1.012056,1.101495,1.005072,0.996884,1.042176,1.011911
2018,1.037313,1.48793,0.993846,1.022361,1.012742,1.036076,1.025419,1.025377,0.993871,0.993912,1.036421,1.043694,1.025287,1.024288,0.977335,1.045734,1.103035
2019,1.035569,1.296752,1.001475,1.023127,1.013316,1.030217,1.023213,1.023267,1.001456,1.001478,1.063017,1.034493,0.993445,1.037255,1.082367,1.043838,1.054052
2020,1.034169,1.205152,1.006471,1.023743,1.013866,1.026805,1.021165,1.021158,1.006439,1.006348,1.081241,1.024377,1.017719,1.035877,1.18212,1.042299,0.996727
2021,1.035865,1.16783,1.012885,1.02439,1.014213,1.028412,1.025171,1.025174,1.012827,1.01294,1.090913,1.019573,1.023735,1.033631,1.113125,1.04386,1.03007
2022,1.035881,1.107286,1.019598,1.023726,1.014102,1.030728,1.02925,1.02929,1.019656,1.019575,1.072062,1.019234,1.027913,1.034139,1.064851,1.043771,1.030159
2023,1.035254,1.063374,1.028614,1.023992,1.01434,1.031473,1.031689,1.031633,1.028548,1.028594,1.058859,1.019495,1.029178,1.035356,1.051938,1.043174,1.030193
2024,1.035337,1.048499,1.030505,1.023749,1.014395,1.031564,1.032954,1.032966,1.030531,1.030529,1.048357,1.023404,1.030403,1.036368,1.043358,1.043084,1.030334
2025,1.034629,1.044463,1.030914,1.023898,1.014528,1.031933,1.033635,1.033618,1.030967,1.030889,1.040376,1.026049,1.031554,1.034024,1.043478,1.042117,1.030635
2026,1.036122,1.016269,1.033285,1.023949,1.014736,1.032043,1.033896,1.033848,1.03325,1.033314,1.040659,1.028251,1.032329,1.035647,1.043508,1.043536,1.030633
2027,1.0358,0.99068,1.032812,1.024131,1.015015,1.032291,1.034216,1.034262,1.03286,1.032865,1.039756,1.030999,1.032011,1.03812,1.034414,1.04314,1.030788
YEAR,ATXPY,ASCHF,ABOOK,ACPIU,ACPIM,AWAGE,ASCHCI,ASCHCL,ASCHEI,ASCHEL,AINTS,ADIVS,ACGNS,ASOCSEC,AUCOMP,AIPD,ABENOTHER,ABENMCARE,ABENMCAID,ABENSSI,ABENSNAP,ABENWIC,ABENHOUSING,ABENTANF,ABENVET
2011,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
2012,1.043862,0.950283,1.104992,1.0209,1.0365,1.032649,1.049023,0.956138,1.165922,0.926962,0.923588,1.327776,1.58966,1.02827,0.7711,0.9231,0.992359,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
2013,1.012518,1.142179,1.033784,1.014791,1.024602,1.019984,0.99505,1.050098,0.997245,1.013128,0.893658,0.819381,0.776217,1.014786,0.728829,0.896219,0.992515,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
2014,1.029476,0.931683,0.976566,1.015927,0.964218,1.039999,1.040616,1.030349,1.075978,0.991321,0.925886,1.17606,1.387522,1.004801,0.641103,0.970506,0.99257,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
2015,1.043858,0.508206,0.999544,1.001235,1.010449,1.042272,1.045643,1.045687,0.999528,0.999533,0.992874,1.157209,1.268161,1.015868,0.910908,1.052061,1.053858,1.023325,1.041528,1.019361,1.102667,1.007792,1.026748,1.132657,1.04693
2016,1.027314,0.689296,0.990701,1.012621,1.01353,1.03404,1.031041,1.031132,0.990745,0.990685,1.000698,0.989028,0.889463,1.005343,0.782145,1.035752,1.097065,1.011695,1.010367,0.993375,0.989722,1.002577,1.01625,0.828168,1.105413
2017,1.033861,0.813631,0.995785,1.022585,1.025269,1.037738,1.041126,1.041095,0.995835,0.995814,1.031828,1.012056,1.101495,1.005072,0.996884,1.042176,1.011911,1.030968,1.014601,0.981621,1.0,0.998715,1.063959,1.0,1.0
2018,1.037313,1.48793,0.993846,1.022361,1.012742,1.036076,1.025419,1.025377,0.993871,0.993912,1.036421,1.043694,1.025287,1.024288,0.977335,1.045734,1.103035,1.045097,1.045897,1.005738,1.0,1.002574,1.034828,1.0,1.0
2019,1.035569,1.296752,1.001475,1.023127,1.013316,1.030217,1.023213,1.023267,1.001456,1.001478,1.063017,1.034493,0.993445,1.037255,1.082367,1.043838,1.054052,1.052158,1.045866,1.000751,1.0,1.002567,1.034809,1.0,1.0
2020,1.034169,1.205152,1.006471,1.023743,1.013866,1.026805,1.021165,1.021158,1.006439,1.006348,1.081241,1.024377,1.017719,1.035877,1.18212,1.042299,0.996727,1.050763,1.046106,1.00255,1.0,1.003841,1.034974,1.0,1.0
2021,1.035865,1.16783,1.012885,1.02439,1.014213,1.028412,1.025171,1.025174,1.012827,1.01294,1.090913,1.019573,1.023735,1.033631,1.113125,1.04386,1.03007,1.047248,1.047927,1.001796,1.0,1.002551,1.034869,1.0,1.0
2022,1.035881,1.107286,1.019598,1.023726,1.014102,1.030728,1.02925,1.02929,1.019656,1.019575,1.072062,1.019234,1.027913,1.034139,1.064851,1.043771,1.030159,1.048769,1.047573,0.999851,1.0,1.002545,1.034942,1.0,1.0
2023,1.035254,1.063374,1.028614,1.023992,1.01434,1.031473,1.031689,1.031633,1.028548,1.028594,1.058859,1.019495,1.029178,1.035356,1.051938,1.043174,1.030193,1.050822,1.048715,1.000448,1.0,1.003807,1.034968,1.0,1.0
2024,1.035337,1.048499,1.030505,1.023749,1.014395,1.031564,1.032954,1.032966,1.030531,1.030529,1.048357,1.023404,1.030403,1.036368,1.043358,1.043084,1.030334,1.048426,1.051767,0.99776,1.0,1.002528,1.034951,1.0,1.0
2025,1.034629,1.044463,1.030914,1.023898,1.014528,1.031933,1.033635,1.033618,1.030967,1.030889,1.040376,1.026049,1.031554,1.034024,1.043478,1.042117,1.030635,1.046248,1.052213,1.002245,1.0,1.003783,1.034897,1.0,1.0
2026,1.036122,1.016269,1.033285,1.023949,1.014736,1.032043,1.033896,1.033848,1.03325,1.033314,1.040659,1.028251,1.032329,1.035647,1.043508,1.043536,1.030633,1.072236,1.0,0.999552,1.0,1.002513,1.034808,1.0,1.0
2027,1.0358,0.99068,1.032812,1.024131,1.015015,1.032291,1.034216,1.034262,1.03286,1.032865,1.039756,1.030999,1.032011,1.03812,1.034414,1.04314,1.030788,1.0,1.0,1.0,1.0,1.002506,1.034863,1.0,1.0