Bookmark and Share

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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: looping twice over same variables without repeating results
Date   Fri, 18 May 2012 11:03:16 +0100

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index