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
New package: simulate2 and psimulate2Thanks to Kit Baum a new package is available on SSC. simulate2 and psimulate2 enhance and parallali…
Significant interaction term in fixed effects modelDear all, I am currently running linear fixed effects regression models (xtreg, fe vce(cluster id)) …
Regressing on two years backHi all, until now I have estimated intercepts and coefficients "asking" STATA to do it for each diff…
How to do a graph like this one in StataDear Statalist, I am trying do replicate (with my own data) a graph like the one I show below. As y…
Technical Issues with STATAI want to know if anyone is having the same problem as I do. Every time I paste my data on STATA, it…
Subscribe to:
Post Comments (Atom)
0 Response to How to write loops that fill a matrix successively
Post a Comment