Thursday, 27 October 2011

What can you do with COMPUTE in SPSS

Note what you can do with Mean.# and Sum.# to tackle missing values. And also take note of LAG which takes up the value of the preceding case.

COMPUTE y=ABS(x). absolute value of x. ABS(!7) =7.
COMPUTE y=SQRT(x). square root
COMPUTE y=LN(x). natural logarithm
COMPUTE y=LG10(x). base 10 logarithm
COMPUTE y=EXP(x). exponential: ex
COMPUTE y=TRUNC(x). integer part. TRUNC(5.7)=5.
COMPUTE y=RND(x). round to nearest integer. RND(5.7)=6
COMPUTE y=MOD(x,11). remainder after division by 11
COMPUTE y=SUM(x1,x2,x3). sum of 3 variables if at least one is non-missing
COMPUTE y=SUM.5(x1 TO x10). sum of 10 variables if at least 5 are non-missing.
COMPUTE y=MEAN.2(x1,x2,x3). mean of 3 variables if at least 2 are non-missing
COMPUTE y=LAG(x). x from previous case
COMPUTE y=$SYSMIS. sets Y to sysmis.

Source: SPSS for Windows 8, 9 and 10 by Svend Juul

Dropping missing values in SPSS

(This needs some more thought and cleaning up)

The SELECT command with the SYSMIS() function can drop all missing cases from the current SPSS data set. Consider the following:

SELECT IF NOT (SYSMIS (amount)). SAVE OUTFILE= 'newfile.sav'.

This example drops all cases whose value of the variable amount is missing, and then saves this data to an SPSS system file called newfile.sav.

If the dataset has more than one coding for missing values, as is often the case for survey data, select all of the different codings for missing values with the AND operator:

SELECT IF NOT (SYSMIS(amount1)) AND NOT (SYSMIS(amount2)). SAVE OUTFILE= 'newfile.sav'.

look at this post (multi variate anal)