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 on April 23, and its replacement, statalist.org is already up and running.


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

st: While/if for individual observations


From   "Williams, Barbara" <Barbara.Williams@vmmc.org>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: While/if for individual observations
Date   Wed, 20 Mar 2013 19:10:08 +0000

My data:
I have a list of 20,000+ patient visits to a clinic with the following 3 variables:

ID  VisitDate Antibiotics_YN
100 01feb2011 0
100 02feb2011 0
100 04feb2011 1
100 10may2011 1
100 10oct2011 1
101 01feb2011 0
101 12mar2011 0
101 13mar2011 0
101 14mar2011 0
101 18mar2011 1
...

My question:
I would like to create a new variable which labels Antibiotics WITHIN 28 days of their first visit.
AND If the patient has another visit more than 28 days after the first visit, the time is re-set (new series).
For ID=100 First series of visits beginning 01feb2011 Antibiotics on visitday = 4
                    Second series of visits beginning 10may2011 Antibiotics on visitday = 1
                   Third series of visits beginning 10oct2011 Antibiotics on visitday  =1
For ID=101 First series of visits beginning 01feb2011 No antibiotics
                   Second series of visits beginning 12mar2011 Antibiotics on visitday = 6


My syntax (doesn't run, I'm not sure how to do this):
local i = 1
local N = _N
while `i' <=`N'   {
   local firstdate = VisitDate[`i']
   while ID[`i'] == ID[`i' - 1] & VisitDate[`i'] <= firstdate + 28 {
       replace abxin28days[`i'] = 1 + abxin28days[`i']
                   local `i' = `i' + 1 }
   replace firstdate[`i'] = VisitDate[`i'] if _n==`i' 
   }

THANK YOU!

****************** CONFIDENTIALITY DISCLAIMER ******************

The information contained in this e-mail may be confidential. IF YOU
RECEIVED THIS IN ERROR, please call the Virginia Mason Privacy Officer
at 206-223-7505. Thank you.

Patients: E-mail is NOT considered secure. By choosing to communicate
with Virginia Mason by e-mail, you will assume the risk of a confidentiality
breach. Please do not rely on e-mail communication if you or a family
member is injured or is experiencing a sudden change in health status. 

If you need emergency attention, call 911.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index