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: Use varlabel in expressions


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Use varlabel in expressions
Date   Sat, 24 Mar 2012 08:08:14 +0000

Joerg and also Sven Trelle are naturally correct.

Note that -ds- (and also -findname- (SSC, SJ))  implement the loop
over variables for you.

With -ds-

ds, has(varl "na-") detail
drop `r(varlist)'

With -findname-

findname, varlabeltext(na-) detail
drop `r(varlist)'

A difference here over the approach below is that you get to see the
variables' details before you -drop- them.

Nick

On Fri, Mar 23, 2012 at 7:39 PM, Joerg Luedicke
<[email protected]> wrote:
> Perhaps consider the following example. It is assumed that "na-"
> is always "na-" exactly (e.g., not "na -" or "n a-") and that it will always
> affect the exact first 3 columns of the variable label. If these
> assumptions do not hold, something else may be needed,
> depending on the exact problem.
>
> *---------------------------
> sysuse auto, clear
> gen x=1
> label var x "na-whatever"
>
> foreach v of varlist _all {
>        loc lab : variable label `v'
>        if substr("`lab'", 1, 3)=="na-" {
>                drop `v'
>        }
> }
> *---------------------------
>
> J.
>
>
>
> On Fri, Mar 23, 2012 at 11:53 AM, Marcelo Lafleur <[email protected]> wrote:
>> I've had not luck with this and all references in this list point to use
>> of value labels.
>>
>> My question is simple: How, if possible, to drop variables based on a
>> prefix in their varlabels?
>>
>> Examples:
>>
>> . des  mv218 mv225 mv245 mv246
>>
>> variable name       value label      variable label
>> ----------------------------------------------------------------------------
>> mv218                                           number of living children
>> mv225                  mv225            na-current pregnancy wanted
>> mv245                                           women fathered children
>> with
>> mv246                   mv246           na-married to mother when first
>> child was born
>>
>> (I edited the output a bit)
>>
>>
>> I want to drop mv225 and mv246 by testing that the variable label starts
>> with "na-"
>>
>> Having hundreds of variables in each dataset, it would be impractical to
>> do by hand.

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