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

st: RE: RE: generating a moving sum


From   Alexander Tsai <act2@cwru.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: RE: generating a moving sum
Date   Sun, 23 Nov 2003 17:29:02 -0500

Thank you Nick. That was painful but worked like a charm.

Alex Tsai

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Sunday, November 23, 2003 12:31 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: generating a moving sum


I hate to say it, but a loop is one way out.

levels hospid, local(H)
levels doadmit, local(D)
gen nprev90 = .

foreach h of local H {
	foreach d of local D {
		qui count if hospid == `h' & doa < `d' & doa >= (`d' -
90)
		replace nprev90 = r(N) if hospid == `h' & doa == `d'
	}
}

Nick
n.j.cox@durham.ac.uk




*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index