# Re: st: AW: Divide the time in equal intervals

 From Beatrice Crozza To statalist@hsphsun2.harvard.edu Subject Re: st: AW: Divide the time in equal intervals Date Thu, 12 Nov 2009 17:04:09 +0000

```Dear Martin,

thank you very much for your reply, but maybe I didn't explained very
well my problem.
This is my database:

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

Now I want to divide my time in 5-min interval from 8:30:00 to
17:30:00 for each day, so on 12/04/2009 I would like to have:

Date              NewTime       Quantity
12/04/2009       8:30:00             0
12/04/2009       8:35:00             0
12/04/2009       8:40:00             0
....
12/04/2009        9:10:00           5
12/04/2009       10:15:00         26  (10+16)
...               ....
How could I do?

Tank you very much

Bea

2009/11/12 Martin Weiss <martin.weiss1@gmx.de>:
>
> <>
>
>
>
> *************
> 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/
>

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