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   Steven Samuels <[email protected]>
To   [email protected]
Subject   Re: st: count number of events within a time, when entry is lagged
Date   Wed, 13 Jul 2011 22:18:36 -0400

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]


On Jul 13, 2011, at 5:20 PM, Miller, Ann C. wrote:

Dear Statalist, 

I'm trying to determine what proportion of patients received lab tests per protocol (ie at least 1 time a month for 6 months). My dataset (currently wideform but easily transferred to long) includes the variables patient id, treatment start date, lab date1-labdate57, ast1-ast57 alt1-alt57 creatinine1-creatinine57 and so on. Some of the patients' first labs are not defined as lab1. Sometimes, the patients' first labs are lab 2, but for other patients, the first lab will be lab6 or lab14 or something. In addition, not all labs have ast, alt or creatinine values. Some labs were done for other things.

I would like to design a program that will get me the following information; 
How many patients received a test for ast, alt and creatinine in all 6 of the months after they started treatment? 

I'd be very grateful for any suggestions. Many thanks!
--Ann


Ann C. Miller, PhD, MPH
Research Associate
Department of Global Health and Social Medicine
Harvard Medical School


*
*   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/


*
*   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