• Paul Brown, Director

Another vector application in SPSS

Updated: Sep 13, 2018

In a similar vein to the ‘Using vectors to deal with multi-coded questions in SPSS’ blog piece, here we’ll use use vectors and loops to create a set of calculated variables from sets of existing variables.

Suppose our final satisfaction score, satfinal, was the weighted sum of two stated measures of satisfaction, sat_a and sat_b, as given by the formula satfinal = (2 x sat_a) + (3 x sat_b). Suppose further that each respondent had answered the satisfaction questions for varying subsets of a set of five different brands.

The data was exported in the following manner, where s_a_1 is sat_a for brand 1, s_b_1 is sat_b for brand 1, s_a_2 is sat_a for brand 2, s_b_2 is sat_b for brand 2 etc., as in the table below.

We need to turn it into the following, where sfin_1 was satfinal for brand1, sfin_2 was satfinal for brand2 etc.

To accomplish this, we used the following piece of code using vectors and scratch variables.

vector sfin_(5).

vector #t= s_a_1 to s_b_5 .

loop #i=1 to 5.

compute sfin_(#i)=2*#t(2*#i-1)+3*#t(2*#i).

end loop.


Here we create the vectors and loop in the usual manner. The trick is to create the new variables by using the adjacent variables pairs given by #t(2*#i-1) for sat_a, and #t(2*#i) for sat_b.

Author: Paul Brown, Director



We solve the data problems that seem unsolvable.


  • Jump Data Twitter Account
  • Jump Data Linkedin Account

Jumpdata Limited. Company No. 08241266.

JumpData Logo
Jump Data Linkedin Account
Jump Data Twitter Account