daily data to quarterly, interquartile range

For questions and discussion related to reading in and working with data.
tclark
Posts: 99
Joined: Wed Nov 08, 2006 3:20 pm

daily data to quarterly, interquartile range

Unread post 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.
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: daily data to quarterly, interquartile range

Unread post 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 1136 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)
tclark
Posts: 99
Joined: Wed Nov 08, 2006 3:20 pm

Re: daily data to quarterly, interquartile range

Unread post by tclark »

Thanks very much, Tom. I'll give that a try.
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
Post Reply