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   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Date: Thu, 7 Dec 2006 14:48:31 +1100
Date   Sun, 10 Dec 2006 14:19:16 -0000

A closer look at the help for -ntimeofday- shows that the -parse()-
option, which may look a little scary, is genuinely optional and 
not needed here, as the default is to parse on spaces and colons. 

The required command is thus 

ntimeofday elecpricdema_dt , s(ymd h min s) gen(elecpricdema) n(min)

Nick 
[email protected] 

Nick Cox
 
> Here for comparison is the solution for Joseph's example 
> with -ntimeofday- from SJ 6(2). The results are, naturally,
> identical. 
> 
> clear 
> input str30 elecpricdema_dt
> "2004/01/01 04:05:00"
> "2004/01/01 04:10:00"
> "2004/01/01 04:15:00"
> end 
> ntimeofday elecpricdema_dt , s(ymd h min s) parse(" " :) 
> gen(elecpricdema) n(min)
> replace elecpricdema = elecpricdema / 5
 
Joseph Coveney replied to Rodrigo Martell 
 
> > 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.
> > 
> > --------------------------------------------------------------
> > ------------------
> > 
> > As Kyle mentioned, you can use a string function to pick out 
> > the elements of
> > the date-time value, and then use other Stata functions to get the
> > substrings into an integer that -tsset- requires.  You can do 
> > the whole
> > conversion in a single line of code, such as that below, 
> > which creates an
> > integer in units of five-minute increments.
> > 
> > Joseph Coveney
> > 
> > clear
> > input str30 elecpricdema_dt
> > "2004/01/01 04:05:00"
> > "2004/01/01 04:10:00"
> > "2004/01/01 04:15:00"
> > end
> > *
> > * Begin here
> > *
> > generate long elecpricdema = ///
> >   date(substr(elecpricdema_dt, 1, 10), "ymd") * 288 + ///
> >   real(substr(elecpricdema_dt, 12, 2)) * 12 + ///
> >   real(substr(elecpricdema_dt, 15, 2)) / 5
> > tsset elecpricdema
> > list elecpricdema_dt elecpricdema, noobs abbreviate(15)
> > exit
> > 
> > It looks like this:
> > 
> > . tsset elecpricdema
> >         time variable:  elecpricdema, 4628497 to 4628499
> > 
> > . list elecpricdema_dt elecpricdema, noobs abbreviate(15)
> > 
> >   +------------------------------------+
> >   |     elecpricdema_dt   elecpricdema |
> >   |------------------------------------|
> >   | 2004/01/01 04:05:00        4628497 |
> >   | 2004/01/01 04:10:00        4628498 |
> >   | 2004/01/01 04:15:00        4628499 |
> >   +------------------------------------+
> > 
> > . exit

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