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: Delete upper case variable
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Re: Delete upper case variable
Date
Mon, 23 Apr 2012 23:04:12 +0100
In this case
keep N* J* C*
is more positive!
Nick
On Mon, Apr 23, 2012 at 9:21 PM, Steve Samuels <[email protected]> wrote:
> What a sweet solution!
>
> There might be a place here for regular expressions if the range of letters to drop
> is more complicated. For example, to drop all variables whose names begin with any
> uppercase letter except "N", "J", or "C"
>
> ****************************************************
> if regexm("`var'","^[AB D-I KLM O-Z]") local todrop
> ****************************************************
>
> and if the first letter is possibly preceded by an underscore
>
> ****************************************************
> if regexm("`var'","^(_|)[AB D-I KLM O-Z]") local todrop
> ****************************************************
>
>
> Steve
> [email protected]
>
>
> On Apr 23, 2012, at 3:23 AM, Nick Cox wrote:
>
> I take your point but remain reluctant to document this, for various
> reasons, including.
>
> Documenting what certain options can do that wasn't intended at all
> would underline some lack of foresight in the design.
>
> Documenting what they can do might give the impression that tricksy
> one-liners are what you need to find, which is a very mixed message.
> In principle you might be able to use the same trick for looking for
> variables with more complicated patterns in value and variable labels
> or characteristics, but then the syntax would get even messier.
>
> In this case, how about
>
> local todrop
> foreach var of var * {
> if inrange(substr("`var'", 1, 1), "A", "Z") local todrop
> `todrop' `var'
> }
>
> if "`todrop'" != "" drop `todrop'
>
> In many ways that's a simpler solution than any using -findname-. Note
> something that is often not grasped: you don't need to fire up -ds- to
> unpack wildcard varlists. It's a pretty direct translation of the
> original problem using only core Stata syntax (macros, loops,
> functions).
>
> Nick
>
> On Mon, Apr 23, 2012 at 2:02 AM, Eric Booth <[email protected]> wrote:
>
>> Ahh, yes, that was the message I was thinking of - I couldn't find it in a SL search. I'm glad I wasnt completely imagining things.
>>
>> Just a friendly suggestion:
>> I know that, in that thread you referenced, you said that you wouldn't make any changes in -findname- for selecting variables names by case since it can be done by any()/all(), but since these options' description "has all VALUES satisfying condition" (my emph.), I think it's big leap for a user to realize it could work with a variable name (and with multiple messages in the past few weeks about this topic there seems to be a need for this functionality).
>> I'm really just suggesting adding an example or clarification of some kind to the options' descriptions to clarify that these options can be extended for use with variable names in this type of situation. Obviously you're free to ignore my suggestion - just wanted to give my 2 cents [which, with the USD to Pounds exchange rate what it is these days, is worth even less than that to you!].
>>
>> By the way, Kit emailed me privately to gloat that his solution to this problem was 26 times more efficient than mine.
>
> On Apr 22, 2012, at 7:38 PM, Nick Cox wrote:
>
>>> You are right about your innermost thought on -findname- (SJ, SSC). See
>>>
>>> http://www.stata.com/statalist/archive/2012-04/msg00193.html
>>>
>>> The -any()- and -all()- options were intended to let users stipulate
>>> conditions about the values of variables, but you can use it as a way
>>> of stipulating conditions about their names.
>>>
>>> The condition that upper("<char>") == "<char>" is also satisfied by
>>> the underscore _ which can begin variable names.
>
> On Sun, Apr 22, 2012 at 10:41 PM, Eric Booth <[email protected]> wrote:
>
>>>> I don't think -findname- has the ability to select on variable case (that I could find anyways ((I thought I remembered Nick Cox commenting about this in an earlier thread, but I couldnt find it - or I'm imagining it))) ).
>>>>
>>>> Here's a one way to do it:
>>>>
>>>> *************!
>>>> sysuse auto, clear
>>>> rename mpg headroom, upper
>>>> **
>>>> foreach a in `c(ALPHA)' {
>>>> cap ds `a'*
>>>> loc list `"`list' `r(varlist)' "'
>>>> }
>>>> di `"`list'"' //check this
>>>> drop `list'
>>>> *************!
>>>>
>
> On Apr 22, 2012, at 4:14 PM, Janet Hill wrote:
>
> I am importing a large dataset and, following various data
> manipulations, I generate new variables that have lower case names. To
> clean the dataset I need to delete all variables that start with an
> upper case letter. I can see the names in ds or findname (from SSC)
> but I can't work out how to select these names for deletion. I would
> be grateful for any advice on this. I am using Stata 12.
>
> *
> * 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/
>
>
> *
> * 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/
*
* 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/