Skip to main content
MedCalc
Mail a PDF copy of this page to:
(Your email address will not be added to a mailing list)
working
Show menu Show menu

AGGREGATE function

Description

AGGREGATE(statistic[,allowmissing],variable,group[,filter]) calculates the specified statistic of a variable in the group a case belongs to.

Parameters

  • statistic: must be COUNT, MEAN, MEDIAN, MIN, MAX, PERCENTILE, SEM, STDEV, VAR, SUM, SUMSQ, GEOMEAN or HARMEAN.

    When PERCENTILE is specified, the function takes one more parameter "centile", which is a value between 0 and 100. See the example below.

  • allowmissing: an optional parameter, if TRUE then the function will also return a value for a case in which data are missing for the continuous variable.
  • variable: a continuous variable for which to calculate the statistic of interest
  • group: a categorical grouping variable (e.g. gender)
  • filter: an optional filter on the continuous variable.

Examples

AGGREGATE function

Column AG1AGGREGATE(MEAN,age,gender) returns the MEAN age in the group defined by the variable gender.
Column AG2AGGREGATE(MEAN,TRUE,age,gender) returns the MEAN age in the group defined by the variable gender, even for a case in which the age value is missing.
Column AG3AGGREGATE(MEAN,age,gender,success=1) returns the MEAN age of cases where success=1, in the group defined by the variable gender.
Column AG4AGGREGATE(PERCENTILE,TRUE,75,age,gender) returns the 75th percentile of age in the group defined by the variable gender, even for a case in which the age value is missing.
Column AG5AGGREGATE(PERCENTILE,75,age,gender) returns the 75th percentile of age in the group defined by the variable gender, but not for cases in which the age value is missing.

Note: we have used Auto-values in this example.

Related functions