*Title (this is from SPSS AnswerNet):
Creating n-tiles based on percent ranges, and not count of cases
Description:
Q
I want to split my data into n-tiles (in this case quintiles)
where the group ranges are equal rather than the number of cases
within each group; the aggregation is based on equal ranges and not
equal counts. How can I do this?
A.
*The following sample job will do what you want. The crux of the
job rests with computing variable to compute a cumulative total using
the LEAVE command, and then a DO IF/END IF procedure to specify the
grouping.
*****.
INPUT PROGRAM.
LOOP #I = 1 TO 100.
COMPUTE salesvol = TRUNC(UNIFORM(100000)) + 1 .
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
COMPUTE cust_id = $casenum.
EXE.
COMPUTE dummy = 1.
EXE.
AGGREGATE /OUTFILE='AGGR.SAV'
/BREAK=dummy
/totl_vol = SUM(salesvol).
MATCH FILES /FILE=*
/TABLE='Aggr.sav'
/BY dummy.
EXE.
SORT CASES BY
salesvol (A) .
COMPUTE cm_sale = cm_sale + salesvol.
LEAVE cm_sale.
FORMATS salesvol totl_vol cm_sale (DOLLAR8).
EXE.
DO IF (cm_sale < (.2 * totl_vol)).
COMPUTE quintile = 5.
ELSE IF (cm_sale >= (.2 * totl_vol) AND cm_sale < (.4 * totl_vol)).
COMPUTE quintile = 4.
ELSE IF (cm_sale >= (.4 * totl_vol) AND cm_sale < (.6 * totl_vol)).
COMPUTE quintile = 3.
ELSE IF (cm_sale >= (.6 * totl_vol) AND cm_sale < (.8 * totl_vol)).
COMPUTE quintile = 2.
ELSE IF (cm_sale >= (.8 * totl_vol)).
COMPUTE quintile = 1.
END IF.
EXE.