"If" syntax question

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

RCJHpsych
Posts: 3
Joined: Mon Sep 29, 2014 2:28 am

"If" syntax question

Postby RCJHpsych » Mon Dec 15, 2014 2:14 pm

Hello,

I am attempting to create a total score using a series of true/false questions. Some of the questions are positively coded and some are negatively coded so that a true score on some results in an increased total score and an false score on some other questions will result in a higher total score. I am aware that I could recode the variables independently but I am hoping that there is another way than adding a 50 new variables to my SPSS file.

I am getting errors with the following syntax related to an expectation of a equal marks for which I assume is because it is expecting a statement like "TOTAL = 2" instead of an additive function. I am hoping this is an easy and quick fix I just can't find the syntax for.

/* 1 = True, 2 = False*/
compute Total = 0.
if Q1 = 2 TOTAL = 1 + TOTAL.
if Q2 = 1 TOTAL = 1 + TOTAL.
execute.

Help me Obi Wan Kenobi. you're my only hope.

Thanks for the help
KeithMurray
Posts: 16
Joined: Fri Feb 21, 2014 1:12 pm

Re: "If" syntax question

Postby KeithMurray » Mon Dec 15, 2014 3:38 pm

Hi

Dummied up some data I have.

Four fields, q1, q2, q3 + q4, each containing either a 1 or a 2.

The following syntax works ....

compute total = 0.
if (q1 = 1) total = total+1.
if (q2 = 2) total = total+1.
if (q3 = 1) total = total+1.
if (q4 = 2) total = total+1.
frequencies variables = total.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: "If" syntax question

Postby GerineL » Mon Dec 15, 2014 3:53 pm

you could also look into do repeat to recode your variables into 1 / 0 (which you can then easily delete via syntax).
also, look into loop, that might be what you need.

Who is online

Users browsing this forum: No registered users and 1 guest

cron