Page 1 of 1

daily data to quarterly, interquartile range

Posted: Mon Jun 13, 2011 10:09 am
by tclark
In a question related to the last post, does anyone have handy an easy way to, at the quarterly frequency, compute the inter-quartile range of daily (business day) data? Specifically, for each quarter, I would like to compute the 75th and 25th fractiles of daily business day data (with some obs. missing due to holidays). The COMPACT option on DATA permits the computation of the max and min, but not these fractiles. Thanks very much.

Re: daily data to quarterly, interquartile range

Posted: Mon Jun 13, 2011 2:53 pm
by TomDoan
This isn't easy, but it works:

Code: Select all

*
* Read original data with year month and day fields
*
open data djia.txt
data(format=free,org=columns) 1 18940 year month day logret logrange close low high
*
* Switch to quarterly calendar covering the period needed.
*
cal(q) 1928:4
all 1999:4
set iqrange 1928:4 1999:4 = 0.0
*
* Use STATS with FRACT and SMPL to compute 25th and 75th quantiles.
*
do time=1928:4,1999:4
   stats(fract,noprint,smpl=year==%year(time).and.(fix(month)+2)/3==%period(time)) logret 1 18940
   compute iqrange(time)=%fract75-%fract25
end do time
djia.txt
Sample data file
(1.28 MiB) Downloaded 1137 times
If the original data are read into a RATS daily calendar and the file has no break down of the dates, you can generate year, month and day before switching calendars by using

Code: Select all

set year  = %year(t)
set month = %month(t)
set day   = %day(t)

Re: daily data to quarterly, interquartile range

Posted: Mon Jun 13, 2011 3:58 pm
by tclark
Thanks very much, Tom. I'll give that a try.