Assigning Partner Values ​​to Paired Strings in SPSS

Imagine a dataset with pairs of participants ("Pair" 1-10), each with a unique identifier ("Person" 1 or 2). Each of these persons in a pair has a unique value for some variable, call it "Actor". I want to write a script that takes the value of "Actor" for an individual and puts it in a new variable for another person in the "Partner" pair. Thus, each Person (line) will have value for himself ("Actor") and the value of his partner ("Partner").

The method I tried involves restructuring:

SORT CASES BY Couple.
CASESTOVARS
  /ID=Couple
  /GROUPBY=VARIABLE.

COMPUTE Partner.1=Actor.2.
COMPUTE Partner.2=Actor.1.
EXECUTE.

VARSTOCASES
  /MAKE Person FROM Person.1 Person.2
  /MAKE Actor FROM Actor.1 Actor.2
  /MAKE Partner FROM Partner.1 Partner.2
  /INDEX=Index1(2) 
  /KEEP=Couple 
  /NULL=KEEP.

      

This now works great for a small, hypothetical dataset I created. However, I would like the script to be able to handle more variables without having to manually enter more / MAKE commands.

Something like that?

for i in varlist[var=all]
do
VARSTOCASES
/MAKE i FROM i.1 i.2
/INDEX=Index1(2).

      

But this is invalid SPSS code. Does anyone know how I can tweak this?

Thank!

+3


source to share


1 answer


The following code should do the trick:

SORT CASES BY couple (A) Person (A).
IF (couple = LAG(couple)) partner = LAG(actor).

SORT CASES BY couple (A) Person (D).
IF (couple = LAG(couple)) partner = LAG(actor).

      



Explanation: First, you sort your data so that each actor is watched by a partner. You can then use the LAG function to copy the Actor ID (from the top line) to the partner's partner variable (the second line). Since SPSS doesn't have a similar function in SPSS (I don't notice it at all), you cannot directly copy the value from the second line to the first. First, you need to sort the person variable in descending order.

+3


source







All Articles