SPSS tutorials website header logo SPSS TUTORIALS VIDEO COURSE BASICS ANOVA REGRESSION FACTOR

SPSS DO REPEAT – Simple Tutorial & Examples

DO REPEAT is a command for running other commands repetitively. SPSS DO REPEAT is often used for looping over (possibly new) variables. VECTOR with LOOP is an alternative way for doing so.

Introduction

SPSS Syntax Example

*1. Create mini test data.

data list free/original.
begin data
1 2 3 4
end data.

*2. Basic dichotimization.

compute d1 = original = 1.
compute d2 = original = 2.
compute d3 = original = 3.
compute d4 = original = 4.
exe.

*3. After visual inspection, delete new variables.

delete variables d1 to d4.

SPSS Do Repeat - Syntax Example 1

*Dichotomize variable with do repeat.

do repeat x = d1 d2 d3 d4 / y = 1 2 3 4.
compute x = original = y.
end repeat print.
exe.

Reconstructing the Original Variable

SPSS Do Repeat - Syntax Example 2

*Reconstruct original variable from dichotomous variables.

do repeat x = d1 to d4 / y = 1 to 4.
if x = 1 reconstructed = y.
end repeat.
exe.

SPSS Do Repeat - Basic Rules

SPSS Do Repeat - Incorrect Syntax Examples

*1. Violation 1: lists contain different numbers of items.

do repeat a = v1 to v4 / b = 1 to 3.
compute a = b.
end repeat.
exe.

*2. Violation 2: non transformation command in do repeat.

do repeat c = d_1 to d_4.
variable labels c "Dummy variable".
end repeat.
exe.

SPSS Do Repeat - Final Notes

SPSS Do Repeat - Syntax Example 4

*1. Create mini test dataset.

data list free/sentence(a45).
begin data
'a b c d    e     f     g     h        i'
end data.

*2. Replace double/triple (and so on) spaces by single ones.

do repeat x = 1 to 3.
compute sentence = replace(sentence,' ',' ').
end repeat.
exe.

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.

THIS TUTORIAL HAS 8 COMMENTS: