StructEst_W20 icon indicating copy to clipboard operation
StructEst_W20 copied to clipboard

PS3 q1b

Open jtcerda opened this issue 5 years ago • 2 comments

Hello Professor, Still not being able to get the histogram right. Here is what I do to get the moments which Im getting right. #Create the first 40 bins hist1, bin_edges1 = np.histogram(hh_inc, bins=40, range=(0, 200000)) #Create the other bins hist2, bin_edges2 = np.histogram(hh_inc, bins=(200000, 250000, hh_inc.max()), range=(200000, hh_inc.max())) #Merge two arrays of hist data and edges hist_dt = np.append(hist1, hist2) bin_edges_dt = np.append(bin_edges1, bin_edges2) #Weight observations weights_dt = ((1 / (hist_dt.shape[0])) * np.ones_like(hist_dt)) weights_dt[40] = ((weights_dt[40] / 10)) weights_dt[41] = ((weights_dt[41] / 200)) #Plot the histogram weighted plt.hist(hh_inc, bins=bin_edges_dt, weights=weights_dt, edgecolor='black') Hist_1

Is the problem with the moments or with the ploting? Thank you!

jtcerda avatar Feb 05 '20 18:02 jtcerda

@jtcerda . The problem with your histogram above is that you have divided the data by 1000, but you are still plotting from 0 to 350000. My solution is to leave the data in its original form in dollars and to set some custom tick marks in matplotlib.

plt.xticks(np.array([0, 50000, 100000, 150000, 200000,
                     250000, 350000]),
           ('$0', '$50', '$100', '$150', '$200', '$250', '$350'))
plt.xlabel(r'Household income (\$000)')

or you can divide the data by 1,000 and use matplotlib commands like the following.

plt.xticks(np.array([0, 50, 100, 150, 200, 250, 350]),
           ('$0', '$50', '$100', '$150', '$200', '$250', '$350'))

rickecon avatar Feb 09 '20 23:02 rickecon

Ok, will try that! Thanks!

jtcerda avatar Feb 10 '20 00:02 jtcerda