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

st: RE: RE: Calculating Borda Count within group


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Calculating Borda Count within group
Date   Thu, 22 Apr 2004 15:11:16 +0100

In addition, check out -rowranks- on SSC. 

Nick 
[email protected] 

Stephen P Jenkins replied to Tonya Cropper
> > 
> > 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.
> 
> 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. 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index