Aggregate variables

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Aggregate variables

Postby JolienK » Tue Jul 14, 2015 5:47 pm

I wanted to aggregate some variables in SPSS. For the contact with the child, there are multiple variables for every possible child. For example CH0014_1 for child 1, CH014_2 for child 2, etc. All these variables have the same answer categories (once a week, daily, etc.). I wondered if I can aggregate these, so I have just one variable for the contact that once person has, with all his or her children. Is this possible? And how? I've tried different things already, like 'do if' or simply a summation with compute, but this all didn't work out.

Thanks a lot!
Jolien.
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Aggregate variables

Postby RubenGeert » Wed Jul 15, 2015 3:51 am

Hi Jolien,

Note that in SPSS, AGGREGATE usually refers to running functions over cases (vertically). Also, see http://www.spss-tutorials.com/spss-aggregate-command/

In your cases, you'd like some function over variables (horizontally) so AGGREGATE doesn't apply here. What you'd like to do is combine categorical variables.

A nice tutorial on doing just that is http://www.spss-tutorials.com/combine-c ... variables/.
JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Re: Aggregate variables

Postby JolienK » Thu Jul 16, 2015 6:49 am

Thanks! Is this also possible for more than two variables?
JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Re: Aggregate variables

Postby JolienK » Thu Jul 16, 2015 7:15 am

Spreekt u Nederlands? :) Dat zou de uitleg makkelijker maken ;)
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Aggregate variables

Postby GerineL » Thu Jul 16, 2015 8:52 am

er zijn 2 mogelijkheden om gemiddelde uit te rekenen met spss:

Compute -> mean: het gemiddelde over verschillende kolommen.
Bijvoorbeeld, elke lijn bevat een participant, er zijn 10 items en je wilt het gemiddelde per persoon over die 10 items uitrekenen.
wordt vaak gebruikt om gemiddelde over een vragenlijst uit te rekenen oid.

Aggregate -> mean:
Bijvoorbeeld, elke lijn bevat een participant, je wilt voor item 1 het gemiddelde van alle personen weten ("groepsgemiddelde").

Rough translation:

Compute -> mean is used to calculate average within person (within line) over several variables, e.g. compute mean scale score.
Aggregate -> mean is used to calculate average within variables (within colum) over sevaral cases, e.g. compute group average for a certain scale.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Aggregate variables

Postby GerineL » Thu Jul 16, 2015 8:58 am

Regarding your original post, if I understand correctly, you now have the following design:


Child1_question1......CHild1_question2..... Child2_question1......Child2_question2....etc.
1.............................3...............................2..............................3.....................

and you want:

ID.....................question1..............question2
1..........................1...........................3
2..........................2...........................3


In that case, create a case number and use if function to fill out variables:

Code: Select all

compute ID = $CASENUM .
execute.


if (ID = 1) question1 = child1_question1.
if (ID = 1) question2 = child1_question2.
if (ID = 2) question1 = child2_question1.
if (ID = 2) question2 = child2_question2.
execute.
I usually make these syntaxes with excel (easy to quickly make a large syntax by copying / dragging), but it is probably also possible with a loop function.
No doubt RubenGeert can help you with that :-)
JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Re: Aggregate variables

Postby JolienK » Sun Jul 19, 2015 12:36 pm

I found a syntax that works for wave 1 en 2, here it is:
COMPUTE W1_ch014_SOM = 99.
EXECUTE.

MISSING VALUES W1_ch014_SOM (99)

DO If (W1_ch014_1=1 or W1_ch014_2=1 or W1_ch014_3=1 or W1_ch014_4=1).
compute W1_ch014_SOM =1.
Else If (W1_ch014_1=2 or W1_ch014_2=2 or W1_ch014_3=2 or W1_ch014_4=2 ).
compute W1_ch014_SOM =2.
Else If (W1_ch014_1=3 or W1_ch014_2=3 or W1_ch014_3=3 or W1_ch014_4=3 ).
compute W1_ch014_SOM =3.
Else If (W1_ch014_1=4 or W1_ch014_2=4 or W1_ch014_3=4 or W1_ch014_4=4 ).
compute W1_ch014_SOM =4.
Else If (W1_ch014_1=5 or W1_ch014_2=5 or W1_ch014_3=5 or W1_ch014_4=5 ).
compute W1_ch014_SOM =5.
Else If (W1_ch014_1=6 or W1_ch014_2=6 or W1_ch014_3=6 or W1_ch014_4=6 ).
compute W1_ch014_SOM =6.
Else If (W1_ch014_1=7 or W1_ch014_2=7 or W1_ch014_3=7 or W1_ch014_4=7 ).
compute W1_ch014_SOM =7.
END IF.

Here I use 4 variables: W1_ch014_1 W1_ch014_2 W1_ch014_3 and W1_ch014_4. The result is exactly what I needed, I now get the seven answercategories in 1 table, for all the 4 variables.

But in Wave 4 the variable ch014 consists of 20 variables (W4_ch014_1 until W4_ch014_20). I used the same syntax:
COMPUTE W4_ch014_SOM = 99.
EXECUTE.

MISSING VALUES W4_ch014_SOM (99)

