Thursday, February 23, 2006

st: RE: RE: graph bar: frequencies as a label

Ah! Yes indeed, that's different.

A principle often mentioned on this list, and somehow I feel a Stata Journal tip coming on for SJ 6(2) 2006, is that when the way ahead with -graph bar- is blocked, you get out of that and roll your sleeves up for a second try with -twoway bar-. Typically some preliminary spadework is needed with -gen- and -egen-.

So,

sysuse auto egen meanprice = mean(price), by(headroom) egen tag = tag(headroom) egen perc = sum(1), by(headroom) count if headroom < . replace perc = 100 * perc / r(N) gen percent = string(perc, "%5.2f")

twoway bar meanprice headroom if tag, barw(0.25) || scatter meanprice headroom if tag, ms(none) mla(percent) mlabpos(12) legend(off)

Nick n.j.cox@durham.ac.uk

Esther Kessler > thank you for your answer. I know the command catplot, but I > think I can't solve my problem with it, because the variable > price is relevant for me. I would like to show the relation > between price and headroom. In addition I would like to have > the frequencies of the variable headroom as a label above the > bars (price). I would like to show how often the headroom > 1.5, headroom 2 etc. occurs in my data. All these information > I would like to present in one graph. > > In my original data I have interval of wages (x-axis) and > effort (y-axis) and I would like to show how many people are > in each unit (wage- interval), so these units sum up to 100%. > > 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. > >

* * 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/


Tag:


Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?