SPSS - 如何通过重复测量对多个变量进行排序

时间:2014-02-10 17:41:22

标签: ranking spss repeat

我有以下问题:我的数据看起来像这样:

UserId |Act1 |Act2 |Act3 |Act4
1      | 2   |  3  | 2   | 2
1      | 2   |  5  | 1   | 0
1      | 0   |  3  | 3   | 0
2      | 2   |  2  | 3   | 0
2      | 2   |  2  | 2   | 2
2      | 1   |  2  | 1   | 5
...
999    | 1   |  2  | 2   | 3

我想对每个案例的活动量进行排名,并创建一个变量“策略”。如果Act1是Act1,ACT2,ACT3和Act4中最高的那个,则“策略”应该等于“1”。如果Act2更高,那么“策略”应该等于“2”,依此类推。我有相同的UserId,因为我重复测量了相同的变量(在这个例子中是3次)。 SPSS语法代码应该如何?我可以在每个案例中循环(即使UserId是相同的)来定义我的用户在本回合中用于实验的策略吗?想法?

谢谢, 最好, 尤金

1 个答案:

答案 0 :(得分:0)

我似乎找到了解决我自己问题的方法。它看起来像这样:

/*Computing strategy*/


/*Calculating dominant action*/

LOOP #i=1 TO 999. /*Assuming I have 999 cases.

/* Calculating the biggest value among activities.
  VECTOR #act(4). /* This is a temporary array variable.
  COMPUTE #act(1) = Act1.
  COMPUTE #act(2) = Act2.
  COMPUTE #act(3) = Act3.
  COMPUTE #act(4) = Act4.

/*Bubble sorting the numbers.
   LOOP #j=1 to 3.
      LOOP #k=#j+1 TO 4.
         DO IF (#act(#k) >= #act(#j)). 

            COMPUTE #temp = #k.
            COMPUTE #act(#j) = #act(#k).
            COMPUTE #act(#k) = #temp.            

         END IF.
     END LOOP.
/*At this point we have the biggest value in the first position of the array variable, i.e. "#act(1)".




/*Here I check whether the specific action is equal to the highest score.       
     VECTOR #strat(4).
     COMPUTE #strat(1) = Act1.
     COMPUTE #strat(2) = Act2.
     COMPUTE #strat(3) = Act3.
     COMPUTE #strat(4) = Act4.

/*Here I create 2 temporary variables to fix the result.
    COMPUTE #temp1 = 0.
    COMPUTE #temp2 = 0.
/*Next step is hard to explain, but: firstly, an participant could use two strategies, which is ok; secondly, if a participant uses more than 2 strategies, I assume he was acting not strategicaly (it comes from my research design, it may not fit to yours; e.g. Act1 = 0, Act2 = 0, Act3 = 0, Act4=0; or all actions are euqal to 3).
        LOOP #m=1 TO 4.
            DO IF (#strat(#m) = #act(1)). 
               DO IF (#temp1 = 0).
                  COMPUTE #temp1 = #m. /* If the variable has the highest value it is assumed to be a strategy; the value is stored in the variable "#temp1".
               ELSE.
                  DO IF (#temp2=0). /*if the first strtegy is assigned, then the second temporry variable is used, "#temp2".
                     COMPUTE #temp2 = #m.
                  ELSE.
                     COMPUTE #temp1 = 0. /*If all more than 2 variables have "highest" score, than no strategy was played; both temporary variables are defined as 0.
                     COMPUTE #temp2 = 0.
                  END IF.
               END IF.
            END IF.

        END LOOP.
/*And finally we create variables which are stored in our dataset and prescribe them values of our temporary variables.
         COMPUTE DominantStrategy1 = #temp1.
         COMPUTE DominantStrategy2 = #temp2.

   END LOOP.
END CASE. /*Making the same with the next case.
END LOOP.

EXECUTE.

这是我的解决方案,似乎有效!

最佳, 欧根