Hi All,
My data looks like this: UserID Var1 1 string 1 string 1 string 1 string 1 string
I'd like to select all "string" for each identical case and move them into columns, variables of their own to be associated with that case. Any ideas?
|
Administrator
|
P.,
Brevity ~= virtue! Ex of I/O?. D.
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 Peter Spangler
One command: casestovars. If that doesn’t give you what you want, repost with an example with values for var1 that illustrate the problem and what the structure will look like after the restructure. Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peter Spangler Hi All, My data looks like this: UserID Var1 1 string 1 string 1 string 1 string 1 string I'd like to select all "string" for each identical case and move them into columns, variables of their own to be associated with that case. Any ideas? |
The goal is to restructure data such that the unique IDs can be analyzed based on belonging to specific groups. Respondents have selected groups to "Like" online. I see each group being a variable (column) coded 0/1, yes/no. Respondents could then be analyzed for their odds of belonging to group A given group B, Clustered, etc.
Data example: I'd like to make Music, Restaurants and Games variables and have ID 1 appear once. In this case ID 1 would be coded 1 for variables Music, Restaurants, Games.
1 Music 1 Restaurants 1 Games On Sat, Mar 16, 2013 at 7:25 AM, Maguin, Eugene <[hidden email]> wrote:
|
Administrator
|
CASESTOVARS is the heavy lifter here but a bit of mojo in the middle crosses the bridge.
* NOTE fake element @ at top with stand-in 0 id. I believe this is as slick as it gets (without hardcoding unknown variable names into the recode). -- DATA LIST LIST/id (F2) S (A20). BEGIN DATA 0 @ /* note fake case here */ 1 Music 1 Restaurants 1 Games 2 Music 2 Concerts 2 Animals END DATA. AUTORECODE S /INTO NS. CASESTOVARS /ID=ID / INDEX=S. COMPUTE @@=1. RECODE @ TO @@ (SYSMIS=0)(ELSE=1). SELECT IF ID NE 0. EXECUTE /* need this EXECUTE or else DELETE VARIABLES gives error */. DELETE VARIABLES @ @@. LIST. id Animals Concerts Games Music Restaurants 1 0 0 1 1 1 2 1 1 0 1 0 Number of cases read: 2 Number of cases listed: 2
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?" |
Wow! Thank you David. This is what I was looking for. Essentially I can copy my IDs and Strings as is below and the scratch variable is to set others to 0?
On Mon, Mar 18, 2013 at 9:34 AM, David Marso <[hidden email]> wrote: CASESTOVARS is the heavy lifter here but a bit of mojo in the middle crosses |
Administrator
|
Peter,
Actually, technically speaking it shouldn't be referred to as a scratch variable as there is an actual entity called a scratch variable in SPSS (very special creatures). Maybe we can refer to it as a tosser? I was seeking a way to be able to mass recode without actually knowing the values of the strings. By creating a fake id (anything which does not exist in the data) and a string value which sorts before any of the actual strings the AUTORECODE forces the @ to precede any of the values. By later creating another variable @@ (guaranteed to be at the end) I can use @ TO @@ in the recode and thereby ensure the new variable names are implicitly mapped (.->0, other->1). It is by exploiting insights into the collating order of strings and the truly awesome INDEX feature of C2V (values ->variable names) that this sort of thing happens. Back in the day prior to C2V one would have to create a VECTOR of strings, LOOP and XSAVE and it would be a truly fugly hack to get the original values into the variable names (doable but even more twisted than a Cirque Du Soleil contortionist act). I am interested if anyone can come up with a native solution involving fewer steps (I mean no python).
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?" |
When I ran the syntax with your example everything worked perfectly. Same output. When I ran the syntax on my actual data the DATA LIST syntax was no problem to produce columns id and S. When running the second part I received error # 4825:
COMPUTE @@ =1 RECODE @ TO @@ (SYSMIS=09) (ELSE=1) ERROR #4825 IN COLUMN 13. TEXT: @@
THE FORM VARX TO VARY TO REFER TO A RANGE OF VARIABLES HAS BEEN USED INCORRECTLY
EXECUTION OF THIS COMMAND STOPS SELECT IF ID NE 0. EXECUTE/*NEED THIS EXECUTE OR ELSE DELETE VARIABLES GIVES ERROR */ DELETE VARIABLES @ @@. On Mon, Mar 18, 2013 at 10:19 AM, David Marso <[hidden email]> wrote: Peter, |
Administrator
|
Let's see: Your variable is not called S and you forgot to add the dummy case with @.
Must study the code, get the epiphany and then apply to your data. Copy? Over and Out. --
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?" |
The dummy case (0 @) appears at the top after BEGIN DATA. It also appears correctly in the created data file.
The epiphany that cases become variables and those ids without a given string become 0 and with become 1 is great. But these warnings indicate problems I'm unsure of.
Warnings: The INDEX values for case 3 have occurred before in the cases with the same ID values Execution of this command stops. Text: @ Command: DELETE VARIABLES
An undefined variable name, or a scratch or system variable was specified in a variable list which accepts only standard variables. Check spelling and verify the existence of this variable. Execution of this command stops.
On Mon, Mar 18, 2013 at 11:28 AM, David Marso <[hidden email]> wrote: Let's see: Your variable is *not called S* and you forgot to add the *dummy |
The repeated string values seem to prevent the second part of the syntax from functioning! When I use sample data with discrete string values per id (no duplicates) the syntax resumes working.
Can I SELECTCASES to delete cases where there are duplicate values. For example, delete cases 2 and 3.
case id string 1 1 music 2 1 music 3 1 music On Mon, Mar 18, 2013 at 12:08 PM, Peter Spangler <[hidden email]> wrote: The dummy case (0 @) appears at the top after BEGIN DATA. It also appears correctly in the created data file. |
Administrator
|
In reply to this post by Peter Spangler
Well, It obviously works on my dummy data. Right.
So read it, master it, conform it to your data and enjoy the gift. You need to get familiar with CasesToVars. 1. Looks like perhaps the values for a case are not unique. * Look at AGGREGATE for that. Obviously the CasesToVars underwent an epic fail because the data do not conform to the requirements of in their current state. Aside from that? You know myself and others on this list provide training and consulting services. You might consider some of that from either myself or another. Could possibly save you a lot of head banging and frustration! ---
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?" |
I truly do appreciate the gift and will study the syntax and references.
I think I'm on the path to solving this: Creates ID, (unique) string value, groupSize. AGGREGATE /OUTFILE='C:\Users\pspangler\Desktop\Marketplace/FB.AGG.sav'
/BREAK=ID S /groupSize=N. Removing groupSize variable leaves me with the data prepared for the remainder of the restructure syntax. Thanks again David!
On Mon, Mar 18, 2013 at 12:36 PM, David Marso <[hidden email]> wrote: Well, It obviously works on my dummy data. Right. |
I’m still a bit unclear as to how you plan to use your profiles but it seems to me that you are throwing away a lot of information by turning a like category into a binary value. Depending upon how many persons I have, I would think about leaving the data in long format and run a crosstab of string by id and then create a dataset from the pivot table of counts. From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peter Spangler I truly do appreciate the gift and will study the syntax and references. I think I'm on the path to solving this: Creates ID, (unique) string value, groupSize. AGGREGATE /OUTFILE='C:\Users\pspangler\Desktop\Marketplace/FB.AGG.sav' /BREAK=ID S /groupSize=N. Removing groupSize variable leaves me with the data prepared for the remainder of the restructure syntax. Thanks again David! On Mon, Mar 18, 2013 at 12:36 PM, David Marso <[hidden email]> wrote:
|
My interest began with a desire to restructure the data around categories of interest. The counts themselves do add to each users story.
I am new to profile creation with this sort of data and welcome any suggestions.
On Mon, Mar 18, 2013 at 4:48 PM, ViAnn Beadle <[hidden email]> wrote:
|
Because I have predetermined categories of interests I began with the binary categorical level to evaluate the odds of membership among them.
For classification I would typically use a cluster analysis to build a decision tree. Is this the sort of classification -- association -- you would have in mind?
On Mon, Mar 18, 2013 at 5:44 PM, ViAnn Beadle <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |