Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: count number of events within a time, when entry is lagged


From   "Miller, Ann C." <Ann_Miller@hms.harvard.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: count number of events within a time, when entry is lagged
Date   Thu, 14 Jul 2011 10:58:20 -0400

Thank you Steve, for taking the time to do this! Hugely useful and taught me a lot.  
--Ann



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Steven Samuels
Sent: Wednesday, July 13, 2011 10:19 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: count number of events within a time, when entry is lagged 

Oops, I forgot to "generate" some variables, corrected below.
Steve

By all means convert your data to long format.

Then your data will look like

id treatment start_date index lab_date ast alt creatine

with index having values 1-57. However, you do not need this variable below, though you might want to check that dates were in index order.

Your protocol is ambiguous because months have differing numbers of days.  I'm going to use 30 day months here, but you might choose to modify the definition. Also, save interim data sets along the way.

Then:
************************
drop index
sort id lab_date
gen days_study = (lab_date - start_date)
gen month_study = int((days_study-1)/30) +1
gen had_ast = ast!=.
gen had_alt = alt!=.
gen had_cre = creatinine!=.
// Now get monthly totals of tests
egen msum_ast = total(had_ast), by(id month_study)
egen msum_alt = total(had_alt), by(id month_study)
egen msum_cre = total(had_cre), by(id month_study)
bys id month_study: keep if _n==1
gen m_ok = msum_ast>0 & msum_ast<. ///
        & msum_alt>0 & msum_alt<. ///
        & msum_cre>0 & msum_cre<.
egen nmonths_ok =total(m_ok), by(id)
bys id: keep if _n==1
tab nmonths_ok, missing 
*************************************

Steve
sjsamuels@gmail.com



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index