Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: graph bar: frequencies as a label


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: graph bar: frequencies as a label
Date   Wed, 22 Feb 2006 21:35:26 -0000

Yes; I know how to do this. 

The Visual Guide is an excellent resource on official Stata
graphics. But -- correct me if I'm wrong -- it doesn't touch on 
user-written programs. So, the usual route to follow is 

. findit bar 

which gives lots of pointers including 


FAQ     . . . . . . . . . . . . . . . . . . Creating percent summary variables
        . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox and S. Merryman
        11/05   How can I create variables containing percent
                summaries?
                http://www.stata.com/support/faqs/data/percentvars.html


SJ-4-2  gr0004  .  Speaking Stata: Graphing categorical and compositional data
        Q2/04   SJ 4(2):190--215                                 (no commands)
        discusses graphical possibilities for categorical and
        compositional data

catplot from http://fmwww.bc.edu/RePEc/bocode/c
    'CATPLOT': module for plots of frequencies, fractions or percents of
    categorical data / catplot shows frequencies (or optionally fractions or
    percents) / of the categories of one, two or three categorical variables.
    The / first named variable is innermost on the display; that is, its /

In your case, -price- is irrelevant, as you want a simple bar
chart of the frequencies of a variable. Installing -catplot- 
gives you one way 

. ssc inst catplot 
. catplot bar headroom, percent blabel(bar, format(%5.2f)) 

But you can get there with official Stata too

. histogram headroom , discrete barw(0.25) w(0.5) percent addlabels 

except that tweaking the format eludes me for the moment. 

This may be covered in Michael Mitchell's book, but I can't 
check. Colleagues grabbed my copy of the book gleefully as soon as they 
spotted it and it's hardly been in my hands since the day it 
arrived. 

Nick 
[email protected] 

Esther Kessler
 
> I would like to have the frequencies in percent above the 
> bars as a label. I couldn't find anything in the visual guide 
> to stata graphics. 
> 
> To illustrate my problem:
> sysuse auto
> tab headroom
> graph bar price, over(headroom) blabel(bar, format(5%5.2d))
> 
> Instead of the price I would like to have 5.14 above the 
> first bar (headroom 1.5), 17.57 above the second bar 
> (headroom 2.0) and so on. 
> 
> Does anybody know how to do this? 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index