SPSS AGGREGATE Command

Aggregate is an SPSS command for creating variables holding statistics over cases. This tutorials briefly demonstrates the most common scenarios and points out some best practices.

SPSS Aggregate

SPSS Aggregate Command

The SPSS AGGREGATE command typically works like so:

  • One or more BREAK variables can be specified.*
  • All cases with the same value(s) on the break variable(s) are referred to as a break group
  • Each break group will become a single case in the aggregated data (unless MODE = ADDVARIABLESis used).
  • This new case has summary statistics over the original cases as new variables. Available statistics include the frequencymeanmaximum and many others. Consult the command syntax reference for a complete overview.
  • The result of AGGREGATE may be the active dataset, a new dataset or a new data file. (This last option is not available for MODE = ADDVARIABLES.) A new Dataset must first be declared before it can be specified in AGGREGATE.
  • For a very basic demonstration, run the syntax below.

SPSS Aggregate Syntax Example

*1. Create test data.

data list free/id.
begin data
3 5 5 8 8 8 9 9 9 9
end data.*2. Create Dataset with id counts (called ‘freq’ for ‘frequency’).

aggregate outfile *
/break id
/freq = nu.

MODE = ADDVARIABLES

SPSS Aggregate Mode AddvariablesSPSS Aggregate – Mode = Addvariables

Except for SPSS versions 12 and below, summary statistics of break groups can be appended to a Dataset without actually aggregating it. The syntax below demonstrates this.

SPSS Aggregate Syntax Example

*Append id counts to Dataset.

aggregate outfile * mode = addvariables
/break id
/freq = nu.

Statistics over Multiple Variables

Summary statistics can be rendered over multiple variables in one go. The TO and ALL keywords can conveniently shorten the list of variables as shown in the syntax below.

*1. Create test data.

data list free/v1 to v5.
begin data
1 2 3 4 5 6 7 8 9 10
end data.*2. Aggregate multiple variables at once.

aggregate outfile *
/mean_1 to mean_5 = mean(v1 to v5).

Multiple Statistics

Different summary statistics (over the same or different variables) can be specified in a single command. This is demonstrated below (uses test data from previous example).

* Different summary statistics in a single command.

aggregate outfile *
/mean_1 to mean_5 = mean(v1 to v5)
/sd_1 to sd_5 = sd(v1 to v5).

Final Note

Lots of different things can be done with the AGGREGATE command. This tutorial aimed at illustrating the most common scenarios found in practice. It is by no means intended as an exhaustive overview of all options.