DO If (W4_ch014_1=1 or W4_ch014_2=1 or W4_ch014_3=1 or W4_ch014_4=1 or W4_ch014_5=1 or W4_ch014_6=1 or W4_ch014_7=1 or W4_ch014_8=1 or W4_ch014_9=1 or W4_ch014_10=1 or W4_ch014_11=1 or W4_ch014_12=1 or W4_ch014_13=1 or W4_ch014_14=1 or W4_ch014_15=1 or W4_ch014_16=1 or W4_ch014_17=1 or W4_ch014_18=1 or W4_ch014_19=1 or W4_ch014_20=1 ).
compute W4_ch014_SOM =1.
Else If (W4_ch014_1=2 or W4_ch014_2=2 or W4_ch014_3=2 or W4_ch014_4=2 or W4_ch014_5=2 or W4_ch014_6=2 or W4_ch014_7=2 or W4_ch014_8=2 or W4_ch014_9=2 or W4_ch014_10=2 or W4_ch014_11=2 or W4_ch014_12=2 or W4_ch014_13=2 or W4_ch014_14=2 or W4_ch014_15=2 or W4_ch014_16=2 or W4_ch014_17=2 or W4_ch014_18=2 or W4_ch014_19=2 or W4_ch014_20=2 ).
compute W4_ch014_SOM =2.
Else If (W4_ch014_1=3 or W4_ch014_2=3 or W4_ch014_3=3 or W4_ch014_4=3 or W4_ch014_5=3 or W4_ch014_6=3 or W4_ch014_7=3 or W4_ch014_8=3 or W4_ch014_9=3 or W4_ch014_10=3 or W4_ch014_11=3 or W4_ch014_12=3 or W4_ch014_13=3 or W4_ch014_14=3 or W4_ch014_15=3 or W4_ch014_16=3 or W4_ch014_17=3 or W4_ch014_18=3 or W4_ch014_19=3 or W4_ch014_20=3 ).
compute W4_ch014_SOM =3.
Else If (W4_ch014_1=4 or W4_ch014_2=4 or W4_ch014_3=4 or W4_ch014_4=4 or W4_ch014_5=4 or W4_ch014_6=4 or W4_ch014_7=4 or W4_ch014_8=4 or W4_ch014_9=4 or W4_ch014_10=4 or W4_ch014_11=4 or W4_ch014_12=4 or W4_ch014_13=4 or W4_ch014_14=4 or W4_ch014_15=4 or W4_ch014_16=4 or W4_ch014_17=4 or W4_ch014_18=4 or W4_ch014_19=4 or W4_ch014_20=4 ).
compute W4_ch014_SOM =4.
Else If (W4_ch014_1=5 or W4_ch014_2=5 or W4_ch014_3=5 or W4_ch014_4=5 or W4_ch014_5=5 or W4_ch014_6=5 or W4_ch014_7=5 or W4_ch014_8=5 or W4_ch014_9=5 or W4_ch014_10=5 or W4_ch014_11=5 or W4_ch014_12=5 or W4_ch014_13=5 or W4_ch014_14=5 or W4_ch014_15=5 or W4_ch014_16=5 or W4_ch014_17=5 or W4_ch014_18=5 or W4_ch014_19=5 or W4_ch014_20=5 ).
compute W4_ch014_SOM =5.
Else If (W4_ch014_1=6 or W4_ch014_2=6 or W4_ch014_3=6 or W4_ch014_4=6 or W4_ch014_5=6 or W4_ch014_6=6 or W4_ch014_7=6 or W4_ch014_8=6 or W4_ch014_9=6 or W4_ch014_10=6 or W4_ch014_11=6 or W4_ch014_12=6 or W4_ch014_13=6 or W4_ch014_14=6 or W4_ch014_15=6 or W4_ch014_16=6 or W4_ch014_17=6 or W4_ch014_18=6 or W4_ch014_19=6 or W4_ch014_20=6 ).
compute W4_ch014_SOM =6.
Else If (W4_ch014_1=7 or W4_ch014_2=7 or W4_ch014_3=7 or W4_ch014_4=7 or W4_ch014_5=7 or W4_ch014_6=7 or W4_ch014_7=7 or W4_ch014_8=7 or W4_ch014_9=7 or W4_ch014_10=7 or W4_ch014_11=7 or W4_ch014_12=7 or W4_ch014_13=7 or W4_ch014_14=7 or W4_ch014_15=7 or W4_ch014_16=7 or W4_ch014_17=7 or W4_ch014_18=7 or W4_ch014_19=7 or W4_ch014_20=7 ).
compute W4_ch014_SOM =7.
END IF.

But now when I look at the frequencies, I only get the value 1 and the missing 99 in the tabel.
Is this syntax not possible with this many variables? Or am I doing something wrong?

Thanks ;)
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Aggregate variables

Postby GerineL » Tue Jul 21, 2015 11:16 am

I don't know what your variable names mean so I can't see if it is correct. but in theory you can do this with this many varaibles, and many many more if needed.
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Aggregate variables

Postby RubenGeert » Tue Jul 21, 2015 12:07 pm

@Jolien: writing /pasting this syntax must have been a nightmare and it's so unreadable that it really hurts my eyes. I don't want to mind your business but I think things may get much easier, faster and more manageable if you read up on SPSS' ANY function: http://www.spss-tutorials.com/spss-any-function/

Second, using IF instead of DO IF will probably speed up things as well: http://www.spss-tutorials.com/spss-if-command/

And if you want to get things done really fast, mastering SPSS' LOOP command will probably turn out very helpful as well.

HTH,

Ruben

Who is online

Users browsing this forum: No registered users and 1 guest

cron