Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: tslist: new and improved


From   "Michael S. Hanson" <[email protected]>
To   [email protected]
Subject   Re: tslist: new and improved
Date   Thu, 29 Jul 2004 20:12:06 -0400

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).

Thanks again to Nick and Kit.

-- Mike

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index