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

Re: st: Re: what time is it?


From   "Jesper B. Sorensen" <[email protected]>
To   [email protected]
Subject   Re: st: Re: what time is it?
Date   Fri, 27 Sep 2002 15:14:22 -0400


I did not see the original posting, but if a string version of the date and time variable will work, you can do something like the following, using the datestamp variable from my earlier posting. The datestamp variable can also be the difference between two points in time. (xx is just a placeholder)

gen day=int(datestamp)
gen double xx=datestamp-int(datestamp)
gen hr = int(xx*24)
replace xx=((xx*24)-hr)
gen min = int(xx*60)
gen sec = (xx*60-min)*60



gen str30 datestr= string(day,"%d") + ":" + string(hr,"%02.0f") + ":" + string(min,"%02.0f") + ":" + string(sec,"%04.1f")

Other variants are of course possible, and once settled upon likely best put in an ado file for personal use.


At 09:39 AM 9/27/2002 -0400, you wrote:

<snip>
> I agree that it might be nice in some situations to have a format that specified
> the exact time as well as the day.
>
> //Jesper
>
<more snip>

I hate to SAS you all, but what I'm looking for is this:

gen DATE=mdy(mon_var,day_var,yr_var) we've got this in Stata
TIME=hms(hr_var,min_var,sec_var) SAS code
DATETIME=dhms(DATE,hr_var,min_var,sec_var) SAS code

As Kit noted, I need to be able to calculate the difference between two
date/time points and display it in a meaningful way which may include
hours, minutes and seconds.
*
* 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/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jesper B. S�rensen
Richard S. Leghorn (1939) Associate Professor of Strategic Management
Sloan School of Management
Massachusetts Institute of Technology
E52-581
Cambridge, MA 02142
http://web.mit.edu/sorensen/www/
(617) 253 7945  -- voice
(617) 253 2660  -- fax

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