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: AW: Merging 2 variables to calculate time elapse (time/date)


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Merging 2 variables to calculate time elapse (time/date)
Date   Thu, 15 Apr 2010 13:08:10 +0200

<> 


Amy, you may want to try this example code. Time and date issues are a
recurring theme on the list, and I am not sure whether this solution is the
most elegant one, but it works:


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

inp byte patid Var1date Var2date  /* 
*/ str10(Var1time Var2time)
1 16874 16871 "12-31" "13-43"
2 16885 16879 "01-11" "10-21"
3 16732 16730	"10-00" "10-00"
end

gen stringVar1=string(Var1date,"%dD_m_Y")+" "+ Var1time
gen stringVar2=string(Var2date,"%dD_m_Y")+" "+ Var2time
gen double minutediff= /* 
*/ minutes(clock(stringVar1, "DM20Yhm")- /* 
*/ clock(stringVar2, "DM20Yhm"))
list, noo

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



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Penn, Amy
Gesendet: Donnerstag, 15. April 2010 11:37
An: statalist@hsphsun2.harvard.edu
Betreff: st: Merging 2 variables to calculate time elapse (time/date)

Dear Statalist users,

I am very much a beginner in Stata, and I have Stata 11.0.  I have read the
?help dates? instructional from Stata, but am still confused.  For my
project in the Zambian hospital setting, I must calculate the elapsed time
in minutes of 2 sets of variables, they are:

Var1date: Date patient departed from the clinic
Var1time: Time patient departed from the clinic

Var2date: Date patient arrived at the hospital
Var2time: Time patient arrived at the hospital

The time variables have type ?str5? and format ?%5s.?  The date variables
have the type ?long? and format ?%dD_m_Y.?  (I also do not quite understand
the meaning of ?str5,? ?%5s,? and ?long.?)  

I would like to calculate the time difference (in minutes) between the time
the patient left the clinic to when the patient arrived at the hospital.
How would I merge, for example, Var2date and Var2time into ?Var2? from which
I may subtract Var1 (Var2-Var1 = time transport takes).

Thanks very much for your consideration,
Amy

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