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

st: RE: return the name of the variable of greater rank


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: return the name of the variable of greater rank
Date   Fri, 12 Jul 2002 16:21:34 -0400

> -----Original Message-----
> From: Jose Maria Pacheco de Souza [mailto:jmpsouza@usp.br] 
> Sent: Friday, July 12, 2002 4:04 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: return the name of the variable of greater rank
> 
> 
> Dear Statalisters:
> 
>  I have, say, variables var1 var2 var3 var4 var5 varcompare . 
> I want to
> compare var1 var2 var3 var4 var5, to choose the one with the greatest
> rank. The  _name_ of the vari with the greater rank should then be the
> string "value" of varcompare for each individual.
> Is there a command for this?
> Thanks,
> Jose Maria

  gen str1 varcompare=""
  gen valmax=max(var1 var2 var3 var4 var5)
  foreach v in var1 var2 var3 var4 var5 {
    replace varcompare=varcompare+" `v'" if `v'==valmax
  }

This will put multiple varnames in the variable in case of ties.  If you
don't want that,
take out the "varcompare+" part of the replace statement.

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