I wrote some syntax to help us identify participants who answered with a set response. We have 8 scales with which this syntax will be applied to. I think that a macro would require less “space” in our already massive syntax file. Could someone give me an example of how to transform this function into a macro? *creates variable that flags a set response (same answer for each question) COMPUTE Bel_SR_t0=999. DO IF (Belief1c_t0=1&Belief2c_t0=1&Belief3c_t0=1&Belief4c_t0=1&Belief5c_t0=1&Belief6c_t0=1&Belief7c_t0=1&Belief8c_t0=1& Belief9c_t0=1&Belief10c_t0=1&Belief11c_t0=1&Belief12c_t0=1&Belief13c_t0=1&Belief14c_t0=1&Belief15c_t0=1&Belief16c_t0=1). compute Bel_SR_t0=1. else if (Belief1c_t0=2&Belief2c_t0=2&Belief3c_t0=2&Belief4c_t0=2&Belief5c_t0=2&Belief6c_t0=2&Belief7c_t0=2&Belief8c_t0=2&Belief9c_t0=2& Belief10c_t0=2&Belief11c_t0=2&Belief12c_t0=2&Belief13c_t0=2&Belief14c_t0=2&Belief15c_t0=2&Belief16c_t0=2). compute Bel_SR_t0=1. else if (Belief1c_t0=3 &Belief2c_t0=3&Belief3c_t0=3&Belief4c_t0=3&Belief5c_t0=3&Belief6c_t0=3&Belief7c_t0=3&Belief8c_t0=3&Belief9c_t0=3& Belief10c_t0=3&Belief11c_t0=3&Belief12c_t0=3&Belief13c_t0=3&Belief14c_t0=3&Belief15c_t0=3&Belief16c_t0=3). compute Bel_SR_t0=1. else if (Belief1c_t0=4 &Belief2c_t0=4&Belief3c_t0=4&Belief4c_t0=4&Belief5c_t0=4&Belief6c_t0=4&Belief7c_t0=4&Belief8c_t0=4&Belief9c_t0=4& Belief10c_t0=4&Belief11c_t0=4&Belief12c_t0=4&Belief13c_t0=4&Belief14c_t0=4&Belief15c_t0=4&Belief16c_t0=4). compute Bel_SR_t0=1. else if(Belief1c_t0=5 &Belief2c_t0=5&Belief3c_t0=5&Belief4c_t0=5&Belief5c_t0=5&Belief6c_t0=5&Belief7c_t0=5&Belief8c_t0=5& Belief9c_t0=5&Belief10c_t0=5&Belief11c_t0=5&Belief12c_t0=5&Belief13c_t0=5&Belief14c_t0=5&Belief15c_t0=5&Belief16c_t0=5). compute Bel_SR_t0=1. else if (BeliefTc_T0>=0). compute Bel_SR_t0=0. end if. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). EXECUTE. *this would be repeated for the 8 scales *then; I add up the sum of the flagged variables COMPUTE SRsum_t0=SUM(Bel_SR_t0, Diff_SR_t0, Beh_SR_t0, BSC_SR_t0, BAI_SR_t0, BDEP_SR_t0, BAN_SR_t0, BDB_SR_t0). EXECUTE. *then I re-code the variable and add var labels & value labels RECODE SRsum_t0 (MISSING=SYSMIS)(2 thru 8=1) (0 thru 1=0). IF SRsum_t0<0 SRsum_t0=999. VARIABLE LABELS SRsum_t0 'Participant has a set response to 2 or more scales 1=yes, 0=no'. VALUE LABELS SRsum_t0 0 'No' 1 'Yes'. EXECUTE In the final syntax unneeded variables are dropped for the final dataset. Thank you for any help, and I apologize about the previous empty e-mail. Jon |
Administrator
|
YIKES!!!!!
Try something like...will suffice to replace EVERYTHING in your "function". COMPUTE Bel_SR_t0=999. IF (MIN(Belief1c_t0 TO Belief1c_t0 Belief16c_t0) = MAX(Belief1c_t0 TO Belief1c_t0 Belief16c_t0) ) Bel_SR_t0=1. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). There is nothing magical about MACROs which will "cure" this! Your "already massive syntax file" is massive because it likely contains HUGE blocks of really inefficient code like what you posted. OTOH: what do you do if someone picks 15 of the same response and a single other response. AFAIC it would still be some sort of "set" response. Strikes me that this is a rather naive approach.
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 jonathonrose
Looks incredibly cumbersome. If I understand you correctly, have you thought of using COUNT to check for non-varying responses first? COUNT r1 = belief1c_t0 to belief16c_t0 (1) /r2 = belief1c_t0 to belief16c_t0 (2) /r3 = belief1c_t0 to belief16c_t0 (3) /r4 = belief1c_t0 to belief16c_t0 (4) /r5 = belief1c_t0 to belief16c_t0 (5) . RECODE r1 to r5 (0 thru 16 = 0)(17 = 1) . MULT RESPONSE groups rset (r1 to r5(1) . John F Hall From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jonathon Rose I wrote some syntax to help us identify participants who answered with a set response. We have 8 scales with which this syntax will be applied to. I think that a macro would require less “space” in our already massive syntax file. Could someone give me an example of how to transform this function into a macro? *creates variable that flags a set response (same answer for each question) COMPUTE Bel_SR_t0=999. DO IF (Belief1c_t0=1&Belief2c_t0=1&Belief3c_t0=1&Belief4c_t0=1&Belief5c_t0=1&Belief6c_t0=1&Belief7c_t0=1&Belief8c_t0=1& Belief9c_t0=1&Belief10c_t0=1&Belief11c_t0=1&Belief12c_t0=1&Belief13c_t0=1&Belief14c_t0=1&Belief15c_t0=1&Belief16c_t0=1). compute Bel_SR_t0=1. else if (Belief1c_t0=2&Belief2c_t0=2&Belief3c_t0=2&Belief4c_t0=2&Belief5c_t0=2&Belief6c_t0=2&Belief7c_t0=2&Belief8c_t0=2&Belief9c_t0=2& Belief10c_t0=2&Belief11c_t0=2&Belief12c_t0=2&Belief13c_t0=2&Belief14c_t0=2&Belief15c_t0=2&Belief16c_t0=2). compute Bel_SR_t0=1. else if (Belief1c_t0=3 &Belief2c_t0=3&Belief3c_t0=3&Belief4c_t0=3&Belief5c_t0=3&Belief6c_t0=3&Belief7c_t0=3&Belief8c_t0=3&Belief9c_t0=3& Belief10c_t0=3&Belief11c_t0=3&Belief12c_t0=3&Belief13c_t0=3&Belief14c_t0=3&Belief15c_t0=3&Belief16c_t0=3). compute Bel_SR_t0=1. else if (Belief1c_t0=4 &Belief2c_t0=4&Belief3c_t0=4&Belief4c_t0=4&Belief5c_t0=4&Belief6c_t0=4&Belief7c_t0=4&Belief8c_t0=4&Belief9c_t0=4& Belief10c_t0=4&Belief11c_t0=4&Belief12c_t0=4&Belief13c_t0=4&Belief14c_t0=4&Belief15c_t0=4&Belief16c_t0=4). compute Bel_SR_t0=1. else if(Belief1c_t0=5 &Belief2c_t0=5&Belief3c_t0=5&Belief4c_t0=5&Belief5c_t0=5&Belief6c_t0=5&Belief7c_t0=5&Belief8c_t0=5& Belief9c_t0=5&Belief10c_t0=5&Belief11c_t0=5&Belief12c_t0=5&Belief13c_t0=5&Belief14c_t0=5&Belief15c_t0=5&Belief16c_t0=5). compute Bel_SR_t0=1. else if (BeliefTc_T0>=0). compute Bel_SR_t0=0. end if. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). EXECUTE. *this would be repeated for the 8 scales *then; I add up the sum of the flagged variables COMPUTE SRsum_t0=SUM(Bel_SR_t0, Diff_SR_t0, Beh_SR_t0, BSC_SR_t0, BAI_SR_t0, BDEP_SR_t0, BAN_SR_t0, BDB_SR_t0). EXECUTE. *then I re-code the variable and add var labels & value labels RECODE SRsum_t0 (MISSING=SYSMIS)(2 thru 8=1) (0 thru 1=0). IF SRsum_t0<0 SRsum_t0=999. VARIABLE LABELS SRsum_t0 'Participant has a set response to 2 or more scales 1=yes, 0=no'. VALUE LABELS SRsum_t0 0 'No' 1 'Yes'. EXECUTE In the final syntax unneeded variables are dropped for the final dataset. Thank you for any help, and I apologize about the previous empty e-mail. Jon |
In reply to this post by David Marso
David,
YIKES indeed! I must admit i am learning on the go, and sometimes i am forced to take the long way around. Your syntax works, however it assigns a 'missing' value to those who did complete the scale but didn't answer with a set response. It is very helpful to see your example though. We are strictly interested in those who answered with a set response for the full scale ATM. COMPUTE Bel_SR_t0=999. IF (MIN(Belief1c_t0 TO Belief16c_t0) = MAX(Belief1c_t0 TO Belief16c_t0) ) Bel_SR_t0=1. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). =============================================== John, That is an interesting method, and would indeed achieve the desired function. From this i would compute a var so that if r1 TO r5 were greater than 0 for a particular scale, it would flag the scale as having a set response. I would just need to figure out a way to still account for those who completed the scale, but didn't answer with a set response. I did get an error though "Unrecognized symbol on the MULT RESPONSE command. The program expected either a group name or a slash ending the GROUPS list." any idea? i am not familiar with the MULT RESPONSE... COUNT r1 = belief1c_t0 to belief16c_t0 (1) /r2 = belief1c_t0 to belief16c_t0 (2) /r3 = belief1c_t0 to belief16c_t0 (3) /r4 = belief1c_t0 to belief16c_t0 (4) /r5 = belief1c_t0 to belief16c_t0 (5) . RECODE r1 to r5 (0 thru 15 = 0)(16 = 1) . MULT RESPONSE groups rset (r1 to r5(1)) . ==================================== Thank you for your help and insight! We are working on a 4 timepoint study, and the full dataset has 1500+variables at the moment. You both have been very helpful with shortening the syntax file. Thank you! -jon |
In reply to this post by David Marso
David, i tweaked your syntax a bit:
COMPUTE Bel_SR_t0=999. DO IF (MIN(Belief1c_t0 TO Belief16c_t0) = MAX(Belief1c_t0 TO Belief16c_t0) ). compute Bel_SR_t0=1. else if (BeliefTc_T0>=0). compute Bel_SR_t0=0. end if. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). EXECUTE. works perfect. thank you for teaching me! -jon |
Administrator
|
Even tidier would be to use the SD function rather than the MIN and MAX (off list fr Rich Ulrich) COMPUTE Bel_SR_t0=999. DO IF (SD(Belief1c_t0 TO Belief16c_t0) EQ 0). + COMPUTE Bel_SR_t0=1. ELSE IF (BeliefTc_T0>=0). + COMPUTE Bel_SR_t0=0. END IF. etc...
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 jonathonrose
Sorry! I left out the frequency sub-command in mult resp. You can also
count the MISSING responses. COUNT r1 = belief1c_t0 to belief16c_t0 (1) /r2 = belief1c_t0 to belief16c_t0 (2) /r3 = belief1c_t0 to belief16c_t0 (3) /r4 = belief1c_t0 to belief16c_t0 (4) /r5 = belief1c_t0 to belief16c_t0 (5) . /rmiss = belief1c_t0 to belief16c_t0 (missing) FREQ r1 to rmiss. RECODE r1 to r5 (0 thru 15 = 0)(16 = 1) . MULT RESPONSE groups rset (r1 to rmiss (1)) /freq rset . There's a set of tutorials for MULT RESP in section 3.3 on my website (see: http://surveyresearch.weebly.com/block-3-analysing-two-variables-and-sometim es-three.html ). The example I wrote is for a single value across a range of variables, but it is also used for a range of values in questions which allow more than one answer (eg. Tick as many as apply). There are some examples of both uses in my Old Dog Old Tricks paper (see: http://surveyresearch.weebly.com/7-old-dog-old-tricks.html main paper, pp31-35; 3rd slideshow, 24-43) If you want to keep the original counts for r1 to rmiss, you can always have two sets of variables and recode the second one. Instead of RECODE above: DO REPEAT X = r1 to rmiss /y = xr1 to xr5 xrmiss . Compute y = x . Recode y (0 thru 15 =0)(16 = 1) . End repeat . John F Hall [hidden email] www.surveyresearch.weebly.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of jonathonrose Sent: 14 July 2011 20:23 To: [hidden email] Subject: Re: Question about macros David, YIKES indeed! I must admit i am learning on the go, and sometimes i am forced to take the long way around. Your syntax works, however it assigns a 'missing' value to those who did complete the scale but didn't answer with a set response. It is very helpful to see your example though. We are strictly interested in those who answered with a set response for the full scale ATM. COMPUTE Bel_SR_t0=999. IF (MIN(Belief1c_t0 TO Belief16c_t0) = MAX(Belief1c_t0 TO Belief16c_t0) ) Bel_SR_t0=1. VARIABLE LABELS Bel_SR_t0 'Set response flag'. VALUE LABELS Bel_SR_t0 0 'No' 1 'Yes'. MISSING VALUES Bel_SR_t0 (999). =============================================== John, That is an interesting method, and would indeed achieve the desired function. From this i would compute a var so that if r1 TO r5 were greater than 0 for a particular scale, it would flag the scale as having a set response. I would just need to figure out a way to still account for those who completed the scale, but didn't answer with a set response. I did get an error though "Unrecognized symbol on the MULT RESPONSE command. The program expected either a group name or a slash ending the GROUPS list." any idea? i am not familiar with the MULT RESPONSE... COUNT r1 = belief1c_t0 to belief16c_t0 (1) /r2 = belief1c_t0 to belief16c_t0 (2) /r3 = belief1c_t0 to belief16c_t0 (3) /r4 = belief1c_t0 to belief16c_t0 (4) /r5 = belief1c_t0 to belief16c_t0 (5) . RECODE r1 to r5 (0 thru 15 = 0)(16 = 1) . MULT RESPONSE groups rset (r1 to r5(1)) . ==================================== Thank you for your help and insight! We are working on a 4 timepoint study, and the full dataset has 1500+variables at the moment. You both have been very helpful with shortening the syntax file. Thank you! -jon -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Question-about-macros-tp458722 7p4587703.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 ===================== 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 David Marso
For this one or the other, you can shorten the commands to one statement
that assigns 1 for True, 0 for False -- COMPUTE Bel_SR_t0= (SD(Belief1c_t0 TO Belief16c_t0) EQ 0). > Date: Thu, 14 Jul 2011 14:13:52 -0700 > From: [hidden email] > Subject: Re: Question about macros > To: [hidden email] > > Even tidier would be to use the SD function rather than the MIN and MAX (off > list fr Rich Ulrich) > COMPUTE Bel_SR_t0=999. > DO IF (SD(Belief1c_t0 TO Belief16c_t0) EQ 0). > + COMPUTE Bel_SR_t0=1. > ELSE IF (BeliefTc_T0>=0). > + COMPUTE Bel_SR_t0=0. > END IF. > etc... > -- Rich Ulrich |
Administrator
|
Normally true,
However, it appears that the desired variable may assume possible 3 values 1 - set behavior 999 - missing 0 - conditional upon BeliefTc_T0>=0 (whatever that is, but apparently important). It seems more natural to compute within a DO IF... --
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?" |
John, Rich & David
thank you for giving me some insight into this, i really appreciate it. what a wonderful resource this board is, i only hope that someday i'll be able to offer assistance to someone as well. John, i will enjoy digging into your site. cheers all, and have a great weekend. -jon |
Free forum by Nabble | Edit this page |