Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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." <[email protected]>
To   "[email protected]" <[email protected]>
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: [email protected] [mailto:[email protected]] On Behalf Of Steven Samuels
Sent: Wednesday, July 13, 2011 10:19 PM
To: [email protected]
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
[email protected]



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index