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: converting high frequency data to low frequency
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: converting high frequency data to low frequency
Date
Fri, 5 Nov 2010 16:24:54 +0000
Well, it's your problem, but I'd always recommend keeping a variable that means something meaningful whenever possible. You end up with time of day coded 1-96, which is not especially transparent and certainly not compulsory.
Nick
[email protected]
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Dimitriy V. Masterov
Sent: 05 November 2010 16:20
To: [email protected]
Subject: Re: st: converting high frequency data to low frequency
Thanks to Nick and David for their help. I followed Nick's suggestion,
but I had to recode bins with no observation to zero in 2 ways:
The code below is for 15 minute time bins:
/* 1000 ms*15 minutes*60 seconds = 900000 ms */
gen double binnedtime = 900000 * floor(ordertime/900000);
format binnedtime %tc;
/* orders will contain the number of orders in each time bin, possibly zero */
contract store_id binnedtime, zero freq(orders);
xtset store_id binnedtime, delta(15 minutes);
/* This is needed to ensure all stores have the same bins */
tsfill, full;
replace orders=0 if orders==.;
/* This gives you the date */
gen date=dofc(binnedtime);
format date %td;
/* This "labels" the bin time interval. Subtracting 1000 ensure the
bins don't overlap */
gen timestr = string(hh(binnedtime),"%02.0f") + ":" +
string(mm(binnedtime),"%02.0f")+"-"+string(hh(binnedtime+900000-10000),"%02.0f")
+ ":" + string(mm(binnedtime+900000-10000),"%02.0f");
/* This gives you a variable 1-96 that corresonds to 15 min intervals
in each day */
encode timestr, gen(time)
*
* 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/