SPSS: use a loop to compute new variables for different time points

Viewed 87

my SPSS-dataset includes variables, that have been collected for different time measurement points. I would like to inverse my variables with a loop for the different time measurement points (t1, t2, t3 and so on...).

Is there a way to repeat the same command for the different time measurement points, e.g. by replacing the X with t1, t2, t3 etc. in a loop?

COMPUTE variable_1_X_inv = 5-variable_1_X
EXE.

Thanks for your help!

1 Answers

Assuming these variables are contiguous in the dataset, this will do the job:

do repeat orig=variable_1_1 to variable_1_50 / inv=variable_1_inv_1 to variable_1_inv_50.
   compute inv = 5 - orig.
end repeat.

Note that variable_1_1_inv to variable_1_50_inv will NOT work, but if you can accept the index being at the end of the name, as above, all should be well.

Note 2: You should also look up loop and vector that can be helpful in similar situations.

Related