Dear Stata users,
I have some trouble in creating a new variable as a result of a matrix.
I am using the command -pco- in Stata 12.
I want to calculate the euclidean distance between subjects (n) based on three attributes (x y z).
The -pco- command reduces all attributes to two dimensions, and generates a matrix (n x n) where each score represents the euclidean distance between each of the subjects.
Here is the obtained matrix, where the tags "codeXX" represents subjects and the values represent the distance between each pair of subjects:
symmetric r(D)[8,8]
code17 code18 code20 code19 code12 code14 code13 code16
code17 0
code18 6 0
code20 12.84375 6.40625 0
code19 10.03125 2.59375 3.5625 0
code12 9.5763889 8.7638887 9.2951387 10.607639 0
code14 3.46875 4.09375 7.25 7 3.0034724 0
code13 8.71875 7.78125 3.375 6.9375 3.045139 2.375 0
code16 3.96875 5.96875 9.875 6.6875 3.1701389 1.8125 4.125 0
I would like to create a new variable reflecting the average distance between him/her and all other subjects. This value, of course, would be different for each subject. For instance, for "code 17", the score of this new variable would be computed as (6+12.84+10.03+9.57+3.46+8.71+3.96)/6
Any help on this will be highly appreciated.
Many thanks in advance,
Oscar
I have some trouble in creating a new variable as a result of a matrix.
I am using the command -pco- in Stata 12.
I want to calculate the euclidean distance between subjects (n) based on three attributes (x y z).
The -pco- command reduces all attributes to two dimensions, and generates a matrix (n x n) where each score represents the euclidean distance between each of the subjects.
Code:
pco conscientiousness neuroticism openness extraversion agreeableness, id(code) matrix list r(D)
symmetric r(D)[8,8]
code17 code18 code20 code19 code12 code14 code13 code16
code17 0
code18 6 0
code20 12.84375 6.40625 0
code19 10.03125 2.59375 3.5625 0
code12 9.5763889 8.7638887 9.2951387 10.607639 0
code14 3.46875 4.09375 7.25 7 3.0034724 0
code13 8.71875 7.78125 3.375 6.9375 3.045139 2.375 0
code16 3.96875 5.96875 9.875 6.6875 3.1701389 1.8125 4.125 0
I would like to create a new variable reflecting the average distance between him/her and all other subjects. This value, of course, would be different for each subject. For instance, for "code 17", the score of this new variable would be computed as (6+12.84+10.03+9.57+3.46+8.71+3.96)/6
Any help on this will be highly appreciated.
Many thanks in advance,
Oscar
Comment