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

RE: st: question: how do i...


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: question: how do i...
Date   Mon, 7 Mar 2005 12:55:04 -0000

Note that none of these give the right 
answer in the event of a tie for first place. 
Phil Schumm's code does. 

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

Matt Dobra
 
> Good game indeed!
> 
> egen max = rmax(votesa votesb votesc votesd)
> gen margin=.
> foreach x of varlist votesa votesb votesc votesd {
> replace margin=max-`x' if max-`x'<margin&max!=`x'
> }

Keith Dear
 
> > This is a good game...
> >
> > egen maxscore = rmax(votesA votesB votesC votesD)
> > gen second=.
> > foreach i of any A B C D {
> >   replace second=max(second,votes`i') if votes`i'<maxscore
> > }
> > gen margin=maxscore-second

Anirban 

> >> global lst "A B C D"
> >> egen maxscore = rmax(votesA votesB votesC votesD)
> >> foreach i of global lst {
> >> gen diff`i'= maxscore - votes`i'
> >> replace diff`i'=. if diff`i'==0
> >> }
> >> egen margin_of_victory = rmin(diffA diffB diffC diffD)


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