Recap: CTABLES sort--force "other" to top or bottom when sorting on column percentages

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Recap: CTABLES sort--force "other" to top or bottom when sorting on column percentages

King Douglas
Folks,

Bruce Weaver tells me that my original post wasn't handled correctly, so here's a recap and another request for help.  The original post with data and examples follows the recap.

The original question how to force the value for "other" in a categorical variable to the top or bottom of a CTABLE when sorting by percentages.  I'm interested in a solution for both a single variable and for a multiple response variable.

For the single variable, Vlad Simion suggested creating a new counting variable, initialized at 1 and setting the value of "other" to -1, and employing the new variable in the sort parameters.  That worked very well.

Jon Peck suggested, "...you can use the function genCategoryList in the spssaux2.py module from the SPSS Community site to build a set of macros that can be used in the CTABLES commands.  It takes an "exception" list for items such as Other that should be moved to the head or tail of the list. So, the net is that you would run this function or something like it to generate the requisite macros and then use those in the CATEGORIES category list fields.  While this function sorts by counts, it would be simple to create one that sorted by values or value labels."

If you have an idea how to solve this for MR variables without using Python (I'm assisting someone with an older version of SPSS), Please let me know.

ORIGINAL POST:

A search of the archives shows that this question has been addressed
previously without a satisfactory answer. I have many single and MR
variables with an "Other" category (i.e., value).  I want to create and sort tables in
ascending order of column percentages, but with "Other" at the top (or bottom) of the
table, irrespective of actual percentage of the "other" value.

I want to do this programatically, with as little post hoc work as
possible.  The tables will be exported to Excel and I can create a macro to
handle the sorting task, but I'd rather make this as clean as possible and
export the tables without further manipulation.  I wouldn't mind adding
variables to the dataset or to the table if that will get me where I want to
go.

So say we have two questions:

1. What's your favorite flavor of ice cream?
2. What ice cream flavors have you enjoyed in the last month?

In both cases, I want to sort the responses, but force "Other" to the bottom
of the table.  Any ideas?

Thanks,
King Douglas

* TESTED CODE FOLLOWS.

data list free
 /flavor1 to flavor4.
BEGIN DATA
1,2,3,4
2,3,4,1
3,4,1,2
4,1,2,3
1,3,2, 4
2,1,3,
4,1,2,
1,4,2,
END DATA.

VALUE LABELS FLAVOR1 FLAVOR2 FLAVOR3 FLAVOR4
1 'Vanilla'
2 'Chocolate'
3 'Strawberry'
4 'Other'.

* SINGLE VARIABLE.

CTABLES
 /VLABELS VARIABLES=flavor1 DISPLAY=DEFAULT
 /TABLE flavor1 [COLPCT.COUNT PCT40.1, COUNT F40.0]
 /CATEGORIES VARIABLES=flavor1 ORDER=A KEY=COLPCT.COUNT (flavor1)
EMPTY=EXCLUDE TOTAL=YES
   POSITION=AFTER.

* MR VARIABLE.


MRSETS
 /MCGROUP NAME=$Flavor VARIABLES=flavor1 flavor2 flavor3 flavor4
 /DISPLAY NAME=[$Flavor].

CTABLES
 /VLABELS VARIABLES=$Flavor DISPLAY=DEFAULT
 /TABLE $Flavor [C][COLPCT.RESPONSES PCT40.1, COUNT F40.0]
 /CATEGORIES VARIABLES=$Flavor ORDER=A KEY=COLPCT.RESPONSES ($Flavor)
EMPTY=INCLUDE TOTAL=YES
   POSITION=AFTER.