Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[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 <>
Subject   Re: st: looping twice over same variables without repeating results
Date   Fri, 18 May 2012 12:31:56 +0200

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.


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


On Fri, May 18, 2012 at 10:52 AM, Beatriz Rodriguez Prado
<>  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:

*   For searches and help try:

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