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.
Related Posts with How to write loops that fill a matrix successively
Creating a cumulative sumHey everyone and thanks for taking the time. Here is some sample data, that I will use to explain m…
Trying to figure out how to effectively display long label names while using tabplotArray Array I am displaying two graphs here - example 1 and example 2. I use the same code for bot…
Graphing results of segmented regression (assessing the guideline effects on the rate of dose reduction)Hi STATA experts, Please help out a novice! I need to graphically display results of the segmented…
Stata 13. Counting variable on loop.Dear all, I'm having problems trying to generate a variable of count from a local and a loop. I need…
Is there any command that can do the BSADF test?Is there any command that can do the BSADF test? Relevant papers Phillips et.al(PWY,2011),Phillips …
Subscribe to:
Post Comments (Atom)
0 Response to How to write loops that fill a matrix successively
Post a Comment