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: loop issue


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: loop issue
Date   Wed, 10 Jul 2013 10:13:34 +0100

I think it is easier to think of this the other way round. Also, why
think of it as a loop at all? There are just three cases. There is
marginal advantage to setting up a loop over three cases (a loop is at
least three lines long...).

local myvars  var2 var3  var6 var7 var8 var9  var 10

logistic outcome `myvars'
logistic outcome `myvars'  var5
logistic outcome `myvars'  var1 var5

It would be possible to go

local myvars  var2 var3  var6 var7 var8 var9  var 10
local Myvars
foreach v in ""  var5 var1 {
         local Myvars `Myvars' `v'
         logistic outcome `Myvars'
         <something to do with processing results>
}

Constructs such as loops are there to simplify complicated problems,
not to complicate simple problems.

Nick
[email protected]

On 10 July 2013 10:01, Dherani, Mukesh <[email protected]> wrote:

> I have a very basic problem in creating a loop.
> In my data I want to run successive logistic regression models after dropping a few variables. I have developed following code:
>
> local all  var1 var2 var3 ..................... var 10          // include all variables
> local exclvar1 in var2 var3 ................ var10              // exclude var1
> local exclvar15 in var2 var3 ................ var10             // exclude var1 & var5
>         foreach log in all exclvar1 exclvar15 {
>                 eststo `log' {
>
> }
> }
>
> logistic outcome `log'
>
>
> I want stata to produce three different outputs with i) all variables, ii) excluding var1 & iii) excluding var1 & var5. After this it would store the output accordingly. Stata runs the code but only produces one output with "outcome" only.
> Any corrections .... please. [thank you in advance]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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