Re: verifying and documenting RECODE on Multiple Response set

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

Re: verifying and documenting RECODE on Multiple Response set

Jon Peck
Try this, starting from your mr x mr  table.

dataset declare table.
oms select tables /if subtypes="customtable"
/destination outfile=table format=sav.
CTABLES
  /VLABELS VARIABLES=$z@SetOfCrops $SetOfCrops DISPLAY=DEFAULT
  /TABLE $z@SetOfCrops [C][COUNT F40.0] BY $SetOfCrops [C]
  /SLABELS VISIBLE=NO
  /CATEGORIES VARIABLES=$z@SetOfCrops $SetOfCrops ORDER=A KEY=VALUE EMPTY=INCLUDE MISSING=EXCLUDE.
omsend.
dataset activate table.
begin program.
import spssdata, spssaux


vardict = spssaux.VariableDict()
ind = vardict.indexes()
names = vardict.variables
ddict = dict([(k, v) for k,v in zip(ind, names)])

with spssdata.Spssdata(names=False) as curs:
    for case in curs:
        nvars = len(case)    
        caseres = []
        for i in range(5, nvars):
            if case[i] > 0:
                caseres.append("%s: %d" % (ddict[i], case[i]))
        print "%s::" % case[4], " ".join(caseres)
end program.

On Thu, Aug 20, 2020 at 12:46 PM Art Kendall <[hidden email]> wrote:
To avoid reinventing the wheel has somebody already worked this out?

Ordinarily, for a recode on a single variable I would RECODE MyVar ... INTO
MyNewVar and then
CROSSTAB TABLES = MyVar BY MyNewVar.  In order to *verify that I drafted the
recode the way I intended*.
The current situation is that I have a Multiple Response  set of 10
variables and 80-some values that could occur in any of the positions in the
set.  The order is irrelevant.

I would like to have a dataset that had the original set of values as rows
with a recoded set of values as columns.  If I cross the two MR sets most of
the cells are distractions. The goal is to see something like
2 apples    <== 1 apple 2 apples 10 manzanas 16 pommes
18 potatoes <== 17 potato 18 potatoes 19 potatos
      or
apple apples manzanas pommes ==> apples
potato potatoes potatos ==> potatoes

or a table with the old categories as rows and the new catgories as columns.
The difference from a MRSet by MRSet crosstab is that

Two things I have considered but have not yet figured out how to implement
are
(1) OMS to get the list of categories from AUTORECODE and the details of the
RECODE.
(2) some VartoCases approach and then a crosstab

This is where I am so far.
NEW FILE.
*    create example set of data.
DATA LIST LIST/ MyCrops (a100).
BEGIN DATA
'beans|corn|apples|pears'
'apples|beans'
'pear|corn|potato'
'potatoes|apple|bean'
'blé|poire|haricots'
'potatos'
'pommes|poires'
'manzanas|frijoles|maíz'
'maíz|peras'
END DATA.
* split string into variable names will want in final file.
spssinc trans result = T.Crop01 to T.Crop04 type=25
    /formula "string.split(MyCrops, '|')".
*  convert into variables with names will want in final file.
AUTORECODE VARIABLES = T.Crop01 to T.Crop04 /INTO Crop01 to Crop04
    /BLANK = MISSING /GROUP /PRINT.
*    convert into variables will NOT want in final file but need .
*    to document recodes.
AUTORECODE VARIABLES = T.Crop01 to T.Crop04 /INTO z@Crop01 to z@Crop04
    /BLANK = MISSING /GROUP.
MRSETS
    /MCGROUP NAME=$SetOfCrops LABEL='all crops in final' VARIABLES=Crop01 TO
Crop04
    /DISPLAY NAME=[$SetOfCrops].
MRSETS
    /MCGROUP NAME=$z@SetOfCrops LABEL='crops before combining'
VARIABLES=z@Crop01 TO z@Crop04
    /DISPLAY NAME=[$z@SetOfCrops].
RECODE Crop01 TO Crop04
(20=-1)(1,2,10,16=2)(3,4,7,8=4)(6,9=6)(11,12,13,15=12)(17,18,19=18)(ELSE=-2).
ADD VALUE LABELS Crop01 TO Crop04
-1 'missing'
-2 'not considered in recode'.

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=$z@SetOfCrops DISPLAY=LABEL
  /TABLE $z@SetOfCrops [COUNT F40.0]
  /CATEGORIES VARIABLES=$z@SetOfCrops ORDER=A KEY=VALUE EMPTY=INCLUDE
MISSING=EXCLUDE.


* Custom Tables.
CTABLES
  /VLABELS VARIABLES=$SetOfCrops DISPLAY=LABEL
  /TABLE $SetOfCrops [C][COUNT F40.0]
  /CATEGORIES VARIABLES=$SetOfCrops ORDER=A KEY=VALUE EMPTY=EXCLUDE
MISSING=EXCLUDE.







-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD