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: how to create a loop for all the feasible regressions in a varlist


From   Stefano Lombardi <[email protected]>
To   [email protected]
Subject   Re: st: how to create a loop for all the feasible regressions in a varlist
Date   Wed, 23 Mar 2011 23:42:34 +0100

Il 23/03/2011 23:17, Nick Cox ha scritto:
This came up only a few days ago.

See http://www.stata.com/statalist/archive/2011-03/msg00770.html

local varlist var1 var2 var3 var4
tokenize "`varlist'"

forval i = 1/4 {
        local x : list varlist - `i'
        regress ``i'' `x'
}

On Wed, Mar 23, 2011 at 9:42 PM, Stefano Lombardi<[email protected]>  wrote:

Starting from a list of 4 variables, I need to:
    - regress var1 on var2, var3, var 4
    - regress var2 on var1, var3, var4
and so on..
Basically I need to create a loop where every time the dependent variable is
regressed on all the three others.

I have been trying to use the "foreach" command, but I cannot find the right
way to solve the issue. In fact if I type:

  foreach x in Gasp PNC PUC PPT {
    reg `x' Gasp PNC PUC PPT
    }

the software, obviusly, every time returns an erroneous model (R^2 = 1),
because in each model the dependent variable is explained by itself..
The point is that I have no idea on how to remove the `x' variable from the
regressors list.
*
*   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/
Thank you very much!

Best regards,

Stefano Lombardi
*
*   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