Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Using results from correlation matrices to pinpoint variables


From   Alejandro Delafuente <alejandro.delafuente@st-antonys.oxford.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Using results from correlation matrices to pinpoint variables
Date   Fri, 17 Jun 2005 20:08:32 +0100 (BST)

Dear Nick, thanks for your advice. With some little adjustments it worked out! 
Also, taking advantage of your generosity let me ask you a quick question: am 
trying to drop some monthly variables in a time sequence (from january 1961 to 
dec 2001) with missings in them. My code looks as follows:
foreach var of varlist jan* feb* ... dec* {
	if `var' ==. {
	drop `var' 
	}
}
But for some reason it is not working. Can you tell why?
As always, many thanks.

In message <031173627889364697C50B3B266CBB8A101BA3@GEOGMAIL.geog.ad.dur.ac.uk> 
statalist@hsphsun2.harvard.edu writes:
> 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 
> n.j.cox@durham.ac.uk 
> 
> > -----Original Message-----
> > From: owner-statalist@hsphsun2.harvard.edu
> > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Alejandro
> > Delafuente
> > Sent: 16 June 2005 17:49
> > To: statalist@hsphsun2.harvard.edu
> > 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/
> 

-- 
Alejandro de la Fuente
QEH/Department of International Development
Oxford University
*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index