It sounds as if the heart of this is something like
this
qui foreach x of var v4-v60 {
local whichvar
local highestr = 0
foreach y of var v1-v3 {
corr `x' `y'
if r(rho) > 0.75 & r(rho) > `highestr' {
local highestr = r(rho)
local whichvar `y'
}
}
if "`whichvar'" != "" {
di "`y' `whichvar' `highestr'"
}
}
Nick
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Alejandro
> Delafuente
> Sent: 16 June 2005 17:49
> To: [email protected]
> Subject: st: Using results from correlation matrices to pinpoint
> variables
>
>
> Dear Statalisters,
> I am running several correlations between a set of core
> variables (v1 v2 v3)
> and a list of other variables (v4 to v60). Once each
> correlation is run, I
> want Stata to select a variable from my core group if it
> satisfies two
> conditions: a) has the highest correlation coefficient among
> all (always
> plausible to find one), and b) have a coefficient above >.75.
> Thus, in my
> example below v2 would be the variable that i want. I don't
> know how to tell
> Stata to look for the variable when both conditions are met,
> and then use it
> for other purposes (ie, create a means ratio where the
> denominator would be the
> time mean for the selected variable), or do nothing when this
> is not the case.
> My subprogram below the correlation matrix is just to clarify
> my goal. I don't
> know if saving the matrix after each correlation and then
> referring to the
> outputs of the first column would be a possible way to
> pinpoint my variable.
> Any help on how to program this (if possible) would be very
> much appreciated.
>
> corr v4 $othervars if _n>10
> (obs=162)
>
> | v4 v1 v2 v3
> -------------+------------------------------------
> v4 | 1.0000
> v1 | 0.6307 1.0000
> v2 | 0.8028 0.7753 1.0000
> v3 | 0.7045 0.4304 0.5670 1.0000
>
>
> forvalues i = 1/60 {
> corr v`i' `othervars' //`othervars' includes v1 v2 and v3
> gen ratio`i'=v`i' / x
> // if x has the highest correlation with v`i' & corr>.75 // here v2
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/