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

st: Re: Adding sample sizes to graph


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Adding sample sizes to graph
Date   Mon, 12 Jan 2004 09:11:54 -0800 (PST)

--- "Wagner, Joseph" <[email protected]> wrote:
> I think this is a fairly simple question but I didn't see anything
> similar in the archive.  I have a large number of scatter plots
> that I need to generate but I have been asked to include the sample
> sizes in the graphs.
> For example, I want to do a scatter of bmi by age for HIV- and HIV+
> so I would like to get the sample size reported in each graph but I
> don't want to have to type the sample size for each graph I will
> need.
> 
> scatter bmi age, by(hivst)

Joseph,

I am sure there is a more elegant solution but here is one way to add
the sample sizes.

. sysuse auto
. count if mpg<. & weight<. & foreign==0
. gen sample = r(N) if foreign==0
. count if mpg<. & weight<. & foreign==1
. replace sample = r(N) if foreign==1
. sum weight if mpg<. & foreign<.
. gen xpos = r(max)
. sum mpg if weight<. & foreign<.
. gen ypos = r(max)
. twoway (scatter mpg weight) (scatter ypos xpos, mlabel(sample)
msymbol(i)), by(foreign, legend(off))

I tried the -text- option but don't know how to show the sizes of the
two -by- samples only once in the graph. The -scatter- command below
adds the text "N = 52" and "N = 22" twice to the graph. Can another
list member suggest how to show the sample sizes only once?

. 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'")

Friedrich Huebler

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
*
*   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