st: RE: Calculating Borda Count within group

 From "Stephen P Jenkins" To Subject st: RE: Calculating Borda Count within group Date Thu, 22 Apr 2004 14:59:05 +0100

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of
> Tonya Cropper
> Sent: 22 April 2004 14:22
> To: Statalist
> Subject: st: Calculating Borda Count within group
>
>
> Dear Statalisters:
>
> I wrote a program to calculate a Borda count result of
> predicted probabilities of people within groups.  The program
> calculates the results I want, but I am hoping there's a more
> efficient way of doing it.  Within each group, I want to rank
> each person's predicted probability for three outcomes(Pd,
> Pl, Pu). I have multiple sets of these probabilites based on
> different models, so I performed the counts in a loop.  I
> gave each person a score of 3 for the highest probability, 2
> for the 2nd, and 1 for the lowest. I then summed each outcome
> to get a total Borda score.  If Pd was the highest score,
> then the Borda result is 1 and 0 otherwise (I mainly care
> about Pd, ties will go to Pl, Pu is undecided).  Below is an
> example.  I will appreciate any assistance to streamline the
> program.  Thank you.
>
>         Pd1    Pl1    Pu1    death
> id1    .275    .401    .324    0
> id2    .582    .163    .255    0
> id3    .072    .630    .298    0
> id4    .489    .064    .446    0
> id5    .242    .400    .358    0
>
>
> Borda ranking result :
>                 Pd1    Pl1    Pu1
>         id1    1        3        2
>         id 2   3        1        2
>         id3    1        3        2
>         id4    3        1        2
>         id5    1        3        2
> Borda count:9    11     10
> result/borda1 = 0
> success =1 (since death=board1)
>

I think -reshape- helps.  See below

. list

+---------------------------------+
| id     p1     p2     p3   death |
|---------------------------------|
1. |  1   .275   .401   .324       0 |
2. |  2   .582   .163   .255       0 |
3. |  3   .072    .63   .298       0 |
4. |  4   .489   .064   .446       0 |
5. |  5   .242     .4   .358       0 |
+---------------------------------+

.  reshape long p, i(id) j(pr)
(note: j = 1 2 3)

Data                               wide   ->   long
------------------------------------------------------------------------
-----
Number of obs.                        5   ->      15
Number of variables                   5   ->       4
j variable (3 values)                     ->   pr
xij variables:
p1 p2 p3   ->   p
------------------------------------------------------------------------
-----

. list

+------------------------+
| id   pr      p   death |
|------------------------|
1. |  1    1   .275       0 |
2. |  1    2   .401       0 |
3. |  1    3   .324       0 |
4. |  2    1   .582       0 |
5. |  2    2   .163       0 |
|------------------------|
6. |  2    3   .255       0 |
7. |  3    1   .072       0 |
8. |  3    2    .63       0 |
9. |  3    3   .298       0 |
10. |  4    1   .489       0 |
|------------------------|
11. |  4    2   .064       0 |
12. |  4    3   .446       0 |
13. |  5    1   .242       0 |
14. |  5    2     .4       0 |
15. |  5    3   .358       0 |
+------------------------+

. bys id (p):ge r = _n

. bys pr: egen bc = sum(r)

. list

+---------------------------------+
| id   pr      p   death   r   bc |
|---------------------------------|
1. |  1    1   .275       0   1    9 |
2. |  4    1   .489       0   3    9 |
3. |  3    1   .072       0   1    9 |
4. |  2    1   .582       0   3    9 |
5. |  5    1   .242       0   1    9 |
|---------------------------------|
6. |  2    2   .163       0   1   11 |
7. |  3    2    .63       0   3   11 |
8. |  5    2     .4       0   3   11 |
9. |  1    2   .401       0   3   11 |
10. |  4    2   .064       0   1   11 |
|---------------------------------|
11. |  1    3   .324       0   2   10 |
12. |  2    3   .255       0   2   10 |
13. |  3    3   .298       0   2   10 |
14. |  4    3   .446       0   2   10 |
15. |  5    3   .358       0   2   10 |
+---------------------------------+

Now manipulate as you wish.

Stephen
-------------------------------------------------------------
Professor Stephen P. Jenkins <stephenj@essex.ac.uk>
Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374.  Fax: +44 1206 873151.
http://www.iser.essex.ac.uk

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