Statalist The Stata Listserver


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

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


From   "Rodrigo Martell" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Date: Thu, 7 Dec 2006 14:48:31 +1100
Date   Fri, 8 Dec 2006 09:36:55 +1100

Thanks Kyle and Nick for your suggestions.

I might try getting the date in the format 20040101040500. In fact, this is similar to how this kind of data (electricity) is treated by some. 
In Australia, electricity data (price and demand) is reported every 5-minutes (I think it might be 10,15, or 30 in the US), hence the reason why my time string goes up in 5-minute intervals.
There are 288 5-minute intervals in a day so some people write the date using a DIID (dispatch interval ID) that goes, for example, 20040101000 to 20040101287 (base of zero) for the 1st of Jan 2004. I think using -substr- to get it in this format might help, but I'm unsure whether -tsset- will like this.

I'll have a play around with both of your suggestions to see what happens.

Thanks again,

Rodrigo 

Rodrigo Martell

 <http://www.frontier-economics.com> 	
Frontier Economics Pty. Ltd.
395 Collins Street
Melbourne VIC 3000
Australia
www.frontier-economics.com 	
switch:
direct:
fax:
mobile:
email:


+61 (0)3 9620 4488
+61 (0)3 9613 1518
+61 (0)3 8614 2711
+61 (0)407 909 811
[email protected] <mailto:[email protected]> 


This e-mail, including any attachments, may contain confidential and privileged information for the sole use of the intended recipient(s). Any review, use, disclosure or distribution by others is strictly prohibited. If you are not the intended recipient (or authorised to receive information for the recipient), please contact the sender by reply e-mail and delete all copies of this message. Thank you.

	



-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Kyle Hood
Sent: Friday, 8 December 2006 3:27 AM
To: [email protected]
Subject: Re: st: RE: Date: Thu, 7 Dec 2006 14:48:31 +1100


There is a function that allows you to pick out portions of a string 
variable.  Because your variable appears to be in a fixed format, you 
might find this function useful.  This function is substr():

substr(s,n1,n2) returns the substring of s starting at n1 for a length of 
n2.  If n1<0, the starting position is interpreted as distance from the 
end of the string.  If n2 is missing (.), the remaining portion of the 
string is returned.

Thus, you can pick out the minutes digits, save this in a new variable, 
and then destring this variable.

Kyle

On Thu, 7 Dec 2006, Nick Cox wrote:

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