daily data to quarterly, interquartile range
daily data to quarterly, interquartile range
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
Economic Research Dept.
Federal Reserve Bank of Cleveland
Re: daily data to quarterly, interquartile range
This isn't easy, but it works:
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
*
* 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 timeCode: Select all
set year = %year(t)
set month = %month(t)
set day = %day(t)Re: daily data to quarterly, interquartile range
Thanks very much, Tom. I'll give that a try.
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
Economic Research Dept.
Federal Reserve Bank of Cleveland