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

Re: st: List options


From   "Michael S. Hanson" <[email protected]>
To   [email protected]
Subject   Re: st: List options
Date   Thu, 29 Jul 2004 16:36:22 -0400

Thanks to Nick & Kit for their very helpful sample programs. I have tried to combine and modify what they presented, but I'm still having some difficulties writing a version that does exactly I want. Despite reading what I think are the relevant parts of the manuals, I have run into the following issues:

1. I want to see the dates that contain *any* of the variables to be listed, with missing values indicated as appropriate. A consequence of using the -marksample touse- command (I think) is that only dates with *all* the variables to be listed are shown. Put another way, I want to see the union and not the intersection of the samples corresponding to the varlist. Simply dropping the -marksample- command caused all -if- conditions added to -tslist- calls to be ignored, which is no solution.

2. Since I want a list by the time series variable, and since this is easily recovered from the -tsset- command as `r(timevar)', I made this the first argument in the list (see below). However, I'd like to be able to purge the timevar from the varlist if the user (me) inadvertently included it -- that is, have the timevar listed once (first) rather than twice. However, I could not figure out how to drop the timevar from the varlist if it was included.

3. -sep()- puts the dividers in the "wrong" place if the sample doesn't start with the first sub-unit of time of the year. For example, -sep(4)- with data starting in the third quarter places the separator between Q2 and Q3 of subsequent years, rather than at the change in year (the "natural" place). In theory, I can get around this problem by using -sepby()- instead of -sep()- as the option on -list- in my program, if I can identify the year changes. Here is a version of I have tried:


program tslist

version 8.2
syntax varlist [if] [in], [*]
marksample touse

capture tsset
local timevar `r(timevar)'
local unit `r(unit1)'

local yr "`yofd(dof`unit'(`timevar'))'"
list `yr' `timevar' `varlist' if `touse', sepby(`yr') noobs `options'

end


Problem is, this doesn't have any effect -- the separators still occur every 5 observations. Moreover, the variable `yr' does not show up in the listing (added simply to troubleshoot), so apparently it is not defined correctly. I've tried various permutations of the single and double quotes, but nothing helped. (In fact, most just retuned an error.)

If I replace the last two lines with:


gen yr = yofd(dof`unit'(`timevar'))
list yr `timevar' `varlist' if `touse', sepby(yr) noobs `options'


and add a -preserve- after the -version- line, it then works as intended.(!) S

Suggestions are welcome, especially ideas on how to address the first two issues listed above. (Yes, at some point I also should add some error checking as Nick and Kit did in their versions, but I still am learning to crawl here....) TIA.

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