Hi all,
I've got a questionnaire that needs some weights applied to the scores before summing the totals.
There are 10 questions.
If a person responds with a 1, multiply the response x 1
If a person responds with a 2, multiply the response x 2
If a person responds with a 3, multiply the response x 3
i created 10 new variables:
numeric Tot1 to Tot10.
Now, I'm in the middle of a bunch of "if then" statments to do the above, but i gotta think there is a cleaner and less error ridden way to accomplish this than the mess of syntax i'm creating right now.
I also suspect this is not the first time this has been asked.
If anyone can direct me to a previous thread that gives this syntax, i'd appreciate it. I searched through nabble but i don't think i'm using the correct search terms.
TIA
Carol
|
weight cases by varname.
Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "Parise, Carol A." <[hidden email]> To: [hidden email], Date: 09/13/2013 01:03 PM Subject: Cleaner syntax for weighting responses Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi all, I've got a questionnaire that needs some weights applied to the scores before summing the totals. There are 10 questions. If a person responds with a 1, multiply the response x 1 If a person responds with a 2, multiply the response x 2 If a person responds with a 3, multiply the response x 3 i created 10 new variables: numeric Tot1 to Tot10. Now, I'm in the middle of a bunch of "if then" statments to do the above, but i gotta think there is a cleaner and less error ridden way to accomplish this than the mess of syntax i'm creating right now. I also suspect this is not the first time this has been asked. If anyone can direct me to a previous thread that gives this syntax, i'd appreciate it. I searched through nabble but i don't think i'm using the correct search terms. TIA Carol |
In reply to this post by parisec
can you provide a small
set of data say with 2 variables and 6 cases that shows (where wants shows
what value you want as results)
id var1 var2 want1 want2 Art Kendall Social Research ConsultantsOn 9/13/2013 2:04 PM, parisec [via SPSSX Discussion] wrote:
Art Kendall
Social Research Consultants |
Sure...I have Q1 to Q4; Tq1 to Tq4 is the goal.
ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4 1 1 2 1 3 1 4 1 9 2 2 1 2 1 4 1 4 1 3 3 2 0 2 9 4 0 4 4 1 3 3 0 1 9 9 0 numeric Tq1 to Tq4. if (Q1=1 or Q2=1 or Q3=1 or Q4=1) ToQ1=Q1*1 if (Q1=2 or Q2=2 or Q3=2 or Q4=2) ToQ1=Q1*2 if (Q1=3 or Q2=3 or Q3=3 or Q4=3) ToQ1=Q1*3 ....follows same pattern for each question. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall Sent: Friday, September 13, 2013 11:17 AM To: [hidden email] Subject: Re: Cleaner syntax for weighting responses can you provide a small set of data say with 2 variables and 6 cases that shows (where wants shows what value you want as results) id var1 var2 want1 want2 Art Kendall Social Research Consultants On 9/13/2013 2:04 PM, parisec [via SPSSX Discussion] wrote: Hi all, I've got a questionnaire that needs some weights applied to the scores before summing the totals. There are 10 questions. If a person responds with a 1, multiply the response x 1 If a person responds with a 2, multiply the response x 2 If a person responds with a 3, multiply the response x 3 i created 10 new variables: numeric Tot1 to Tot10. Now, I'm in the middle of a bunch of "if then" statments to do the above, but i gotta think there is a cleaner and less error ridden way to accomplish this than the mess of syntax i'm creating right now. I also suspect this is not the first time this has been asked. If anyone can direct me to a previous thread that gives this syntax, i'd appreciate it. I searched through nabble but i don't think i'm using the correct search terms. TIA Carol ________________________________ If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Cleaner-syntax-for-weighting-responses-tp5721977.html To start a new topic under SPSSX Discussion, email [hidden email] To unsubscribe from SPSSX Discussion, click here. NAML <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> Art Kendall Social Research Consultants ________________________________ View this message in context: Re: Cleaner syntax for weighting responses <http://spssx-discussion.1045642.n5.nabble.com/Cleaner-syntax-for-weighting-responses-tp5721977p5721979.html> Sent from the SPSSX Discussion mailing list archive <http://spssx-discussion.1045642.n5.nabble.com/> 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 |
Administrator
|
DO REPEAT v=v1 TO v10 /t=t1 TO t10.
+ COMPUTE t=v**2. + COMPUTE total=SUM(total,t). END REPEAT. or if you don't require the t variables? DO REPEAT v=v1 TO v10 . + COMPUTE total=SUM(total,v**2). END REPEAT.
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 parisec
At 02:28 PM 9/13/2013, Parise, Carol A. wrote:
>I have Q1 to Q4; Tq1 to Tq4 is the goal. > > >ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4 >1 1 2 1 3 1 4 1 9 >2 2 1 2 1 4 1 4 1 >3 3 2 0 2 9 4 0 4 >4 1 3 3 0 1 9 9 0 > > >numeric Tq1 to Tq4. > if (Q1=1 or Q2=1 or Q3=1 or Q4=1) ToQ1=Q1*1 > if (Q1=2 or Q2=2 or Q3=2 or Q4=2) ToQ1=Q1*2 > if (Q1=3 or Q2=3 or Q3=3 or Q4=3) ToQ1=Q1*3 >....follows same pattern for each question. This would give Tq1=6 rather than 4 in case 1. Which is correct? ===================== 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 |
ugh.
Tq1 should actually be 1 for Q1 case 1 . The rules are: Multiply any question with a response of 1 by 1 Multiply any question with a response of 2 by 2 Multiply any question with a response of 3 by 3 this is why i let spss do the math. -----Original Message----- From: Richard Ristow [mailto:[hidden email]] Sent: Friday, September 13, 2013 11:57 AM To: Parise, Carol A.; [hidden email] Subject: Re: Cleaner syntax for weighting responses At 02:28 PM 9/13/2013, Parise, Carol A. wrote: >I have Q1 to Q4; Tq1 to Tq4 is the goal. > > >ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4 >1 1 2 1 3 1 4 1 9 >2 2 1 2 1 4 1 4 1 >3 3 2 0 2 9 4 0 4 >4 1 3 3 0 1 9 9 0 > > >numeric Tq1 to Tq4. > if (Q1=1 or Q2=1 or Q3=1 or Q4=1) ToQ1=Q1*1 > if (Q1=2 or Q2=2 or Q3=2 or Q4=2) ToQ1=Q1*2 > if (Q1=3 or Q2=3 or Q3=3 or Q4=3) ToQ1=Q1*3 ....follows same >pattern for each question. This would give Tq1=6 rather than 4 in case 1. Which is correct? ===================== 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 parisec
Bother!
At 02:28 PM 9/13/2013, Parise, Carol A. wrote: >I have Q1 to Q4; Tq1 to Tq4 is the goal. > > >ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4 >1 1 2 1 3 1 4 1 9 >2 2 1 2 1 4 1 4 1 >3 3 2 0 2 9 4 0 4 >4 1 3 3 0 1 9 9 0 > > >numeric Tq1 to Tq4. > if (Q1=1 or Q2=1 or Q3=1 or Q4=1) ToQ1=Q1*1 > if (Q1=2 or Q2=2 or Q3=2 or Q4=2) ToQ1=Q1*2 > if (Q1=3 or Q2=3 or Q3=3 or Q4=3) ToQ1=Q1*3 >....follows same pattern for each question. This would give Tq1=3 rather than 1 in case 1; and 3 rather than 1 in case 4. Which is correct? (I should have taken that nap.) ===================== 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
----- Original Message -----
> From: David Marso <[hidden email]> > To: [hidden email] > Cc: > Sent: Friday, September 13, 2013 8:46 PM > Subject: Re: [SPSSX-L] Cleaner syntax for weighting responses > > DO REPEAT v=v1 TO v10 /t=t1 TO t10. > + COMPUTE t=v**2. > + COMPUTE total=SUM(total,t). > END REPEAT. But where did "total" come from? Or did that variable exist already? How about this (untested): vector #total = Tq1 to Tq4. loop #i = 1 to 4. +do repeat #question = q1 to q4 / #n = 1 to 4. + if ( any(#n, q1 to q4) ) #total(#i) = #question * #n. +end repeat. end loop. ===================== 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 parisec
I sent this before but
it did not appear so I am sending it again.
It produces exactly the request results for the cases given. if i understand correctly you just want to square each variable. open a new instance of SPSS. copy and paste the syntax below into a syntax window, run it. data list list/ ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4(9f1). begin data 1 1 2 1 3 1 4 1 9 2 2 1 2 1 4 1 4 1 3 3 2 0 2 9 4 0 4 4 1 3 3 0 1 9 9 0 end data. do repeat myvar= q1 to q4 /result= r1 to r4. compute result = myvar**2. end repeat. formats r1 to r4(f2). list. Art Kendall Social Research ConsultantsOn 9/13/2013 2:04 PM, parisec [via SPSSX Discussion] wrote:
Art Kendall
Social Research Consultants |
I've been off trying out everyones suggestions.
1) Yes. now that i look at it, doi! the variables just need to be squared. 2) The below worked as did David Marso's I haven't tried Albert-Jan's yet but am going to give it a shot. You have all given me solutions that not only work here, but that i think i can apply to some other projects i've got going. Thanks a bunch for taking your time to help. Carol -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall Sent: Friday, September 13, 2013 12:50 PM To: [hidden email] Subject: Re: Cleaner syntax for weighting responses I sent this before but it did not appear so I am sending it again. It produces exactly the request results for the cases given. if i understand correctly you just want to square each variable. open a new instance of SPSS. copy and paste the syntax below into a syntax window, run it. data list list/ ID Q1 Q2 Q3 Q4 Tq1 Tq2 Tq3 Tq4(9f1). begin data 1 1 2 1 3 1 4 1 9 2 2 1 2 1 4 1 4 1 3 3 2 0 2 9 4 0 4 4 1 3 3 0 1 9 9 0 end data. do repeat myvar= q1 to q4 /result= r1 to r4. compute result = myvar**2. end repeat. formats r1 to r4(f2). list. Art Kendall Social Research Consultants On 9/13/2013 2:04 PM, parisec [via SPSSX Discussion] wrote: Hi all, I've got a questionnaire that needs some weights applied to the scores before summing the totals. There are 10 questions. If a person responds with a 1, multiply the response x 1 If a person responds with a 2, multiply the response x 2 If a person responds with a 3, multiply the response x 3 i created 10 new variables: numeric Tot1 to Tot10. Now, I'm in the middle of a bunch of "if then" statments to do the above, but i gotta think there is a cleaner and less error ridden way to accomplish this than the mess of syntax i'm creating right now. I also suspect this is not the first time this has been asked. If anyone can direct me to a previous thread that gives this syntax, i'd appreciate it. I searched through nabble but i don't think i'm using the correct search terms. TIA Carol ________________________________ If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Cleaner-syntax-for-weighting-responses-tp5721977.html To start a new topic under SPSSX Discussion, email [hidden email] To unsubscribe from SPSSX Discussion, click here. NAML <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> Art Kendall Social Research Consultants ________________________________ View this message in context: Re: Cleaner syntax for weighting responses <http://spssx-discussion.1045642.n5.nabble.com/Cleaner-syntax-for-weighting-responses-tp5721977p5721988.html> Sent from the SPSSX Discussion mailing list archive <http://spssx-discussion.1045642.n5.nabble.com/> 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 |
Administrator
|
In reply to this post by Albert-Jan Roskam
Albert-Jan:
total does *NOT* exist prior to: COMPUTE total = SUM(total,t). It doesn't need to. Neat trick IMO to bypass unnecessary initialization code ;-) --
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?" |
A great way to write unreadable, unmaintainable
code.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email], Date: 09/14/2013 09:33 AM Subject: Re: [SPSSX-L] Cleaner syntax for weighting responses Sent by: "SPSSX(r) Discussion" <[hidden email]> Albert-Jan: total does *NOT* exist prior to: COMPUTE total = SUM(total,t). It doesn't need to. Neat trick IMO to bypass unnecessary initialization code ; |
In reply to this post by David Marso
----- Original Message -----
> From: David Marso <[hidden email]> > To: [hidden email] > Cc: > Sent: Saturday, September 14, 2013 5:32 PM > Subject: Re: [SPSSX-L] Cleaner syntax for weighting responses > > Albert-Jan: > total does *NOT* exist prior to: > COMPUTE total = SUM(total,t). > It doesn't need to. > Neat trick IMO to bypass unnecessary initialization code ;-) Hi David, ehh? So you can take the sum of a variable (and something else) before it even springs into life? *) Btw, my code was wrong although it did seem to be a generalization of what the OP mentioned, but maybe I shiohould have read the entire thread. *) confusing: I am now going to drink a beer without actually opening the bottle **) **) on the second thought I *will* open it! --cheers! Albert-Jan ===================== 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 |
Administrator
|
In reply to this post by Jon K Peck
Both readable and maintainable Jon!
Scratching an itch? --
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?" |
Free forum by Nabble | Edit this page |