Dear SPSS users, I want to compute variables r1-r9 that rank within a row (pzg1-pzg9) like this: pzg1 pzg2 pzg3 pzg4 pzg5 pzg6 pzg7 pzg8 pzg9 r1 r2 r3 r4 r5 r6 r7 r8 r9 0,04 0,39 0,36 0,05 0,00 0,00 0,01 0,00 0,16 5 1 2 4 9 7 6 8 3 0,25 0,01 0,01 0,12 0,03 0,35 0,01 0,22 0,00 2 7 8 4 5 1 6 3 9 0,26 0,21 0,11 0,01 0,00 0,21 0,17 0,01 0,01 1 3 5 6 9 2 4 8 7 0,38 0,05 0,06 0,02 0,00 0,04 0,43 0,02 0,00 2 4 3 7 8 5 1 6 9 So in the first row the second variable is highest (= 1), followed by the third (=2) etc. I did it in Excel but there should be a way to solve it with SPSS?! Any ideas are welcome! Thanks, Mario Mario Giesel Munich, Germany |
Mario,
Macro !hrank in collection Horizontal tools on http://www.spsstools.net/en/KO-spssmacros ranks within cases. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by spss.giesel@yahoo.de
Here's a solution using the SPSSINC TRANS extension command. The program looks up the position in the sorted list s (counting from zero). The SPSSINC TRANS code creates new variables r1 to r9. The formula uses the shorthand <> to stand for the variable list in the variables subcommand. begin program. def index(*pzg): s = sorted(pzg) return [s.index(item) for item in pzg] end program. spssinc trans result=r1 to r9 /variables pzg1 to pzg9 /formula index(<>). On Wed, Feb 14, 2018 at 10:24 AM, Mario Giesel <[hidden email]> wrote:
|
Administrator
|
This post was updated on .
In reply to this post by spss.giesel@yahoo.de
Quick and dirty?
*EDITED* COMPUTE ID=$CASENUM. DATASET NAME raw. MATRIX. GET data /FILE */VARIABLES pzg1 TO pzg9. LOOP #=1 TO NROW(data). SAVE {ID(#),GRADE(data(#,:))}/OUTFILE */VARIABLES= ID R1 TO R9. END LOOP. END MATRIX. Ties are problematic/arbitrary as they are with your example? Mario Giesel-2 wrote > Dear SPSS users, > > I want to compute variables r1-r9 that rank within a row (pzg1-pzg9) like > this: > > pzg1 pzg2 pzg3 pzg4 pzg5 pzg6 pzg7 pzg8 pzg9 > r1 r2 r3 r4 r5 r6 r7 r8 r9 > 0,04 0,39 0,36 0,05 0,00 0,00 0,01 0,00 0,16 > 5 1 2 4 9 7 6 8 3 > 0,25 0,01 0,01 0,12 0,03 0,35 0,01 0,22 0,00 > 2 7 8 4 5 1 6 3 9 > 0,26 0,21 0,11 0,01 0,00 0,21 0,17 0,01 0,01 > 1 3 5 6 9 2 4 8 7 > 0,38 0,05 0,06 0,02 0,00 0,04 0,43 0,02 0,00 > 2 4 3 7 8 5 1 6 9 > > So in the first row the second variable is highest (= 1), followed by the > third (=2) etc. > I did it in Excel but there should be a way to solve it with SPSS?! > > Any ideas are welcome! > > Thanks,Mario > Mario GieselMunich, Germany > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by spss.giesel@yahoo.de
I haven’t worked it out so I may be missing some step (or steps) but it seems like this could be done by a varstocases and sorting and numbering within column
segment and then a casestovars back. Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of Mario Giesel Dear SPSS users, Mario Mario Giesel Munich, Germany ===================== To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Something like this?
DATA LIST LIST /pzg1 TO pzg9. BEGIN DATA 0.04 0.39 0.36 0.05 0.00 0.00 0.01 0.00 0.16 0.25 0.01 0.01 0.12 0.03 0.35 0.01 0.22 0.00 0.26 0.21 0.11 0.01 0.00 0.21 0.17 0.01 0.01 0.38 0.05 0.06 0.02 0.00 0.04 0.43 0.02 0.00 END DATA. COMPUTE ID=$CASENUM. VARSTOCASES /MAKE D FROM pzg1 TO pzg9. RANK D BY ID /RANK . FORMATS RD (F2.0). CASESTOVARS /ID=ID. DATASET NAME Ranked. Maguin, Eugene wrote > I haven’t worked it out so I may be missing some step (or steps) but it > seems like this could be done by a varstocases and sorting and numbering > within column segment and then a casestovars back. > Gene Maguin > > From: SPSSX(r) Discussion [mailto: > SPSSX-L@.UGA > ] On Behalf Of Mario Giesel > Sent: Wednesday, February 14, 2018 12:25 PM > To: > SPSSX-L@.UGA > Subject: Computing ranks within rows > > Dear SPSS users, > > I want to compute variables r1-r9 that rank within a row (pzg1-pzg9) like > this: > > pzg1 pzg2 pzg3 pzg4 pzg5 pzg6 pzg7 pzg8 pzg9 r1 > r2 r3 r4 r5 r6 r7 r8 r9 > 0,04 0,39 0,36 0,05 0,00 0,00 0,01 0,00 0,16 5 > 1 2 4 9 7 6 8 3 > 0,25 0,01 0,01 0,12 0,03 0,35 0,01 0,22 0,00 2 > 7 8 4 5 1 6 3 9 > 0,26 0,21 0,11 0,01 0,00 0,21 0,17 0,01 0,01 1 > 3 5 6 9 2 4 8 7 > 0,38 0,05 0,06 0,02 0,00 0,04 0,43 0,02 0,00 2 > 4 3 7 8 5 1 6 9 > > So in the first row the second variable is highest (= 1), followed by the > third (=2) etc. > I did it in Excel but there should be a way to solve it with SPSS?! > > Any ideas are welcome! > > Thanks, > Mario > > > Mario Giesel > Munich, Germany > ===================== To manage your subscription to SPSSX-L, send a > message to > LISTSERV@.UGA > <mailto: > LISTSERV@.UGA > > (not to SPSSX-L), with no body text except the command. To leave the > list, send the command SIGNOFF SPSSX-L For a list of commands to manage > subscriptions, send the command INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
In reply to this post by David Marso
David Marso wrote
> Quick and dirty? > *EDITED* > *EDITED again Th AM* > COMPUTE ID=$CASENUM. > DATASET NAME raw. > MATRIX. > GET data /FILE */VARIABLES pzg1 TO pzg9. > GET ID /FILE */VARIABLES ID. > LOOP #=1 TO NROW(data). > SAVE {ID(#),GRADE(data(#,:))}/OUTFILE */VARIABLES= ID R1 TO R9. > END LOOP. > END MATRIX. > > Ties are problematic/arbitrary as they are with your example? > > > Mario Giesel-2 wrote >> Dear SPSS users, >> >> I want to compute variables r1-r9 that rank within a row (pzg1-pzg9) like >> this: >> >> pzg1 pzg2 pzg3 pzg4 pzg5 pzg6 pzg7 pzg8 pzg9 >> r1 r2 r3 r4 r5 r6 r7 r8 r9 >> 0,04 0,39 0,36 0,05 0,00 0,00 0,01 0,00 0,16 >> 5 1 2 4 9 7 6 8 3 >> 0,25 0,01 0,01 0,12 0,03 0,35 0,01 0,22 0,00 >> 2 7 8 4 5 1 6 3 9 >> 0,26 0,21 0,11 0,01 0,00 0,21 0,17 0,01 0,01 >> 1 3 5 6 9 2 4 8 7 >> 0,38 0,05 0,06 0,02 0,00 0,04 0,43 0,02 0,00 >> 2 4 3 7 8 5 1 6 9 >> >> So in the first row the second variable is highest (= 1), followed by the >> third (=2) etc. >> I did it in Excel but there should be a way to solve it with SPSS?! >> >> Any ideas are welcome! >> >> Thanks,Mario >> Mario GieselMunich, Germany >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (not to SPSSX-L), with no body text except the >> command. To leave the list, send the command >> SIGNOFF SPSSX-L >> For a list of commands to manage subscriptions, send the command >> INFO REFCARD > > > > > > ----- > Please reply to the list and not to my personal email. > Those desiring my consulting or training services please feel free to > email me. > --- > "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos > ne forte conculcent eas pedibus suis." > Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in > abyssum?" > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |