Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: AW: finding date occurrences within a specified range, searching in multiple variables


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: AW: finding date occurrences within a specified range, searching in multiple variables
Date   Sun, 11 Oct 2009 18:53:00 +0100

Let me focus on one detail implicit in the sequence of postings by
Martin Weiss on this subject. 

As -foreach- can take a varlist, you can go directly to 

foreach var of varlist t_* { 

I can't see any advantage is using -ds- first in this example. The only
obvious reason for using -ds- would be as a filter to include (e.g.)
numeric variables only. 

Nick 
n.j.cox@durham.ac.uk 

Michael McCulloch

Thanks Nick, what I meant more broadly was whether multiple date  
variables, all whose names begin with "t_", for example t_date1,  
t_date2, etc., could be specified in this line, in which the second  
date is changed for a wider time frame:

> foreach var of varlist `r(varlist)'{
> 	gen byte seek`var' = `var' > td(1nov2009) & t_date <
td(9nov2009)


I also attempted a modification, which rather than giving me the id of  
only records in which any date (t_*) was within 1nov to 9nov, instead  
gave me all records and all dates:

qui ds t_*
sort id
foreach var of varlist `r(varlist)'{
	gen byte seek`var' = `var' > td(1nov2009) & `var' < td(9nov2009)
	list id seek* if `var'!=0
}




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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