已解决
// Construct the list and count the items.
unab varlist: apple-wmt
local k: word count `varlist'
// Loop over distinct pairs of variables:
// 1,2; 1,3, ... 2,3, ...; k-1, k
local km1 = `k' - 1 // k minus 1
forval i = 1/`km1' {
local ip1 = `i' + 1 // i plus 1
forval j = `ip1'/`k' {
local v1: word `i' of `varlist'
local v2: word `j' of `varlist'
di as result _newline "working with `v1' and `v2'"
vecrank `v1' `v2' // trivial example of using v1 and v2
}
}
来源
https://www.statalist.org/forums ... -pairs-in-a-dataset