Statalist


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

st: AW: Keep an observation if the time of the obs. is closest to another time


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Keep an observation if the time of the obs. is closest to another time
Date   Fri, 7 Aug 2009 14:31:03 +0200

<> 

This code takes you to the point where you have your difference in hand, but
I cannot figure out what you want to happen next from your description...


*************
clear*

input Id  str10(drugadmdate   drugadmtime  /* 
 */  careunitdate   careunittime    careunit)
1  2mar06  11.15  2mar06   10.01  Cardio
1  2mar06  11.15  2mar06   11.25   Inf.dis
end

compress 

gen careunittime2= /* 
 */ careunitdate + " " + careunittime

gen double careunittime3= /* 
 */ clock(careunittime2, "DM20Yhm")

format careunittime3 %tc

gen drugadmtime2= /* 
 */ drugadmdate + " " + drugadmtime

gen double drugadmtime3= /* 
 */ clock(drugadmtime2, "DM20Yhm")

format drugadmtime3 %tc

//get diff
gen double diff= /* 
 */ minutes(careunittime3- /* 
 */ drugadmtime3)

la var diff /* 
 */ "Difference in Minutes"

list, noobs

*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Thomas Cars
Gesendet: Freitag, 7. August 2009 13:12
An: statalist@hsphsun2.harvard.edu
Betreff: st: Keep an observation if the time of the obs. is closest to
another time

Hi,
I am working with two datasets, the first dataset includes date and  
time for a drug administration for a patient  and the second includes  
date and time for which care units the patient have been visit the  
same date for the drug administration.
In some cases, the patient have visit two or more care units the same  
day and then the drug administration is matched/connected to two or  
more care units. I now want to ?match? (eg. drop care units) the drug  
administration with the care unit closest in time for the drug  
administration.
Are there any command in STATA like ?keep if time is closest to another
time?

Example (the drug administration is now connected to two care units)


Id   drug. adm.date   drug. adm.time   care.unit.date   careunit.time   
  careunit
1    2mar06           11.15            2mar06           10.01
Cardio
1    2mar06           11.15            2mar06           11.25           
  Inf.dis


I now want to keep the second row, the one that the time for drug.adm  
is closest in time to the care unit time.

I hope anyone can help be!
/Thomas



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