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: Re: Variable selection


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Re: Variable selection
Date   Fri, 4 Mar 2011 09:50:45 +0000 (GMT)

--- On Fri, 4/3/11, Sherriff, Martyn wrote:
> Rather than write a 'locaI' to include the variables that I
> wish to analyse I have tried to exclude the variables that
> I do not want as follows:
> 
> qui:findname
> foreach v of varlist `r(varlist)'{
>     if "`v'" !="chew" {
>         kwallis `v',by(ur6)
>     }
>}

There is no need for such a loop, see the example below:

*------------- begin example -----------------
sysuse auto, clear

// already exclude string variables
ds, has(type numeric) 

// store remaining variable names in a local
local varl `r(varlist)' 

// store the variables you want to exclude 
// in another local 
local out "foreign rep78" 

// remove the variables names you want to remove
local varl : list varl - out

// check if they are really out
di "`varl'"
*--------------- end example -----------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

You can read more about this trick and many more by 
going to the helpfile of -macro- and click on the link
to "extended macro functions".

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

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