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: Selecting variables based on variable labels
From
Austin Nichols <[email protected]>
To
[email protected]
Subject
Re: st: Selecting variables based on variable labels
Date
Fri, 7 Sep 2012 23:22:41 -0400
Mitch Downey <[email protected]>:
Or just run through vars and selectively rename:
foreach v of var * {
loc s=strpos("TYPE OF RESIDENCE R IS LIVING ")
if `s'>0 ren `v' res`=substr("`:var la `v''",`s'+32,2)
}
On Fri, Sep 7, 2012 at 9:25 PM, Nick Cox <[email protected]> wrote:
> Look at -ds- (official) or -findname- (SJ). The latter is more versatile.
>
> Example:
>
> findname, varlabeltext(TYPE OF RESIDENCE*)
>
> Nick
>
> On Sat, Sep 8, 2012 at 2:09 AM, Mitch Downey <[email protected]> wrote:
>> Hello,
>>
>> I'm using the National Longitudinal Survey of Youth. There are several
>> series of variables where the same question was asked over multiple years.
>> E.g.,
>>
>> R0188000 TYPE OF RESIDENCE R IS LIVING 79
>> R0402800 TYPE OF RESIDENCE R IS LIVING 80
>> R0612100 TYPE OF RESIDENCE R IS LIVING 81
>> R0828400 TYPE OF RESIDENCE R IS LIVING 82
>> R1075700 TYPE OF RESIDENCE R IS LIVING 83
>> R1451400 TYPE OF RESIDENCE R IS LIVING 84
>> R1798600 TYPE OF RESIDENCE R IS LIVING 85
>> R2160200 TYPE OF RESIDENCE R IS LIVING 86
>> R2369100 TYPE OF RESIDENCE R IS LIVING 87
>>
>> where R0188000 is the variable name and TYPE OF RESIDENCE R IS LIVING 79
>> is the variable label. Unfortunately, the variable names are random. This
>> makes it impossible to select a group of variables using res* (for
>> instance) or res79-res87. The only way I can find this group of variables
>> is by typing
>> -- lookfor "TYPE OF RESIDENCE R IS LIVING" --
>>
>> I would like to identify a list of variables using the lookfor command and
>> either create a list or rename them in a sequential way. Is there a way to
>> do this? Can you build a variable list from lookfor results? My ultimate
>> goal is to make the dataset long format, so if anyone has and idea to
>> shortcut straight to that, I'm all ears.
*
* 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/