Search code examples
spss

SPSS: aggregate and count different values


In SPSS i have a variabele with a lot of different values (8 figure number; 00000000). Every row is a person. I want to aggregate this data on postal area and count the number of different values in a postal area. Is there a way?

Result within a postal area should be 1 to N : 1 = every person has the same value, N = every person has a different value


Solution

  • Aggregate in two steps. Assuming your dataset name is data1, with variables var1 (the variable of interest) and postalcode, I would do this:

    Create a dataset step1, with one row for each combination of values of postalcode and var1. Also possible by using the command casestovars.

    dataset declare step1.
    dataset activate data1.
    aggregate outf=step1 /break=postalcode var1 /n=n(var1).
    

    Create a dataset result with one row for each postalcode, and a variable n for the number of rows from the previous dataset step1.

    dataset declare result.
    dataset activate step1.
    aggregate outf=result /break=postalcode /n=n(var1).
    

    So, in conclusion: first break by both of the variables, then break only by the variable of postal code. This should do the trick!