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: converting high frequency data to low frequency


From   "Dimitriy V. Masterov" <[email protected]>
To   [email protected]
Subject   Re: st: converting high frequency data to low frequency
Date   Fri, 5 Nov 2010 12:20:14 -0400

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/


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