janboone / applied-economics

course material for the course applied economics
17 stars 21 forks source link

Question on cost per head plot #36

Closed florisvanlaarhoven closed 3 years ago

florisvanlaarhoven commented 3 years ago

Hi,

I have used the following code: range_age = range(18) plt.plot(range_age, costs_per_sex_age[costs_per_sex_age.sex == 'M'].costs_per_head,label='Male') plt.plot(range_age, costs_per_sex_age[costs_per_sex_age.sex == 'F'].costs_per_head,label='Female') plt.xlabel('age') plt.ylabel('Cost per head') plt.show()

However, I know the range_age is wrong, but I don't know how to get the right values on the x-axis, because my dataframe is not ordered by age, but by category of age. E.g.: 0 t/m 4, 5 t/m 8 etc.

So how should I solve this?

janboone commented 3 years ago

I think this is related to the previous point. In the correct dataset the variable age corresponds to 0,1,2,... and hence maps to range(90) statement as you are using.