|
Let me try to simplify my request. And I think I found a shortcut on how to do this.
I wish to create a cumulative count in my data file for the record number within the data file for the respondent. So- for example- and let us say we have 25 respondents but four rows for each id. Therefore the data file will have 100 records. I want to make it so that I create a variable that is a cumulative count for a common id.
So the data file would look like 1 2 3 4, 1 2 3 4... and so on down the rows in one field. Somehow it needs to also condition on the fact that it restarts the count for each new respid. $casenum = 1 will have respid = 1, #2 has 2, #3 has 3, #4 has 4, AND #5 has 1, and so on....
The following is what I have started to program but I just get a column of 2s if I do this. Not only do I need it to add to the previous row but it, again, needs to re-start every 4 records.
COMPUTE order = 1. COMPUTE order = (order + 1). LEAVE order. EXECUTE. Thanks a bunch!
Zachary
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zachary Feinstein
The scenario is I have 1,000 respondents in a survey. Each person is classified as having a score between 1 and 7 for some brands they rated. They could have rated up to 15 brands total.
My job is to randomly select 4 brands that they will do followup ratings with. Problems occur because some of the rules overlap and I think I know how to fix it but I do not know the SPSS code.
So it starts out by saying brand1 is chosen based on who had the highest score. Only one can fit into Brand 1.
Then the algorithm starts looking at filling brand2 then brand3. Brand 2 says to pull a certain brand but if that does not occur then use another rule. That same rule defines the first condition for brand 3.
So, for example, the first rule for 2 might say to pull any brand that is a 5 or 6, but if they do not exist then pull a 3 or 4 and submit that instead to brand 2.
But brand 3 is to first try to pull 3 or 4 but the problem is that I want to remove any responses (not cases) selected from brand 2 from the pool before I get to brand 3.
To visualize this I am also submitting one respondent from a stacked dataset below. They are no. 1291. I broke brand2 into 2 different fields. One is called brand2_1 and the next one is called brand2_2. No-one qualified to rate the brands based on the first Brand 2 definition but many did based on the 2nd one. What I need to learn to program is if I pull the first response off of brand2_2 then I want to remove that same first response from brand3_1. I am using AGGREGATE with the FIRST() functionality to pull the first instance I find for each of the listed fields. So ideally the first for each. If I can get the program to work it would be 3-1-5-2. The 5 is pulled because I somehow got rid of the first 1 there because it was selected for Brand2.
Any and all help is highly valued and appreciated.
Zachary (651) 698-2184
|
|
Dear Zachary,
I think you need to drop the first line. Try this SPSS code (for nonexisting variable 'order')! COMPUTE order = (order + 1). LEAVE order. EXECUTE. Kind regards, Ruben van den Berg Date: Thu, 18 Jun 2009 15:29:23 -0700 From: [hidden email] Subject: Cumulative Count in Data Window Might Help To: [hidden email] Let me try to simplify my request. And I think I found a shortcut on how to do this.
I wish to create a cumulative count in my data file for the record number within the data file for the respondent. So- for example- and let us say we have 25 respondents but four rows for each id. Therefore the data file will have 100 records. I want to make it so that I create a variable that is a cumulative count for a common id.
So the data file would look like 1 2 3 4, 1 2 3 4... and so on down the rows in one field. Somehow it needs to also condition on the fact that it restarts the count for each new respid. $casenum = 1 will have respid = 1, #2 has 2, #3 has 3, #4 has 4, AND #5 has 1, and so on....
The following is what I have started to program but I just get a column of 2s if I do this. Not only do I need it to add to the previous row but it, again, needs to re-start every 4 records.
COMPUTE order = 1.
COMPUTE order = (order + 1). LEAVE order. EXECUTE. Thanks a bunch!
Zachary
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zachary Feinstein
The scenario is I have 1,000 respondents in a survey. Each person is classified as having a score between 1 and 7 for some brands they rated. They could have rated up to 15 brands total.
My job is to randomly select 4 brands that they will do followup ratings with. Problems occur because some of the rules overlap and I think I know how to fix it but I do not know the SPSS code.
So it starts out by saying brand1 is chosen based on who had the highest score. Only one can fit into Brand 1.
Then the algorithm starts looking at filling brand2 then brand3. Brand 2 says to pull a certain brand but if that does not occur then use another rule. That same rule defines the first condition for brand 3.
So, for example, the first rule for 2 might say to pull any brand that is a 5 or 6, but if they do not exist then pull a 3 or 4 and submit that instead to brand 2.
But brand 3 is to first try to pull 3 or 4 but the problem is that I want to remove any responses (not cases) selected from brand 2 from the pool before I get to brand 3.
To visualize this I am also submitting one respondent from a stacked dataset below. They are no. 1291. I broke brand2 into 2 different fields. One is called brand2_1 and the next one is called brand2_2. No-one qualified to rate the brands based on the first Brand 2 definition but many did based on the 2nd one. What I need to learn to program is if I pull the first response off of brand2_2 then I want to remove that same first response from brand3_1. I am using AGGREGATE with the FIRST() functionality to pull the first instance I find for each of the listed fields. So ideally the first for each. If I can get the program to work it would be 3-1-5-2. The 5 is pulled because I somehow got rid of the first 1 there because it was selected for Brand2.
Any and all help is highly valued and appreciated.
Zachary (651) 698-2184
Express yourself instantly with MSN Messenger! MSN Messenger |
|
Zachary, Ruben,
I don't think this will give you what you want. COMPUTE order = (order + 1). LEAVE order. EXECUTE. It will give a cumulative count, from order=1 to order=100 in the example of 25 ids, each with exactly four records per case. It sounded to me like you wanted a variable that went from 1 to 4 within each id. The key phrases are these. 'I want to make it so that I create a variable that is a cumulative count for a common id. So the data file would look like 1 2 3 4, 1 2 3 4... and so on down the rows in one field ...'. I think you need something like this. Compute order=1. If (lag(id) eq id) order=lag(order)+1. Gene Maguin ===================== 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 |
|
If you want a column that cycles through the numbers 1,2,3,4,
then this works: compute order=mod($casenum,4)+1. Tony Babinec [hidden email] "They always say time changes things, but you actually have to change them yourself." Andy Warhol ===================== 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 |
|
In reply to this post by Ruben Geert van den Berg
Dear Zachary,
I'm not entirely sure but I think it's something like this: SPSS computes a new variable starting from $casenum 1 and works downwards to the last $casenum. When it proceeds from $casenum 1 to $casenum 2, the computation for $casenum to starts with '0' and the value for $casenum 1 is forgotten. LEAVE causes the computation for $casnum 2 not to start with '0' but with the value of the previous case. The new variable is not reinitialized when proceeding from case to case. Kind regards and have a nice weekend! Ruben van den Berg Date: Fri, 19 Jun 2009 06:27:06 -0700 From: [hidden email] Subject: Re: Cumulative Count in Data Window Might Help To: [hidden email]
COMPUTE order = (order + 1). IF (order > 15) order = 1. LEAVE order. EXECUTE. Thanks a bunch! The code up above is exactly what I employed too. I appreciate the help. I frankly do not understand the logic to the LEAVE command for some reason. Zachary From: Ruben van den Berg <[hidden email]> To: [hidden email]; SPSS mailing list <[hidden email]> Sent: Friday, June 19, 2009 1:53:02 AM Subject: RE: Cumulative Count in Data Window Might Help Dear Zachary, I think you need to drop the first line. Try this SPSS code (for nonexisting variable 'order')! COMPUTE order = (order + 1). LEAVE order. EXECUTE. Kind regards, Ruben van den Berg Date: Thu, 18 Jun 2009 15:29:23 -0700 From: [hidden email] Subject: Cumulative Count in Data Window Might Help To: [hidden email] Let me try to simplify my request. And I think I found a shortcut on how to do this.
I wish to create a cumulative count in my data file for the record number within the data file for the respondent. So- for example- and let us say we have 25 respondents but four rows for each id. Therefore the data file will have 100 records. I want to make it so that I create a variable that is a cumulative count for a common id.
So the data file would look like 1 2 3 4, 1 2 3 4... and so on down the rows in one field. Somehow it needs to also condition on the fact that it restarts the count for each new respid. $casenum = 1 will have respid = 1, #2 has 2, #3 has 3, #4 has 4, AND #5 has 1, and so on....
The following is what I have started to program but I just get a column of 2s if I do this. Not only do I need it to add to the previous row but it, again, needs to re-start every 4 records.
COMPUTE order = 1.
COMPUTE order = (order + 1). LEAVE order. EXECUTE. Thanks a bunch!
Zachary
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zachary Feinstein
The scenario is I have 1,000 respondents in a survey. Each person is classified as having a score between 1 and 7 for some brands they rated. They could have rated up to 15 brands total.
My job is to randomly select 4 brands that they will do followup ratings with. Problems occur because some of the rules overlap and I think I know how to fix it but I do not know the SPSS code.
So it starts out by saying brand1 is chosen based on who had the highest score. Only one can fit into Brand 1.
Then the algorithm starts looking at filling brand2 then brand3. Brand 2 says to pull a certain brand but if that does not occur then use another rule. That same rule defines the first condition for brand 3.
So, for example, the first rule for 2 might say to pull any brand that is a 5 or 6, but if they do not exist then pull a 3 or 4 and submit that instead to brand 2.
But brand 3 is to first try to pull 3 or 4 but the problem is that I want to remove any responses (not cases) selected from brand 2 from the pool before I get to brand 3.
To visualize this I am also submitting one respondent from a stacked dataset below. They are no. 1291. I broke brand2 into 2 different fields. One is called brand2_1 and the next one is called brand2_2. No-one qualified to rate the brands based on the first Brand 2 definition but many did based on the 2nd one. What I need to learn to program is if I pull the first response off of brand2_2 then I want to remove that same first response from brand3_1. I am using AGGREGATE with the FIRST() functionality to pull the first instance I find for each of the listed fields. So ideally the first for each. If I can get the program to work it would be 3-1-5-2. The 5 is pulled because I somehow got rid of the first 1 there because it was selected for Brand2.
Any and all help is highly valued and appreciated.
Zachary (651) 698-2184
Express yourself instantly with MSN Messenger! MSN Messenger Express yourself instantly with MSN Messenger! MSN Messenger |
|
In reply to this post by Anthony Babinec
Sorry, didn't test the syntax last time. Try
compute order=mod($casenum-1,4)+1. Tony Babinec [hidden email] "They always say time changes things, but you actually have to change them yourself." Andy Warhol ===================== 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 |
| Free forum by Nabble | Edit this page |
