Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: looping twice over same variables without repeating results
From
Beatriz Rodriguez Prado <[email protected]>
To
[email protected]
Subject
Re: st: looping twice over same variables without repeating results
Date
Fri, 18 May 2012 12:59:00 +0200
Thank you, Nick, you have solved my problem.
Beatriz
El 18/05/2012 12:46, Nick Cox escribió:
OK, but that bites the other way. You can easy get half but how are
you going to avoid choices of response (outcome, regressand,
criterion, dependent variable) that are arbitrary; there is an
asymmetry to -regress y x- and -regress x y-.
Any way, as a matter of Stata technique, this appears to be what you
are asking for:
sysuse auto, clear
unab varlist : price-foreign
local nv : word count `varlist'
local nvm1 = `nv' - 1
tokenize "`varlist'"
forval i = 1/`nvm1' {
local J = `i' + 1
forval j = `J'/`nv' {
di "``i'' ``j''"
regress ``i'' ``j''
}
}
On Fri, May 18, 2012 at 11:31 AM, Beatriz Rodriguez Prado
<[email protected]> wrote:
Thank you Nick.
The other question you raise is my problem. Sorry it was not clear.
I do not want to regress y on x and x on y. I just want one of two
regressions.
Beatriz
El 18/05/2012 12:03, Nick Cox escribió:
Your question raises another which is whether you want the regression
of y on x _and_ the regression of x on y.
foreach x of local varlist {
foreach y of local varlist {
if "`x'" != "`y'" regress `y' `x'
}
}
is a safer and better way to avoid -regress-ing a variable on itself
but it will produce all the other p (p - 1) regressions for p
variables.
Nick
On Fri, May 18, 2012 at 10:52 AM, Beatriz Rodriguez Prado
<[email protected]> wrote:
I have 3 variables named pmm_and pmm_ext pmm_es and I want to make simple
regressions of each pair of variables.
I have writen this code
foreach x in and ext es {
foreach y in and ext es{
if pmm_`x'!=pmm_`y' {
regres pmm_`x' pmm_`y'
}
}
}
How could avoid to run repeated regressions?
In fact I have 50 variables and have to run regressions, test some
hyphotesis and make graphs and the output of the loop is unnecesary big.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/