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

st: question: how do i...


From   "israel solaresbravo" <israelsolaresbravo@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: question: how do i...
Date   Mon, 07 Mar 2005 01:53:24 +0000

dear all,

i have the following problem:

i want to construct a variable called margin of victory:

my data set looks something like this:


state votesA votesB votesC votesD
1 10 1 6 21
2 11 2 7 22
3 12 3 8 13
4 1 4 2 3
5 2 5 3 7


my question is:

how do i create a variable called margin_of_victory = votes for 1st place - votes for 2nd place?, i.e. 21-10 for state 1, 22 - 11 for state 2, 13 - 12 for state 3, 4 - 3 for state 4, etc.

i can't do this by hand, since i have a huge data set.

i know that the command

. egen margin_of_victory = rmax (votesforA votesforB votesforC votesforD)


will help me pick the biggest number in each row, but how do i get to choose the 2nd biggest number?

thanks many, and sorry if this is a silly question.

thanks many.

ISB

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

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