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

st: Calculating Borda Count within group


From   "Tonya Cropper" <[email protected]>
To   "Statalist" <[email protected]>
Subject   st: Calculating Borda Count within group
Date   Thu, 22 Apr 2004 09:22:17 -0400

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)


*** Borda Count **
gen rPd`i'=0
gen rPl`i'=0
gen rPu`i'=0

local i=1
while i<= 3 {
if (Pd`i'>Pl`i') & (Pl`i'>Pu`i') {
replace rPd`i'=3
replace rPl`i'=2
replace rPu`i'=1
}
else if (Pd`i'>Pu`i') & (Pu`i'>Pl`i') {
replace rPd`i'=3
replace rPl`i'=1
replace rPu`i'=2
}
else if (Pl`i'>Pd`i') & (Pd`i'>Pu`i') {
replace rPd`i'=2
replace rPl`i'=3
replace rPu`i'=1
}
else if (Pl`i'>Pu`i') & (Pu`i'>Pd`i') {
replace rPd`i'=2
replace rPl`i'=1
replace rPu`i'=3
}
else if (Pu`i'>Pd`i') & (Pd`i'>Pl`i') {
replace rPd`i'=1
replace rPl`i'=3
replace rPu`i'=2
}
else if (Pu`i'>Pl`i') & (Pl`i'>Pd`i') {
replace rPd`i'=1
replace rPl`i'=2
replace rPu`i'=3
}
}
collapse (sum)rPd1 rPl1 rPu1 (sum)rPd1 rPl1 rPu1 (sum)rPd1 rPl1 rPu1
(mean)death if (ngrp>2), by(grpid)
gen borda1= ((rPd1>rPl1) & (rPd1>rPu1))
gen borda2= ((rPd2>rPl2) & (rPd2>rPu2))
gen borda3= ((rPd3>rPl3) & (rPd3>rPu3))
gen borda1s:"Borda Count/Prob 1 Success" = (death==borda1)
tab borda1s, miss

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