Yes, this can be done. I'd like to know a better way,
but here is one recipe.
sysuse auto, clear
gen max = .
levelsof rep78, local(levels)
qui foreach l of local levels {
twoway__histogram_gen mpg if rep78 == `l', ///
width(2) start(10) gen(h x, replace)
su h, meanonly
replace max = r(max) if rep78 == `l'
}
egen mean = mean(mpg), by(rep78)
twoway histogram mpg , width(2) start(10) || spike max mean, ///
by(rep78, legend(off)) ytitle(Density) xtitle(`: var label mpg')
See also David Harrison's Tip on -twoway__histogram_gen-.
SJ-5-2 gr0014 . . . . . . . Stata tip 20: Generating histogram bin variables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . D. A. Harrison
Q2/05 SJ 5(2):280--281 (no commands)
tip illustrating the use of twoway__histogram_gen for
creation of complex histograms and other graphs or tables
also reprinted in "Thirty-three Stata Tips" from StataCorp.
Nick
[email protected]
MA V
> Thanks for your suggestion. It works pretty well.
> But in my case I am ploting 15 different histograms in the
> same plot and
> picking a different "max" for each one of them is not really
> practical.
> Also, I'm using the rescaling option for both the X and the Y
> axes since the
> histograms have different scales.
> I was wondering if there is a way of telling Stata that the
> height of each
> of the lines (one for each histogram) should be a function of
> the histogram
> itself. For example, can we somehow specify that each spike
> should be as
> high as the highest bar in each of the histograms? Note: I am
> plotting
> density-based histograms.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/