Thanks as ever to Kit Baum, a new package twoway__whistogram_gen is now available on SSC.
Please note that the name contains first two underscores after twoway and one underscore before gen. That is deliberate.
The point is that official commands histogram and twoway histogram support use of data and use of frequency weights, but no other kind of weights.
From time to time problems arise in which users might want something else. Suppose you want to use aweights, or you have what you regard as frequencies but they have fractional parts. Stata will not accept anything but a variable's integer values in dealing with fweights.
Although it's undocumented -- which is Stata-speak for there is on-line help, just not a manual entry -- there is a very useful official routine twoway__histogram_gen for generating the variables you need for a histogram, which are
1. Some variable holding densities, fractions, percents or frequencies to show as bar heights for the corresponding bins.
2. Some variable holding bin midpoints which are what you need, together with some desired bar width, to draw the histogram.
twoway__whistogram_gen is a cousin of that command -- which is nevertheless community-contributed. -- which aims to complement the official routine by providing support for aweights and iweights.
Once you have such variables you should proceed promptly to firing up twoway bar [NB] to get the graph of your choice. If you have some other use of the variables, that is fine by me too.
Otherwise put, it was neither appropriate nor appealing for me to try to generalize either of the official histogram commands, but this does most of what a user might often find fiddly.
I have no plans to deal with pweights.
Please note that the name contains first two underscores after twoway and one underscore before gen. That is deliberate.
The point is that official commands histogram and twoway histogram support use of data and use of frequency weights, but no other kind of weights.
From time to time problems arise in which users might want something else. Suppose you want to use aweights, or you have what you regard as frequencies but they have fractional parts. Stata will not accept anything but a variable's integer values in dealing with fweights.
Although it's undocumented -- which is Stata-speak for there is on-line help, just not a manual entry -- there is a very useful official routine twoway__histogram_gen for generating the variables you need for a histogram, which are
1. Some variable holding densities, fractions, percents or frequencies to show as bar heights for the corresponding bins.
2. Some variable holding bin midpoints which are what you need, together with some desired bar width, to draw the histogram.
twoway__whistogram_gen is a cousin of that command -- which is nevertheless community-contributed. -- which aims to complement the official routine by providing support for aweights and iweights.
Once you have such variables you should proceed promptly to firing up twoway bar [NB] to get the graph of your choice. If you have some other use of the variables, that is fine by me too.
Otherwise put, it was neither appropriate nor appealing for me to try to generalize either of the official histogram commands, but this does most of what a user might often find fiddly.
I have no plans to deal with pweights.