Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: hours:minutes:seconds


From   "Radu Ban" <[email protected]>
To   <[email protected]>
Subject   st: Re: hours:minutes:seconds
Date   Mon, 16 Dec 2002 15:54:32 -0500

you can try sth like:
if your_time is the variable you have for time

gen str8 stime = your_time
gen shours = substr(stime, 1, 2) *takes the first two digits
gen hours = real(shour) *reads first two digits as number
gen sminutes = substr(stime, 4, 2) *takes digits 4 and 5
gen minutes = real(sminutes)
gen sseconds = substr(stime, 7, 2)
gen seconds = real(sseconds)

*now add up
gen totsecs = 3600*hours + 60*minutes + seconds
  
----- Original Message ----- 
From: "Christa Scholtz" <[email protected]>
To: <[email protected]>
Sent: Monday, December 16, 2002 3:33 PM
Subject: st: hours:minutes:seconds


> Hi,
> 
> I have a data field where the duration of an event is recorded in this
> format:
> 
> hour:minute:second
> 
>  eg:  an event that lasts 5 hours, 27 minutes and 13 seconds is 5:27:13.
> 
> 
> 
> How do I get Stata to convert this into total number of seconds?
> 
> Thanks,
> 
> Christa
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
> 



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index