Search code examples
spss

SPSS Populate Scratch Variable with Standard Deviation


I am just learning SPSS, I have a background in PL/SQL and T-SQL

I have a dataset and need to make three groups based on deviation from the mean for a specific variable

Greater than 1 Standard Deviation Above the Mean

Greater than 1 Standard Deviation Below the Mean

All Others

I wanted to use a scratch variable but have no idea how to find the standard deviation of an existing variable and populate it into a scratch variable to use for my grouping conditions.

Any help appreciated


Solution

  • The aggregate command can calculate the SD of a variable and add it to the dataset, like this:

    aggregate/outfile=* mode=addvariables/break= 
            /SDyourvar=sd(yourvar) /MEANyourvar=mean(yourvar).
    

    Now you can use the variables to create groups like this for example:

    do if yourvar < (MEANyourvar - SDyourvar).
       compute group=-1.
    else if yourvar > (MEANyourvar + SDyourvar).
       compute group=1.
    else.
       compute group=0.
    end if.
    

    Or for a shorter version:

    compute group=(yourvar > (MEANyourvar+SDyourvar)) - (yourvar < (MEANyourvar-SDyourvar)).