Hello all,

I am working on a project where I need difference scores. I will have a number of difference scores, so typing the command over-and-over will become tedious. I am trying to develop a loop that will provide me with ONLY the difference scores for my variables of interest. I realize there is probably some process that I am overlooking, so I need some assistance, please. I am working with the following code:

** setting up data **
set obs 10000
set seed 40245
*set trace on
gen x1 = rnormal(25, 10)
gen x2 = rnormal(12, 3)
gen x3 = rnormal(10, 5)
gen x4 = rnormal(15, 8)
gen x5 = rnormal(5, 2)
gen x6 = rnormal(3, 1)

** actual difference scores that I desire **
gen d1 = x2 - x1
gen d2 = x4 - x3
gen d3 = x6 - x5

**loop to replicate the difference scores **

local t1 x1 x3 x5
local t2 x2 x4 x6

local counter = 2
foreach v1 of varlist `t1' {
foreach v2 of varlist `t2' {
local ++counter
gen d`counter' = `v2'-`v1'

}
}

sum

drop *

At the moment, the loop provides me every possible combination between `v1' and `v2'. I only want the three. How do I "tame" the loop? Thank you in advance.