Interpret inputs
@@ -30,6 +30,32 @@ def parse_scf_distr_stats(
age = None, education = None, year = None
):
+ # Pre-process year to make it a five-year bracket as in the table
+ if age is not None:
+
+ u_bound = int(np.ceil(age/5) * 5)
+ l_bound = u_bound - 5
+ age_bracket = '(' + str(l_bound) + ',' + str(u_bound) + ']'
+
+ else:
+
+ # If no year is given, use all years.
+ age_bracket = 'All'
+
+ # Check whether education is in one of the allowed categories
+ if education is not None:
+
+ message = ("If an education level is provided, it must be one of " +
+ "'NoHS', 'HS', or 'College'.")
+ assert education in ['NoHS','HS','College'], message
+
+ else:
+
+ education = 'All'
+
+ # Parse the year
+ year_str = 'All' if year is None else str(int(year))
+
# Read table
filename = os.path.join(scf_sumstats_dir, "WealthIncomeStats.csv")
@@ -38,7 +64,24 @@ def parse_scf_distr_stats(
index_col = ['Educ','YEAR','Age_grp'],
dtype = {'Educ': str,'YEAR': str,'Age_grp': str})
- print(table.loc[('College','1995','(20,25]')])
+ # Try to access the requested combination
+ try:
+
+ row = table.loc[(education, year_str, age_bracket)]
+
+ except KeyError as e:
+
+ message = ("The summary statistics do not contain the "+
+ "Age/Year/Education combination that was requested.")
+ raise Exception(message).with_traceback(e.__traceback__)
+
+ # Check for NAs
+ if any(row.isna()):
+ warn("There were not enough observations in the requested " +
+ "Age/Year/Education combination to compute all summary" +
+ "statistics.")
+
+ return row.to_dict()
table = get_scf_distr_stats()
-hm = parse_scf_distr_stats()
\ No newline at end of file
+hm = parse_scf_distr_stats(age = 28, education = 'College', year = 1995)
\ No newline at end of file
