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

st: Re: Adding sample sizes to graph


From   "Wagner, Joseph" <[email protected]>
To   "STATAList ([email protected])" <[email protected]>
Subject   st: Re: Adding sample sizes to graph
Date   Wed, 14 Jan 2004 14:34:35 -0500

 --- "Friedrich Huebler <huebler@r...> wrote:
> Is it possible to add different text to the individual plots in a
> by() graph? In a response to a question by Joseph Wagner I posted
> these commands two days ago:
> 
> . sysuse auto
> . count if mpg<. & weight<. & foreign==1
> . local for = string(r(N), "%2.0f")
> . count if mpg<. & weight<. & foreign==0
> . local dom = string(r(N), "%2.0f")
> . scatter mpg weight, by(foreign) text(40 1000 "N = `for'") text(40
> 4000 "N = `dom'")

Unfortunately this method didn't work for me, I did not get sample sizes:

count if bmi<. & age<. & hivst==1
gen sample = r(N) if hivst==1
count if bmi<. & age<. & hivst==2
replace sample = r(N) if hivst==1
sum age if bmi<. & hivst<.
gen xpos = r(max)
sum bmi if age<. & hivst<.
gen ypos = r(max)
twoway (scatter bmi age) (scatter ypos xpos, mlabel(sample) msymbol(i)),
by(hivst, legend(off))

The method Nick Cox described did give me my sample sizes but I now have
been asked to do the same for box plots that are over twice.

graph box bmi, medtype(line) over(sex, label(labsize(small))) over(hivst)
box(1, bfcolor(none)) ///
box(2, bfcolor(none)) blabel(total, position(inside) format(%9.1f))

-hivst- and -sex- are numeric with value labels

I was wondering about the blabel option.  Is it possible to get blabel to
produce the count for that particular box?
*
*   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