SPSS list:
I need help in creating syntax that pulls data from one case and puts it in a different variable in a different case. For example (this is not my real data, but seems like an easy way to imagine the problem): You have a list of students (var1, each student is a case) and their test scores (var2), and the names of each student's best friend (var3). You want to have the test score for the friend appear as new var4. How? For student Jane, it requires the program to search the contents of var3 (say, Jane's friend is Jill) and find a match in var1 (find case for Jill), then take the contents of var2 for Jill and put them in var4 of Jane. Any solutions? Thanks Lise |
Gene recommended I give more information on my question, so maybe this
will clarify it. You have a list of students (var1, each student is a case) and their test scores (var2), and the names of each student's best friend (var3). VAR1 VAR2 VAR3 Tim 10 Dan Tom 19 Jane Dan 13 Ann Ann 14 Jane You want to have the test score for the friend appear as new var4: VAR1 VAR2 VAR3 VAR4 Tim 10 Dan 13 Tom 19 Jane 12 Dan 13 Ann 14 Ann 14 Jane 12 Jane 12 Tom 19 How to you write syntax for VAR4, which requires SPSS to match the contents of VAR3 in VAR1, take the VAR2 contents from that case, and put them in VAR4 of the original case? Maybe this is an easy one, but I've never had to do it before, and don't know how to ask it in the Knowledge Base. Thanks, Lise -----Original Message----- From: Gene Maguin [mailto:[hidden email]] Sent: Thursday, August 24, 2006 3:30 PM To: Lise Valentine Subject: RE: Syntax to search cases? Lise, I understand that you are asking this question because you don't know how to do what you want but you have to provide enough information that potential responders have a fighting chance of being helpful. You haven't. You said: I need help in creating syntax that pulls data from one case and puts it in a different variable in a different case. If you were going to tell someone else how to do this by hand--just suppose, for a moment. What would you tell them to do? Step by step, what would they do? How would they know if they had done it right? Please reformulate your question and repost to the list so that all can see. Thanks, Gene Maguin |
In reply to this post by Lise Valentine
Hi,
as long as var1 names are unique, this shud do the trick: (untested, though) if (var3=var1) var4=var2. HTH, Vivek -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Lise Valentine Sent: Thursday, August 24, 2006 16:43 To: [hidden email] Subject: Re: Syntax to search cases? Gene recommended I give more information on my question, so maybe this will clarify it. You have a list of students (var1, each student is a case) and their test scores (var2), and the names of each student's best friend (var3). VAR1 VAR2 VAR3 Tim 10 Dan Tom 19 Jane Dan 13 Ann Ann 14 Jane You want to have the test score for the friend appear as new var4: VAR1 VAR2 VAR3 VAR4 Tim 10 Dan 13 Tom 19 Jane 12 Dan 13 Ann 14 Ann 14 Jane 12 Jane 12 Tom 19 How to you write syntax for VAR4, which requires SPSS to match the contents of VAR3 in VAR1, take the VAR2 contents from that case, and put them in VAR4 of the original case? Maybe this is an easy one, but I've never had to do it before, and don't know how to ask it in the Knowledge Base. Thanks, Lise -----Original Message----- From: Gene Maguin [mailto:[hidden email]] Sent: Thursday, August 24, 2006 3:30 PM To: Lise Valentine Subject: RE: Syntax to search cases? Lise, I understand that you are asking this question because you don't know how to do what you want but you have to provide enough information that potential responders have a fighting chance of being helpful. You haven't. You said: I need help in creating syntax that pulls data from one case and puts it in a different variable in a different case. If you were going to tell someone else how to do this by hand--just suppose, for a moment. What would you tell them to do? Step by step, what would they do? How would they know if they had done it right? Please reformulate your question and repost to the list so that all can see. Thanks, Gene Maguin |
In reply to this post by Lise Valentine
Lise,
That explanation helped a great deal. In words, what you do is this. The original file is open. Sort it by friends name. Save a new file containing the friends name and their scores. Match the new file to the original file by friends name. There one very important problem that might likely come up: duplicate friends names. Check this first. If you have that problem then you will have to assign unique id numbers to the friends before progressing. Another problem is that the same person is named as friend by multiple respondents. That's a different problem and not as hard to fix. In syntax and assuming nonduplicated friend names. Sort cases by var3. Save outfile='new-file-name'/keep=var3 var2. Match files file='original-file-name'/file='new-file-name'/by var3. If you have the same friend being named by mutliple respondents, then substitute Match files file='original-file-name'/table='new-file-name'/by var3. For the straight match files command. Gene Maguin |
In reply to this post by Lise Valentine
Yes, a simple match files! That should've been obvious. Thank you.
Lise -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin Sent: Thursday, August 24, 2006 4:16 PM To: [hidden email] Subject: Re: Syntax to search cases? Lise, That explanation helped a great deal. In words, what you do is this. The original file is open. Sort it by friends name. Save a new file containing the friends name and their scores. Match the new file to the original file by friends name. There one very important problem that might likely come up: duplicate friends names. Check this first. If you have that problem then you will have to assign unique id numbers to the friends before progressing. Another problem is that the same person is named as friend by multiple respondents. That's a different problem and not as hard to fix. In syntax and assuming nonduplicated friend names. Sort cases by var3. Save outfile='new-file-name'/keep=var3 var2. Match files file='original-file-name'/file='new-file-name'/by var3. If you have the same friend being named by mutliple respondents, then substitute Match files file='original-file-name'/table='new-file-name'/by var3. For the straight match files command. Gene Maguin |
In reply to this post by Lise Valentine
Lise,
Sort your file on var1 (ascending). Then run this syntax: AGGREGATE /OUTFILE='tempfilename.sav' /BREAK=var1 /var4 = FIRST(var2). This will create a temporary unduplicated file with student and score. Then sort your file by var3 (ascending) and run this syntax: MATCH FILES /FILE=* /TABLE='tempfilename.sav' /BY var3. EXECUTE. This will add the variable var4 to your data file. This is the variable that will be the friend's score. Probably a long way around, but it should get the job done. Then Charlotte Woodward Data Coordinator/Analyst Office of Planning and IR [hidden email] |
Free forum by Nabble | Edit this page |