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

RE: st: List options


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: List options
Date   Thu, 29 Jul 2004 23:07:55 +0100

Michael S. Hanson
 
> 	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.

You want -marksample touse, novarlist-. This is implemented
in Kit's -tslist-. 

> 	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
 

The question here really is why the first version didn't work. 
I think everything pivots on 

local yr "`yofd(dof`unit'(`timevar'))'"

There are two bugs here. First, what you are trying to do is an 
evaluation on the fly

local yr "`=yofd(dof`unit'(`timevar'))'"

(note the equals sign). However, this is still the 
wrong path to follow. What you want is in essence 
a variable, as your second version shows, but you 
can't pack a variable's values into a local macro, 
unless trivially you have just one observation. What 
you can do is put a variable name into a macro. Kit's 
gone further, but to show a solution let's polish 
your program slightly:  

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

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

	tempvar yr 
	gen `yr' = yofd(dof`unit'(`timevar'))
	char `yr'[subvarname] "year" 
 	list `yr' `timevar' `varlist' if `touse', sepby(`yr') 
	noobs subvarname `options'

end 

Note that the -preserve- is no longer needed. 
Also, we defined a characteristic to avoid the
display of an ugly temporary variable name. 




Nick 
[email protected] 

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