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: aggregate by high frequency data
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: aggregate by high frequency data
Date
Wed, 27 Jun 2012 18:16:36 +0200
On Wed, Jun 27, 2012 at 5:39 PM, tashi lama wrote:
> If I want to aggregate hits per day, then I would do sth like
>
> gen daily=dofc(read_date)
>
> collapse (sum) hits, by(daily)
>
> Does anyone have any idea aggregating per min or per hr or per sec for that matter? There doesn't seem to have a date-related command to do that both in manual and help?
see -help datetime-, in particular the section labeled "Extracting
time-of-day components from SIFs"
*------------- begin example ------------------
clear
input str18 read_date byte hits
"04jan2011 01:01:41" 1
"04jan2011 01:03:07" 1
"04jan2011 01:04:06" 1
"04jan2011 01:08:21" 1
"04jan2011 01:09:28" 1
"04jan2011 01:58:34" 1
"04jan2011 02:05:04" 1
"04jan2011 02:16:45" 1
"04jan2011 02:18:06" 1
"04jan2011 02:22:34" 1
end
gen double date = clock(read_date, "DMYhms")
format date %tc
gen float daily = dofc(date)
format daily %td
gen byte hourly = hh(date)
collapse (sum) hits, by(daily hourly)
list
*-------------- end example -------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
-- Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/