One way to do this is to use -ci- and a foreach loop
get the scalars at each iteration.
Fred
At 09:54 AM 5/10/2005, you wrote:
Dear Listers -
I know this must be simple, but something eludes me.
I have a data set of subjects (cases and non-cases) by year and am trying
to calculate a prevalence per year, ie, [cases/(cases+noncases)].
ie, data look like this:
id year dxflag
1 1995 1
1 1996 0
1 1997 0
2 1995 0
2 1996 1
...
I found that I can write
by year: count if dxflag==1
or
by year: count
and these return number of cases in the first line, and count of total
population in the second line, just as I want.
But what I need are these values as scalars, so I can create a prevalence
per year. In the Stata 8 help/manual it says that -count- saves the scalar
of number of observations in r(N), but I can't seem to get this number to
appear. Do I actually have to write a program to calculate this? And how
does the "by year" part fit in...?
Thanks for your help,
Heather
*
* 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/
Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125 Fax (316) 263-0761
[email protected]
*
* 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/