Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Divide the time in equal intervals


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Divide the time in equal intervals
Date   Thu, 12 Nov 2009 17:44:19 +0100

<> 



*************
clear*

inp str10(Date Time) Quantity
"12/04/2009" " 9:07:21 "  5
"12/04/2009" "10:10:21 " 10
"12/04/2009" "10:13:23 " 16            
"13/04/2009" " 10:12:54" 3           
"14/04/2009" "13:20:56 " 13
end

replace Date=trim(Date)
replace Time=trim(Time)

bys Date: keep if _n==1

gen str20 start=Date+" "+ "8:30"
gen double start2= /* 
*/ clock(start, "DMYhm")

expand 103

bys Date: gen double myvar= /* 
*/ start2+(_n-1)*msofminutes(5)
format myvar %tcMon_dd,_CCYY_HH:MM
drop  start start2 Time
list, noobs h(30) sepby(Date)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Beatrice Crozza
Gesendet: Donnerstag, 12. November 2009 17:16
An: statalist@hsphsun2.harvard.edu
Betreff: st: Divide the time in equal intervals

Dear all,

I have my database with 3 variables:

     Date              Time             Quantity
12/04/2009         9:07:21           5
12/04/2009        10:10:21         10
12/04/2009        10:13:23         16
                           ...               ....
13/04/2009         10:12:54       3
                         ....               ....
14/04/2009        13:20:56        13

I would like to divide the time in equal intervals of 5-min from
8:30:00 to 17:00:00 for each day.

If I use the function:  egen newtime cut(time), at(...)

I have the result but of course in my newtime I will have only the
time that I already have in time, but equally intervalled.
Instead, I would like to have newtime for every 5-min intervals, this
means that I would like to have also 8:30:00 in my newtime with a
quantity of zero.

How can I reach this result?

Thank you very much.

Best,
Bea
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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