Search code examples
syntaxspss

Using syntax to add a count of the number of cases which match that case's value


I don't think this matches any existing question but it seems kind of fundamental.

I have a variable full of ranks. Think of it like people who ran a marathon and their places. But there are lots of draws so there might be 5 firsts and 4 seconds and 9 thirds and so on.

Each case has a variable with their place except the people who finished third are not actually third. They are joint 10th from the above figures. The people who finished second are joint 6th.

How do I create a new variable with the marathon runners actual places in the race?


Solution

  • If I understand right, you want the Nth place to reflect the number of actual people above in the list? Here is a way to do that:

    sort cases by OrigPlace.
    compute MyPlace=OrigPlace.
    if $casenum>1 and OrigPlace<>lag(OrigPlace) MyPlace=$casenum.
    if $casenum>1 and OrigPlace=lag(OrigPlace) MyPlace=lag(MyPlace).
    exe.