Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: graph bar labels


From   Ricardo Ovaldia <ovaldia@yahoo.com>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: RE: graph bar labels
Date   Thu, 10 Nov 2005 15:50:36 -0800 (PST)

That was it. Thank you Nick.

Ricardo.

--- Nick Cox <n.j.cox@durham.ac.uk> wrote:

> Ah! I see. Now that is fairly simple. It's just
> that -graph bar- is not the best way to do it. 
> -- or indeed a way to do it at all. 
> 
> egen percent = mean(100 * foreign), by(rep78) 
> egen total = sum(1), by(rep78) 
> 
> twoway bar percent rep78, barw(0.5) || 
> 	scatter percent rep78, mlabel(total) mlabpos(12) 
> 	ms(none) legend(off) yti(percent foreign) 
> 
> I follow the convention here that percents add to
> 100, 
> not 1. 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> Ricardo Ovaldia
>  
> > Thank you Nick. Actualy what I was trying to do is
> > very simple (I thought).
> > 
> > Useing the auto data. I collapse to get
> percentages
> > and totals by -rep78- using:
> > 
> > .collapse (mean)  percent=foreign (count)
> > total=foreign,by(rep78)
> > 
> > This yields:
> > 
> >         rep78   percent     total
> >   1.        1         0         2
> >   2.        2         0         8
> >   3.        3        .1        30
> >   4.        4        .5        18
> >   5.        5   .818182        11
> >   6.        .        .2         5
> > 
> > Note that these are the six bars to be plotted.
> > (actualy only 5)
> > 
> > I can graph using:
> > 
> > . graph bar  percent, over( rep78)
> > 
> > But I want the variable -total- on on top of each
> > graph.
> > 
> > Ricardo.
> > 
> > 
> > --- Nick Cox <n.j.cox@durham.ac.uk> wrote:
> > 
> > > Obviously you are a discriminating person 
> > > you knows exactly what you want from Stata. 
> > > Sooner or later you will have to become 
> > > a programmer. 
> > > 
> > > I am not quite clear how your percents 
> > > are to be calculated, over all the values 
> > > or within each group. 
> > > 
> > > Here is one way for the first case. You know
> that
> > > there are 
> > > 69 values for which -foreign- and -rep78- 
> > > are not missing. You ask for a -catplot- 
> > > showing frequency. But you fix the y axis
> > > so that it shows percent. A tool for 
> > > doing this is -mylabels- from SSC. 
> > > 
> > > . mylabels 0(10)40, myscale(@ * .69) local(la)
> > > 0 "0" 6.9 "10" 13.8 "20" 20.7 "30" 27.6 "40"
> > > 
> > > . catplot bar rep78 foreign,  blabel(bar,
> > > position(outside))   yla(`la') ytitle(percent) 
> > > 
> > > So, for example, the label "40" appears at 
> > > where 27.6 would be shown on the frequency
> > > scale, because 40% of 69 is 27.6. 
> > > 
> > > Nick 
> > > n.j.cox@durham.ac.uk 
> > > 
> > > > -----Original Message-----
> > > > From: owner-statalist@hsphsun2.harvard.edu
> > > >
> [mailto:owner-statalist@hsphsun2.harvard.edu]On
> > > Behalf Of Ricardo
> > > > Ovaldia
> > > > Sent: 10 November 2005 18:08
> > > > To: statalist@hsphsun2.harvard.edu
> > > > Subject: Re: st: RE: graph bar labels
> > > > 
> > > > 
> > > > Not exactly, Nick. I basicaly plooting one
> > > variable
> > > > (percetage) over -rep78-, but will like the
> total
> > > > number of observations that when into
> calculating
> > > each
> > > > percentage on top of each bar.
> > > > 
> > > > Thank you,
> > > > Ricardo.
> > > > 
> > > > --- Nick Cox <n.j.cox@durham.ac.uk> wrote:
> > > > 
> > > > > There may be an official Stata solution, but
> > > what 
> > > > > I would recommend is that you try -catplot-
> from
> > > > > SSC. 
> > > > > -catplot- appeared early in the life of
> Stata 8
> > > > > given 
> > > > > the discovery that -graph bar- is not that
> good
> > > at 
> > > > > counting.  
> > > > > 
> > > > > . catplot bar rep78 foreign,  blabel(bar,
> > > > > position(outside))   
> > > > > 
> > > > > Is that what you want? 
> > > > > 
> > > > > Nick 
> > > > > n.j.cox@durham.ac.uk 
> > > > > 
> > > > > Ricardo Ovaldia
> > > > >  
> > > > > > I will like to place the number of
> observation
> > > on
> > > > > top
> > > > > > of each bar.  For example, using the auto
> > > data:
> > > > > > . sysuse auto, clear
> > > > > > . collapse (mean)  foreign (count)
> > > > > > total=foreign,by(rep78)
> > > > > > . graph bar  foreign, over( rep78)
> > > > > > 
> > > > > > What I want is the number in the variable
> > > -total-
> > > > > on
> > > > > > top of the corresonding graph.  I have not
> > > been
> > > > > able
> > > > > > to do this and -blabel()- does not help.
> > > > > 
> 
> *
> *   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/
> 


Ricardo Ovaldia, MS
Statistician 
Oklahoma City, OK


		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs
*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index