Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: labeling twoway histogram plots

From   Leslie Liang <>
Subject   st: labeling twoway histogram plots
Date   Sat, 10 Apr 2010 09:06:03 +0100

I've tried searching for answers on the net all over but I have not found any solutions to this...
Basically, I have 2 variables (say xvar & yvar) and I would like to plot the percent of xvar for each of the 2 values of yvar on the same axis, for each category of zvar. My first attempt at the question was to do:

histogram xvar, discrete percent sort addlabels by(yvar) by(zvar)

However, this command outputs a plot with 2 separate histograms. So the only way I could think of to accomplish this was to make 2 new dummy variables and do a twoway histogram plot:

gen xvary1= (2*xvar- (2-xvar)) if (yvar==1)
gen xvary2= (2*xvar- (1-xvar)) if (yvar==2)
twoway (histogram xvary1, discrete percent width(1) sort) || (histogram xvary2, discrete percent width(1) sort), by(zvar)

Which works and outputs the plot I want. But it seems that "twoway histogram" does not allow the addlabels option to show the heights of each bar. Alternatively, I tried the workaround at but it does not work due to the additional "by" option. Any suggestions how to go about doing it?

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index