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:30:11 +0000

Maarten showed a different approach, but Martyn's question still remains.

What Martyn needed with his approach was to use & instead of |.

     if "`v'" !="chew" & " `v'" !="subject" {

Think of it this way. With | as operator, "chew" is excluded by the
first condition, but not the second, while the opposite is true for
"subject". Hence, as reported, both get through. So & is the operator
needed, because you want to exclude both.

Another way to do it is with

    if !inlist("`v'", "chew", "subject")

and that approach can be less messy, although there is a limit on the
number of arguments.

I will comment separately on Maarten's solution.

Nick

On Fri, Mar 4, 2011 at 9:40 AM, Sherriff, Martyn
<[email protected]> wrote:
> I have a dataset with 125 variables and I only need to analyse a subset of them. 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)
>        }
>        }
> And this works for the exclusion of a single variable. However if I include more than one variable:
>
>        if "`v'" !="chew" |" `v'" !="subject" {
>
> then no variables are excluded.
>
> Could somebody advise me of the syntax error that I am making - or an improved way of solving the problem?

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