Hello,

I've got a question regarding the writing of loops: What I would like to do is to write a loop that picks every variable I've got (except for one) consecutively, then calculates the correlation of the variable that is not included with each of the other included variables and writes the correlation coefficient into an empty matrix, that I have created beforehand.
My problem is the following:
If I write:
foreach k in `varlist' {
forvalues i = 1/10 {
forvalues j = 1/100 {
quietly corr g_russia `k'
matrix corr_with_russia [`i',`j']=r(rho)
}
}
}

Then Stata picks the first entry of my variable list, e.g. g_usa, and fills the whole matrix with the values of the correlation of Russia and the USA. But what I would rather like to do is to compute this correlation and put it in the first row and first column-entry of the matrix. The correlation coefficient for e.g. Spain should then be listed in the second column, first row.
But I don't know how to tell Stata to pick the first variable out of a variable list of 100 variables and only change the first entry of the matrix with the values of this variable;
then it should pick the second variable, compute a correlation coefficient and insert this as the second entry and so....

Wouldn't I have to assign numbers to the variables in the varlist to achieve this?

Hope it's halfway clear what I'm struggling with.

Thank's for the support.