Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: minimum of "all other variables"


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: minimum of "all other variables"
Date   Tue, 17 Oct 2006 15:12:14 +0100

I suspect that this is clearer. It isn't 
necessary to -tokenize-. In terms of 
speed, I guess the difference is between
a blink and a wink. 

 unab myvars : price-foreign
 qui foreach v of local myvars { 
 	local others : list myvars - v 
 	local first : word 1 of `others' 
 	gen max_`v' = `first' 
 	local others : list others - first 
 	foreach w of local others { 
 		replace max_`v' = max(max_`v', `w') 
 	} 
 } 

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

> But this is faster, as it reduces the 
> interpretive overhead of ploughing through 
> -egen- repetitively. 
> 
> unab myvars : price-foreign
> qui foreach v of local myvars { 
> 	local others : list myvars - v 
> 	tokenize `others' 
> 	gen max_`v' = `1' 
> 	local others : list others - 1 
> 	foreach w of local others { 
> 		replace max_`v' = max(max_`v', `w') 
> 	} 
> } 
 
> > unab myvars : ab-AB
> > foreach v of local myvars { 
> > 	local others : list myvars - v 
> > 	egen max_`v' = rowmax(`others') 
> > } 
  
Steve Vaisey
   
> > > I have been wrestling with a problem for a while, and 
> I've finally 
> > > decided to bring it to you for what will probably be an 
> > embarassingly 
> > > quick solution. Here's the problem. Thanks to Nick, I have 
> > a program 
> > > (-myboolean-) that turns fuzzy sets into multiset fuzzy 
> > > intersections. 
> > > So, for example, with fuzzy sets A and B, running -myboolean A B- 
> > > yields four new variables: ab Ab aB AB (where lower = absence 
> > > [1-set], 
> > > upper = presence [set], and -- for example -- AB = 
> > min(A,B)). Enough 
> > > background I hope.
> > > 
> > > What I'd like to do now is to create new variables that 
> contain the 
> > > maximum value of all OTHER configurations for each configuration 
> > > produced by -myboolean-. Manually, this is easy to do: otherAB = 
> > > max(Ab,aB,ab). But with 32 or 64 configuration variables, 
> > > this is very 
> > > time consuming. Is there a way to automate this so that:
> > >      foreach var of varlist ab - AB {
> > >      gen other`var' = max(***all other vars in varlist 
> but `var'***)
> > >      }

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