Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: RE: AW: finding date occurrences within a specified range, searching in multiple variables
Date   Sun, 11 Oct 2009 20:26:58 +0200

<> 

" I can't see any advantage is using -ds- first in this example."

Neither do I, and that is why I used the approach you are suggesting in
later posts, as witnessed here:
http://www.stata.com/statalist/archive/2009-10/msg00459.html

It is pretty much akin to what Maarten and I discussed yesterday in
http://www.stata.com/statalist/archive/2009-10/msg00475.html and follow-ups:
-postfile- is a very general tool, but in the case described by John,
-statsby-, as suggested by Maarten, sufficed. 

The same principle applies to Michael`s query: -ds- takes care of this _and
more_, but -foreach- is happy to expand a standard -varlist- for Michael...


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Sonntag, 11. Oktober 2009 19:53
An: [email protected]
Betreff: RE: st: RE: AW: finding date occurrences within a specified range,
searching in multiple variables

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 
[email protected] 

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/


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index