Note that none of these give the right
answer in the event of a tie for first place.
Phil Schumm's code does.
Nick
[email protected]
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/