<>
Note that your initial times get lost in my approach, and you end up with
five minutes intervals on the days you specified. Getting your "12/04/2009
9:07:21" and so on into the correct place is more cumbersome, but possible:
****
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)
tempfile temp
save `temp', replace
bys Date: keep if _n==1
replace Quantity=0
replace Time=""
gen str20 start=Date+" "+ "8:30"
gen double start2= /*
*/ clock(start, "DMYhm")
expand 103
bys Date: gen double myvar= /*
*/ start2+(_n-1)*msofminutes(5)
drop start start2
tempfile temp2
save `temp2', replace
u `temp', clear
gen str20 newvar=Date+" "+Time
gen double myvar=clock(newvar, "DMYhms")
drop newvar
append using `temp2'
format myvar %tcMon_dd,_CCYY_HH:MM
sort myvar
list, noobs h(30) sepby(Date)
****
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 12. November 2009 17:44
An: [email protected]
Betreff: st: AW: Divide the time in equal intervals
<>
*************
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: [email protected]
[mailto:[email protected]] Im Auftrag von Beatrice Crozza
Gesendet: Donnerstag, 12. November 2009 17:16
An: [email protected]
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/
*
* 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/