Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: adding variables within time range


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: adding variables within time range
Date   Sun, 24 Nov 2013 15:04:10 -0500

Hello Greg.

input Time      Length
236         24
145         300
218         10
2334       31
end

generate Hour=floor(Time/100)
generate period=floor((Hour+1)/2)
list
collapse (sum) Length, by(period)
list

Note that your first period (period 0) is from 0 to 1 hour, others are
2 hours long. Hence +1 in the code for Hour.

Splitting 300 over multiple periods would have been more challenging
task. Make sure you've chosen the right option.

Best, Sergiy


On Sun, Nov 24, 2013 at 2:12 PM, Coleman, Greg <[email protected]> wrote:
> Hi Stata users - so new at Stata I am not sure how to word this. I have data with the time variable in military format. There is also another variable in the row which is an integer just representing length of time,  in minutes. A small snip is as follows:
>
> Time      Length
> 236         24
> 145         300
> 218         10
> 2334       31
>
> What I want to do is add length, for all times occurring between 1 and 3am, 3-5am, and so on.
> In this example 1-3am would be = 24+300+10.
>
> Do I have to create a new variable for each time slice I choose? If so, how would I do the addition?
> Thank you!
> Greg
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index