my data is as the picture shows. Now I want to compute the dissimilarity of partners for one firm. For example, for firm "170040", I first calculate the Euclidean distance between any two partners (i.e., the Euclidean distance between "392896" and "433578", the Euclidean distance between "433578" and "434390", and the Euclidean distance between "434390" and "392896"), using the following code.
forvalue i=1/3{
matrix dissim D`i'=cat1 cat2 cat3 cat4 cat5 if n==`i', Euclidean
matrix list D`i'
matsum D`i', all(D`i')d
}
The result only show in the results window. But I want to generate a variable of "distance", which store the mean of the above results.
How can this be done? How to store the mean value of all the elements in one matrix into a variable?
Thanksf.
forvalue i=1/3{
matrix dissim D`i'=cat1 cat2 cat3 cat4 cat5 if n==`i', Euclidean
matrix list D`i'
matsum D`i', all(D`i')d
}
The result only show in the results window. But I want to generate a variable of "distance", which store the mean of the above results.
How can this be done? How to store the mean value of all the elements in one matrix into a variable?
Thanksf.
Comment