# Jeromy Anglim's Blog: Psychology and Statistics

## Saturday, October 3, 2009

### Scoring a Multiple Choice Test in SPSS using DO REPEAT

How do you score a multiple choice test in SPSS? This post shows you how.

In R: As a side point, to do it in R, just use the score.multiple.choice() function from the psych package.

In SPSS: The following example is based on a class example that I teach. The raw data were the response options (1 to 4) for 53 four-choice multiple test items. the name of each variable was ability1, ability2, and so on, to ability53. The questions are not a serious set of questions. The correct responses were known. I learnt how to use DO REPEAT from Richard Bell.

Run the following syntax:
DO REPEAT  xraw = ability1 to ability53/
xkey = 3, 2, 4, 1, 2, 2, 1, 1, 1, 3, 4, 4, 1,
2, 4, 2, 4, 1, 2, 4, 1, 4, 2, 1, 2, 1,
2, 2, 4, 2, 1, 2, 4, 3, 4, 1, 2, 1, 2,
2, 1, 4, 3, 2, 1, 4, 4, 1, 3, 2, 1, 2,
3/
xscore=score1 to score53.
COMPUTE  xscore = 0.
IF ( xraw = xkey ) xscore = 1.
END REPEAT.
EXECUTE.

COMPUTE meanCorrect = MEAN.53(score1 to score53).
EXECUTE.

The SPSS syntax explained:
• you may need to bring up a syntax editor (File - New - Syntax)
• Verbally the syntax roughly reads:
• Set up a loop: create a variable xraw that will take on one of 53 different values (ability1 to abiltiy53); also create a variable xkey which on each iteration through loop will take on the next value in the series; also create a variable xscore that will take on one of 53 different values (score1 to score53).
• For each iteration through the loop initialise the variable xscore to 0. Then if the response for that item (xraw) matches the key (xkey) the respondent answered the item correctly. Therefore, make xscore 1 to indicate that the person answered it correctly. In order for this loop to run include the the EXECUTE command.
• Then compute a new variable to store the mean number of items correct. The mean.53 function calculates the mean of the items. The 53 in the "mean.53" is used so that any person with missing data will get no mean. If you had mean.3 and someone only answered three items and they answered them correctly, then the person would appear to get 100% correct. there are many other ways that this total could be computed.
• Thus, to make this your own example, change 53 to the number of items you have and change the key.
Some Pictures:

1) The data frame showing the first few variables of the 53 raw ability test items.

2) What the syntax might look like in SPSS using version 17.

3) The data frame with the new variables (score1 to score 53); Note that I have copy and pasted the variable names from the raw items to the scored items.

4) Running basic descriptive statistics on the newly created mean.

1. Hello Jeremy, I want to ask you a few questions regarding SPSS if you don't mind. I learn to use with SPSS mostly through help button from SPSS, google and youtube, but I still couldn't find the right answer.

Now I have 22 variables of knowledge question where there are 3 choices given which are agree, disagree and don't know for the respondent to answer.

Firstly, I want to find the total mean of these 22 variables together not as in mean from each variables.

Secondly, I need to find the cut-off points or also known as the score of the correct answer.

I really hope that you could help me.

Thank You :)

1. You can use the code above to score the test. That said, you would need to decide how to code "don't know". In general with multiple choice tests we omit the don't know category. For example, you could score it correct = 1, don't know = 0, and incorect = -1.

2. thank you so much!

2. Dear Jeromy,
I hope you will see this comment soon and be able to respond. I am actually trying to follow your instructions above on how to set up the DO REPEAT syntax in SPSS. However, I am having such a hard time configuring the variables. When you say "create xraw, xscore, xkey" do you mean that I have to create such variables in the variable view on SPSS? Under the variable value tab, what should I put in? For example, I would type xraw in the name tab, but for value, I have no idea what to put in.
Please help me clarify this. I am pretty to SPSS as you can tell. But I am trying to score some multiple choice test items using your method and I am willing to learn it fast.

Thank you very much and I hope to hear from you soon.
Duke from Taiwan

1. xraw, scrore and xkey are just variables used inside the loop to represent information that changes on each iteration of the loop. You don't create them in your SPSS data file.

3. Hi Jeromy,
I hope you are still active on this issue because I have a question :/ I tried to adapt your code so it fits mine and it looks as follows:

DO REPEAT xraw = ICF01a to ECF01d/
xkey = 3, 1, 4, 5, 2, 5, 5, 1
/
xscore=score1 to score8.
COMPUTE xscore = 0.
IF ( xraw = xkey ) xscore = 2.
END REPEAT.
EXECUTE.

However, the created scores (score 1-8) are all zero although for the first case each xraw = xkey. How can that be? And do you know how I have to adapt the code in order to give further points for answers that are xkex +/- 1?
Best
Ina

4. Hi Jeromy,
I'm looking for a SPSS syntax to apply a scoring key to the raw data which converts the original values in 0, 1, or 2. I tried to adapt your Syntax but unfortunately it doesn't work. This is how i changed it:

DO REPEAT xraw = ICF01a to DO07e/
xkey = 3, 2, 4, 1, 2, 2, 1, 1, 1, 3, 4, 4, 1,
2, 4, 2, 4, 1, 2, 4, 1, 4, 2, 1, 2, 1,
2, 2, 4, 2, 1, 2, 4, 3, 4, 1, 2, 1, 2
xscore=score1 to score53.
COMPUTE xscore = 0.
IF ( xraw = xkey ) xscore = 2.
ELSE IF (xraw + 1 OR xraw - 1 = xkey) xscore = 1.
ELSE xscore = 0.

END REPEAT.
EXECUTE.

I tried to implement it like this in SPSS but unfortunately it doesn't work.
It would be great if you could help me to adapt the Syntax correctly.

Cheers
Ina

5. Hi Jeromy,

After I have run your script, I don't see that any new variables are created. For my master thesis, I want to compare scores on a multiple choice test. Therefore, I want to create a variable that holds the score for each participant in my experiment. I'm I doing something wrong, or do I need to perform an additional step?

Cheers,

Frank