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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Re: Variable selection
Date   Fri, 4 Mar 2011 10:42:40 +0000

Martyn is already using a user-written program, -findname-. As is
standard, where he got it from should be mentioned:

dm0048_1 from http://www.stata-journal.com/software/sj10-4
    SJ10-4 dm0048_1.  Update: Finding variable names / Update: Finding
    variable names / by Nicholas J. Cox, Durham University, UK / Support:
    [email protected] / After installation, type help findname

dm0048 from http://www.stata-journal.com/software/sj10-2
    SJ10-2 dm0048.  Finding variables / Finding variables / by Nicholas J.
    Cox, Durham University, UK / Support:  [email protected] / After
    installation, type help findname

Anyone interested in -findname- should download the later version.

With -findname-, there is a more direct solution:

findname chew subject, not

foreach v in `r(varlist)' {
         kwallis `v',by(ur6)
}

Note that since r(varlist) arrives as separate variable names,
-foreach- does not need to be told that it is a varlist, although that
does no harm

In fact the same solution is possible substituting official -ds- for -findname-

ds chew subject, not

For completeness, here is how Maarten's example looks with -findname-

sysuse auto, clear
findname, type(numeric) local(varl)
local out "foreign rep78"
local varl : list varl - out

There are two small differences. -findname- has a slightly different
syntax and it also has a -local()- option.

Nick

On Fri, Mar 4, 2011 at 9:50 AM, Maarten buis <[email protected]> wrote:
>
> 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".


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