# Re: st: question: how do i...

 From "Eric G. Wruck" To statalist@hsphsun2.harvard.edu Subject Re: st: question: how do i... Date Sun, 6 Mar 2005 23:16:37 -0500

```I like Phil Schumm's solution but wanted to see if I could come up with a way to identify the second largest.  As primitive as it is, this seems to work:

2. replace `var' = . if `var' == max
3. }
(1 real change made, 1 to missing)
(4 real changes made, 4 to missing)

. gen mofv = max - second

. l

+-----------------------------------------------------------------+
|-----------------------------------------------------------------|
1. |     1       10        1        6        .    21       10     11 |
2. |     2       11        2        7        .    22       11     11 |
3. |     3       12        3        8        .    13       12      1 |
4. |     4        1        .        2        3     4        3      1 |
5. |     5        2        5        3        .     7        5      2 |
+-----------------------------------------------------------------+

You may have a problem with ties but you didn't specify how you wanted to handle any such eventuality.

Best wishes,

Eric

>i have the following problem:
>
>i want to construct a variable called margin of victory:
>
>my data set looks something like this:
>
>
>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
>
>
>
>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

--

===================================================

Eric G. Wruck
Econalytics
Columbus, OH  43209

ph:      614.231.5034
cell:    614.327.4182
fax:     614.231.5039
eFax:    614.573.6639
eMail:   ewruck@econalytics.com
website: http://www.econalytics.com

====================================================
*
*   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/
```