Comparing or combining values in a column

Viewed 43

Scenario and question:
Basically I have results for a matched pair survey of couples in SPSS. It's set up where the person A's answers to questions 1-10 are the first 10 variables and then person B's answers to questions 1-10 are the next 10 variables. But I need to run tests and produce crosstabs for individuals, so if I have 20 couples the crosstabs outputs should be out of 40. I was able to simply select all the data for the "person B"s in couples and just copy and paste it over, however I lost couple-specific data and I still need to be able to create new variables based on the matched pair information. My way around this was creating a new variable while still in matched pair form called CoupleNum, so even when they were in individual form I could say if their couple number equaled each other calculate this or that. But I don't actually know how to do this. In the same dataset, how do I compare rows for the same variable?

Example for what I'm talking about:

Here's fake data

A_CoupleNum A1_HappyScale B_CoupleNum B1_HappyScale
1 6 1 4
2 2 2 3
3 9 3 7

I'd move it to individual form like

CoupleNum HappyScale
1 6
2 2
3 9
1 4
2 3
3 7

And then I'd want to be able to make a new variable called CoupleHappiness that was the HappyScale for each person in the couple added together.

CoupleNum HappyScale CoupleHappiness
1 6 10
2 2 5
3 9 16
1 4 10
2 3 5
3 7 16

So essentially I'd want to code something like

if CoupleNum = CoupleNum CoupleHappiness = HappyScale + HappyScale

I know this is definitely not correct but hopefully it gets my point across and what I'd like to do.

Potential solutions I've found that don't work/I don't know how to make them work for my needs:
Since I'm new to SPSS, I've found several things that might work but I don't know SPSS syntax well enough to suit them for my needs. I've noticed people mention things like LAG functions or CREATE + LEAD if they were in adjacent rows, but they could be all over the place. Someone also mentioned using case numbers but I don't exactly understand that.

Sorry this was a really long question but I would appreciate any help!!

1 Answers

What you are looking for is the aggregate function. In this case you can use it this way:

NOTE - this code was edited and corrected:

aggregate out=* mode=addvariables /break CoupleNum/CoupleHappiness=sum(HappyScale).

The function groups all the rows by values of CoupleNum, then for each group the function will calculate the sum of HappyScale and put it in a new variable called CoupleHappiness.

Related