Create n tiles based on percent ranges rather than on count
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | *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. |
Related pages
...