Hi,
We have data for 20 attributes (Attr1_1, … Attr1_3 TO Attr20_1, … Attr20_3) and each attribute is having 3 mentions data (number of mentions and attributes can vary). For each respondent, I want to know the number of unique codes and should create same number of new variables with codes. For your reference please follow the below example Here first respondent answered four unique codes (53,55,126,130) Second respondent answered three unique codes (122,186,187) . So need to create 4 new variables NEWVAR1 to NEWVAR4 (maximum count of unique codes) to store the complete data information. The expected solution can be in either SPSS or Python is fine. Thanks in advance, Anupama |
Administrator
|
/* Untested */.
COMPUTE CaseID=$CASENUM. VARSTOCASES ID=CaseID /MAKE var FROM Attr1_1 TO Attr20_3 . AGGREGATE OUTFILE * / BREAK CaseID Var /N=N. DELETE VARIABLES N. CASESTOVARS /ID=CaseID.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Anupama
Sets in python work well for this task.
************************************. DATA LIST FREE / A1 TO A5 (5F1.0). BEGIN DATA 1 2 2 3 4 1 9 6 7 6 0 0 0 0 0 2 2 2 2 9 END DATA. DATASET NAME Sim. EXECUTE. BEGIN PROGRAM Python. def MySet(x): return sorted(list(set(x))) END PROGRAM. SPSSINC TRANS RESULT = ASet1 TO ASet5 TYPE=0 /VARIABLES A1 TO A5 /FORMULA "MySet([<>])". ************************************. |
In reply to this post by Anupama
You haven't said what you are going to do with these data, but have you considered defining a multiple response set with these variables instead of restructuring? As a multiple dichotomy set, you could use it in Custom Tables and the Chart Builder. On Fri, Feb 24, 2017 at 12:34 AM, Anupama <[hidden email]> wrote: Hi, |
Free forum by Nabble | Edit this page |