Thanks to Kit's and Nick's patient suggestions (and a peek at Kit's
-tslist- on SSC), I have come up with a version that satisfies all my
earlier criteria -- and I think I learned a thing or two in the
process. My code is below, in case anyone else would find it useful.
Suggestions for improvement are most welcome.
program tslist
version 8.2
syntax varlist [if] [in], [*]
marksample touse, novarlist
quiet count if `touse'
if r(N) == 0 error 2000
capture tsset
local timevar `r(timevar)'
local freq `r(unit1)'
if _rc>0 | "`freq'" == "." {
list `varlist' if `touse', `options'
exit
}
local vlist: subinstr local varlist "`timevar'" "", all word
if "`freq'" == "y" {
list `timevar' `vlist' if `touse', noobs `options'
}
else
{
local aidx = index("qmhwd", "`freq'")
local achc y y y q w
local aggr : word `aidx' of `achc'
tempvar agpd
gen `agpd' = `aggr'ofd(dof`freq'(`timevar'))
list `timevar' `vlist' if `touse', sepby(`agpd') noobs `options'
}
end
Note: I have only tested this with monthly and quarterly data. I'd
welcome any feedback based on other frequencies. Notice I let annual
(yearly) data default to the standard
one-separator-per-five-observations, while monthly, quarterly and
semi-annual (half-yearly) place the separator between years. Assuming
it works [untested], daily data should be divided at the week-end, and
weekly data at the quarter (13 weeks).