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

RE: st: adding info to bar graph

From   "Buzz Burhans" <>
To   <>
Subject   RE: st: adding info to bar graph
Date   Wed, 09 Apr 2008 14:38:22 -0400


Thanks for your explanation.  I feel a bit better that I was not alone in
missing how the "5" functioned.  You were right that I didn't quite see how
the recursive use of the macro was being used, as I noted to Scott.



Buzz Burhans, Ph.D.

Dairy-Tech Group

Twin Falls, ID
Phone: 208-320-0829
Fax: 208-735-1289 

So. Albany VT
Phone: 802-755-6842


-----Original Message-----
[] On Behalf Of Nick Cox
Sent: Wednesday, April 09, 2008 1:35 PM
Subject: RE: st: adding info to bar graph

"5" looks like a typo: delete it. Otherwise the important idea is that
each time around the loop
you append a level and the text for that level, here a ratio spelled out
as numerator/denominator. 

In general, 

local macname `macname' <stuff> 

appends <stuff> to local macro macname. 


Buzz Burhans

I liked your solution for Rich's question; could you help me follow what
does with the local macro mytext?  I am having a hard time following how
Stata parses and processes this line of your program in the loop:

local mytext "`mytext' 5 `l'   "`n'/`d'"  "

Buzz Burhans, Ph.D.] On Behalf Of Scott Merryman
Sent: Wednesday, April 09, 2008 11:01 AM
Subject: Re: st: adding info to bar graph

Something like this?

sysuse auto,clear
levelsof rep, local(levels)
foreach l of local levels {
	qui count  if fore == 1 & rep == `l'
	local n = r(N)
	qui count if  rep == `l'
	local d = r(N)
	local mytext "`mytext' 5 `l'   "`n'/`d'"  "
egen percent = mean(100 * foreign), by(rep78)
egen total = sum(1), by(rep78)

twoway bar percent rep78,barw(0.5) text(`mytext', box bc(white)  )
ylabel(,angle(h)) ytitle(Percent Foreign)

On Wed, Apr 9, 2008 at 7:02 AM, Richard Goldstein
<> wrote:
> I want to produce a bar graph where the numeric variable is a 0/1
> (so the means are proportions) over a grouping variable -- that part
> easy.  I would like to automatically add, either as a bar label or
> group id (e.g., the "5", etc. if I typed -graph bar foreign,
> for the auto data), the numerator and denominator for this proportion
> -- is there a way to do that?
> Note that I do know that I can do this with graph edit; however, I
need to
> produce dozens of these graphs so I want an automatic way to do it.

*   For searches and help try:

*   For searches and help try:

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