# RE: st: adding info to bar graph

 From "Buzz Burhans" To Subject RE: st: adding info to bar graph Date Wed, 09 Apr 2008 13:12:59 -0400

```Scott,
I liked your solution for Rich's question; could you help me follow what it
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.

statalist@hsphsun2.harvard.edu] On Behalf Of Scott Merryman
Sent: Wednesday, April 09, 2008 11:01 AM
To: statalist@hsphsun2.harvard.edu
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)

Scott

On Wed, Apr 9, 2008 at 7:02 AM, Richard Goldstein
<richgold@ix.netcom.com> wrote:
> I want to produce a bar graph where the numeric variable is a 0/1 variable
> (so the means are proportions) over a grouping variable -- that part is
> easy.  I would like to automatically add, either as a bar label or under
the
> group id (e.g., the "5", etc. if I typed -graph bar foreign, over(rep78)-
> for the auto data), the numerator and denominator for this proportion
(mean)
> -- 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.
>
> Thanks,
>
> Rich Goldstein
*
*   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/

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