Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: labeling twoway histogram plots


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: labeling twoway histogram plots
Date   Sun, 11 Apr 2010 18:48:17 +0100

-tabplot- from SSC can do histograms as tables of bars and show percents
as numeric text too. 

Nick 
[email protected] 

Leslie Liang

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
http://www.stata.com/statalist/archive/2003-11/msg00769.html but it does
not work due to the additional "by" option. Any suggestions how to go
about doing it?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index