2014-02-10 38 views
1

排名多個變量,我有以下問題:我有我的數據,看起來像這樣:SPSS - 如何通過反覆測量

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相同),以定義我的用戶在本次實驗中使用的策略?想法?

感謝, 最佳, 尤金

+0

我不太從你的描述一定要怎麼做排名。因此,對於'UserId'1,'Act2'是最高的,因爲這些行的總和最大(例如'For UserID = 1,Act2 = 3 + 5 + 3 = 11')?大多數排名策略也需要指定如何處理關係。 –

回答

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. 

這是我的解決方案,它似乎工作!

最佳, 尤金