|
This helps somewhat, but it doesn't quite do what I need it to, so I'll be
more specific to my problem. Imagine I have 10 people who have listed, in 10 variables, 1-10 objects, and, in 10 variables, how much they like those objects (1-5). a1 a2 b1 b2 1 cat dog 3 1 2 rat mat 2 4 now I have a variable which holds a list of possible objects that they could've answered (i constructed this list by looking at all their answers) a1 a2 b1 b2 living not 1 cat dog 3 1 cat mat 2 rat mat 2 4 dog rat the final goal, is to have something that looks like living not 3 4 1 2 i'm currently doing this in a nested-loop fashion, in which i put a1-a10 into a vector, which I scan a1-a10 one by one against what i hope to be each possible answer in living 1 by 1 (and then non-living). currently, my problem is that the nested-loop will scan through each answer for each participant in the vector part of the comparison, but it will only scan the 'living' object that corresponds to that row. so for example, it would find 'cat' because they're both in row 1, but it wouldn't find dog in row 1, and it wouldnt' find rat in row 2. here's my current code for this part: Vector tmpa = q1.1 to q1.5. Vector tmpb = q1.6 to q1.10. LOOP #X=1 TO 5 BY 1. if tmpa(#X) = living_objects living_objects2 = tmpb(#X). END LOOP. How should I alter my code in order to make the vector tmpa scan against all the living_objects, and not just the one that is in the row it's currently looking at? Thanks :-) |
|
I don't understand your explanation but suggest you look at the VARSTOCASES command. Generally speaking, transformations only work within cases and you cannot get more cases than had before with a compute or an if. Also, you can only store one value in a variable in a case. If you want to do tabulations which count across multiple variables, you need to use MULT RESPONSE, TABLES, or CTABLES and don't need the VARSTOCASES command.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Dan Sent: Tuesday, May 15, 2007 9:56 AM To: [hidden email] Subject: [BULK] Re: Extracting Individual Cases From Variables? Importance: Low This helps somewhat, but it doesn't quite do what I need it to, so I'll be more specific to my problem. Imagine I have 10 people who have listed, in 10 variables, 1-10 objects, and, in 10 variables, how much they like those objects (1-5). a1 a2 b1 b2 1 cat dog 3 1 2 rat mat 2 4 now I have a variable which holds a list of possible objects that they could've answered (i constructed this list by looking at all their answers) a1 a2 b1 b2 living not 1 cat dog 3 1 cat mat 2 rat mat 2 4 dog rat the final goal, is to have something that looks like living not 3 4 1 2 i'm currently doing this in a nested-loop fashion, in which i put a1-a10 into a vector, which I scan a1-a10 one by one against what i hope to be each possible answer in living 1 by 1 (and then non-living). currently, my problem is that the nested-loop will scan through each answer for each participant in the vector part of the comparison, but it will only scan the 'living' object that corresponds to that row. so for example, it would find 'cat' because they're both in row 1, but it wouldn't find dog in row 1, and it wouldnt' find rat in row 2. here's my current code for this part: Vector tmpa = q1.1 to q1.5. Vector tmpb = q1.6 to q1.10. LOOP #X=1 TO 5 BY 1. if tmpa(#X) = living_objects living_objects2 = tmpb(#X). END LOOP. How should I alter my code in order to make the vector tmpa scan against all the living_objects, and not just the one that is in the row it's currently looking at? Thanks :-) |
|
In reply to this post by Dan-155
At 11:55 AM 5/15/2007, Dan wrote:
>Imagine I have 10 people And, if I understand you correctly, each person is a record ('case') in your SPSS file. That is, the following record is the information for person number 1: 1 cat dog 3 1 >[They] have listed, in 10 variables, 1-10 objects, and, in 10 >variables, how much they like those objects (1-5). > a1 a2 b1 b2 > >1 cat dog 3 1 >2 rat mat 2 4 So person 1 likes cats level 3, person 2 likes rats level 4, ... >now I have a variable which holds a list of possible objects that they >could've answered (i constructed this list by looking at all their >answers) > > a1 a2 b1 b2 living not >1 cat dog 3 1 cat mat >2 rat mat 2 4 dog > rat >the final goal, is to have something that looks like >living not >3 4 >1 >2 Here, you're forgetting about people, and just looking at objects. You mean, I take it, that three living objects were mentioned, liked at levels 3, 1 and 2; and one none-living object ('mat') liked at level 4. (The file structure is a mistake, I think. It's good to have 'living' and 'not' as two variables in the same cases. That structure suggests that the '3' and '4' are somehow associated, which they aren't.) >i'm currently doing this in a nested-loop fashion, in which i put >a1-a10 into a vector, which I scan a1-a10 one by one against what i >hope to be each possible answer in living 1 by 1 (and then non-living). >currently, my problem is that the nested-loop will scan through each >answer for each participant in the vector part of the comparison, but >it >will only scan the 'living' object that corresponds to that row. Exactly so. That's how the transformation language works: read a record, execute the program; read the next record, execute the program against ITS data,... I don't think I can make your approach work. A key problem is the structure of your data: you have the category classifications as variables, in the same file as the 'likings'. So your record > a1 a2 b1 b2 living not >1 cat dog 3 1 cat mat states two, unrelated things: first, the things that person 1 likes; and second, what categories 'cat' and 'mat' belong to. I suggest three changes: . First, that the classification of objects (living or not) should be in a separate file; . Second (as ViAnn Beadle suggests), you use VARSTOCASES on your original file, so there's a separate record for each response. Then, you can assign categories to the objects named, using MATCH FILES; . Third, you write the 'likings' of living and non-living objects to separate records, not to separate variables in one record. This is SPSS 15 draft output. It uses datasets (SPSS 14 or 15), but could be re-written using scratch files instead, if desired.* ................................................................. . DATASET ACTIVATE People WINDOW=FRONT. LIST. List |-----------------------------|---------------------------| |Output Created |15-MAY-2007 16:05:02 | |-----------------------------|---------------------------| [People] Person a1 a2 b1 b2 1 cat dog 3 1 2 rat mat 2 4 Number of cases read: 2 Number of cases listed: 2 * Use VARSTOCASES to put each 'liking' in a separate record ...... . DATASET COPY Likings. DATASET ACTIVATE Likings WINDOW=FRONT. VARSTOCASES /MAKE Object FROM a1 a2 /MAKE Liking FROM b1 b2 /INDEX = Response# "Response, within person"(2) /KEEP = Person /NULL = DROP. Variables to Cases |----------------------------|---------------------------| |Output Created |15-MAY-2007 16:05:03 | |----------------------------|---------------------------| [Likings] Generated Variables |---------|---------------| |Name |Label | |---------|---------------| |Response#|Response, | | |within person | |Object |<none> | |Liking |<none> | |---------|---------------| Processing Statistics |-------------|-| |Variables In |5| |Variables Out|4| |-------------|-| LIST. List |-----------------------------|---------------------------| |Output Created |15-MAY-2007 16:05:03 | |-----------------------------|---------------------------| [Likings] Person Response# Object Liking 1 1 cat 3 1 2 dog 1 2 1 rat 2 2 2 mat 4 Number of cases read: 4 Number of cases listed: 4 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ . * Here is the separate file with the classifications of the objects . DATASET ACTIVATE Objects WINDOW=FRONT. SORT CASES BY Object. LIST. List |-----------------------------|---------------------------| |Output Created |15-MAY-2007 16:05:04 | |-----------------------------|---------------------------| [Objects] Object Category cat living dog living mat not rat living Number of cases read: 4 Number of cases listed: 4 * Now, combine, to categorize the objects that are liked or not: . DATASET ACTIVATE Likings WINDOW=FRONT. SORT CASES BY Object. MATCH FILES /FILE =Likings /TABLE=Objects /BY Object. SORT CASES BY Category Person Response#. LIST Category Liking Object Person Response#. List |-----------------------------|---------------------------| |Output Created |15-MAY-2007 16:05:05 | |-----------------------------|---------------------------| Category Liking Object Person Response# living 3 cat 1 1 living 1 dog 1 2 living 2 rat 2 1 not 4 mat 2 2 Number of cases read: 4 Number of cases listed: 4 =================== APPENDIX: Test data =================== * ................................................................. . * ................. Test data ..................... . * "People" matches the test data: . DATA LIST LIST SKIP=1 /Person (F3) a1 a2 (2A4) b1 b2(2F2). BEGIN DATA a1 a2 b1 b2 1 cat dog 3 1 2 rat mat 2 4 END DATA. DATASET NAME People. . /*-- LIST /*-*/. * "Objects" is a separate file; in the test data, it was in the . * same file as the people. (That made the problem difficult to the . * point of near impossibility.) . DATA LIST LIST SKIP = 1 /Object (A4) Category (A6). BEGIN DATA. OBJECT CATEGORY cat living dog living rat living mat not END DATA. DATASET NAME Objects. . /*-- LIST /*-*/. |
| Free forum by Nabble | Edit this page |
