daily data to quarterly, interquartile range

For questions and discussion related to reading in and working with data.

daily data to quarterly, interquartile range

Postby tclark » Mon Jun 13, 2011 10:09 am

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
tclark
 
Posts: 35
Joined: Wed Nov 08, 2006 4:20 pm

Re: daily data to quarterly, interquartile range

Postby TomDoan » Mon Jun 13, 2011 2:53 pm

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 115 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)
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: daily data to quarterly, interquartile range

Postby tclark » Mon Jun 13, 2011 3:58 pm

Thanks very much, Tom. I'll give that a try.
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
tclark
 
Posts: 35
Joined: Wed Nov 08, 2006 4:20 pm


Return to Data: Reading, Writing, Transforming

Who is online

Users browsing this forum: No registered users and 0 guests