Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Date: Thu, 7 Dec 2006 14:48:31 +1100


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Date: Thu, 7 Dec 2006 14:48:31 +1100
Date   Thu, 7 Dec 2006 15:19:38 -0000

There is no way that -destring- can do what you want here, 
and I speak as its original author still proud of my offspring, 
despite all that StataCorp programmers have done to it since
it left home. 

-destring- is basically for numbers trapped inside string bodies, 
such as the string "42" which manifestly would convince all
concerned if remodelled as numeric 42. But even shorn of all spaces and 
punctuation, there is no sense in which  

2004/01/01 04:05:00

would be much use to you reborn as 

20040101040500 

In othr words, -destring- has an -ignore()- option which 
could be used to get numbers out of your strings, but it is not 
the answer here. You need code that is smart about seconds, minutes, 
hours, etc., etc.  

What you want is reasonable, but what is available to do it 
consists only of user-written programs. Still, you might 
-search- for -ntimeofday- and -stimeofday- and try them out. 

Once you have a date-time expressed in minutes, produce 
a version that is divided by 5 for -tsset-. You'll need to 
juggle three versions of the same information, your string 
for meaning, a date-time number, and something -tsset- will
treat as you want.

Nick 
[email protected] 

Rodrigo Martell
  
> I've loaded some data into Stata. The date variable is a 
> string and looks like this (yyy/mm/dd hh:mm:ss):
> 2004/01/01 04:05:00
> 
> 2004/01/01 04:10:00
> 
> 2004/01/01 04:15:00
> 
> I've been trying to convert the string to Stata dates (and 
> time) to no avail. I want to eventually -tsset- the 
> (5-minute) time variable. -destring- won't do because it 
> doesn't like the / and : (or the spaces I assume) in the date.
> 
> Does anyone have any hints? I'd appreciate it.

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