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

RE: st: count (Stata 8)


From   Heather Gold <[email protected]>
To   [email protected]
Subject   RE: st: count (Stata 8)
Date   Tue, 10 May 2005 16:21:33 -0400

Thanks - this works perfectly to give both scalars and variables. I appreciate your help!
At 03:02 PM 5/10/2005, you wrote:

I'm on record as a big fan of -foreach- but this problem
doesn't seem to need a loop at all.

Nevertheless, you want scalars, although I am not clear why.

You can have it both ways by having variables and scalars too.
(The variables will come in useful for graphs and tables.)

egen cases = sum(dflag), by(year)
egen n = sum(1), by(year)
gen prevalence = cases / n
tabdisp year, c(prevalence)

levelsof year, local(Y)
foreach y of local Y {
        su prev if year == `y', meanonly
        scalar prev`y' = r(min)
}

Nick
[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/



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