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: How to rename value label names to match variable names?


From   Anna Reimondos <[email protected]>
To   [email protected]
Subject   Re: st: How to rename value label names to match variable names?
Date   Mon, 17 May 2010 20:37:54 +1000

Excellent, thank you for that extra tip Martin.
I  just tested findname (e.g  by defining and attaching a value label
of -3 "Refused" for all variables that have a value of -3)  and it
worked like a treat. Definitely a keeper for me.

On Mon, May 17, 2010 at 5:21 PM, Martin Weiss <[email protected]> wrote:
>
> <>
>
>
> " The ds, has(vallabel)
> is also good to know"
>
>
> Also note NJC`s recent -ssc d findname- then!
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von Anna Reimondos
> Gesendet: Montag, 17. Mai 2010 01:59
> An: [email protected]
> Betreff: Re: st: How to rename value label names to match variable names?
>
> Thank you all for your further suggestions.
> With the labmask, I had not realised that the label values were
> dropped, so yes I would definitely need to use the decode option.
>
> The labvalclone was another program I was not aware of and testing it
> on my data it worked perfectly. The ds, has(vallabel)
> is also good to know because initially when if was using "foreach var
> of varlist _all { " to loop through the variables and was consequently
> creating labels on variables such as ID or weight which did not
> initially have labels.
>
> Thank you again- as always I have learnt a lot.
>
> Anna
>
>
> On Sun, May 16, 2010 at 7:40 PM, Martin Weiss <[email protected]> wrote:
>>
>> <>
>>
>> You can also use NJC`s -labvalclone-, in combination with the -h extended_fcn-s:
>>
>>
>> ***********
>> sysuse nlsw88, clear
>>
>> //see initial state
>> d
>>
>> capt which labvalclone
>> if _rc ssc inst labutil
>>
>> //get all vars with value labels
>> ds, has(vallabel)
>>
>> //cycle thru list and change val label name
>> foreach var of varlist `r(varlist)'{
>>        labvalclone "`:val lab `var''" "`var'"
>>        la val `var' `var'
>> }
>>
>> //see changes
>> d
>>
>> //see whether labels are intact
>> ta race
>> ta occupation
>> ***********
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf Of Tirthankar Chakravarty
>> Sent: Sonntag, 16. Mai 2010 11:13
>> To: [email protected]
>> Subject: Re: st: How to rename value label names to match variable names?
>>
>> Martin,
>>
>> Well-spotted. A simple fix is to use the -labmask, decode- option.
>> ***********
>> sysuse auto
>> des
>> labmask foreign, values(foreign) decode
>> des
>> tab foreign
>> la li
>> ***********
>>
>> T
>>
>> 2010/5/16 Martin Weiss <[email protected]>:
>>>
>>> <>
>>>
>>> But T, after your code the name of the -value label- has been changed, but the labels ("domestic", "foreign") are gone as well. Anna declared herself satisfied, but I am not sure whether this is what she really wants.
>>>
>>>
>>> ***********
>>> sysuse auto
>>> des
>>> labmask foreign, values(foreign)
>>> des
>>> tab foreign
>>> la li
>>> ***********
>>>
>>>
>>> HTH
>>> Martin
>>>
>>>
>>> -----Original Message-----
>>> From: [email protected] [mailto:[email protected]] On Behalf Of Tirthankar Chakravarty
>>> Sent: Sonntag, 16. Mai 2010 08:45
>>> To: [email protected]
>>> Subject: Re: st: How to rename value label names to match variable names?
>>>
>>> You can easily change the name of the value label of a variable after
>>> you have renamed the variable, to match the new variable name, using
>>> Nick Cox's -labmask- utility, part of the -labutil- package (SSC):
>>> ***********************************
>>> sysuse auto
>>> des
>>> labmask foreign, values(foreign)
>>> des
>>> ***********************************
>>>
>>> T
>>>
>>>
>>> 2010/5/16 Anna Reimondos <[email protected]>:
>>>> Hello,
>>>> And thank you both for your suggestions.  I find it a bit hard to
>>>> articulate problems sometimes when it comes to variable names, value
>>>> names and value labels so my question was perhaps not very clear.
>>>>
>>>> I would like to rename the name of the labels rather than the names of
>>>> the variables.
>>>>
>>>> For example
>>>> sysuse, auto
>>>> des
>>>>
>>>> *Here I would want the value label called 'origin' to change to be
>>>> called 'foreign' to match the name of the variable name it is attached
>>>> to.
>>>>
>>>> As Phillip pointed out this is not necessary thing do to, but I must
>>>> do this because I am cleaning a survey dataset that has very
>>>> particular rules about how the variable names and value labels are
>>>> defined and they have asked me to do this....
>>>>
>>>> Thanks,
>>>> Anna
>>>>
>>>>
>>>>
>>>>
>>>> On Sun, May 16, 2010 at 12:46 PM, Tim Wade <[email protected]> wrote:
>>>>> I'm not 100% certain what you are asking but if you want to relabel
>>>>> the newly generated variables so that the labels are the same as the
>>>>> new variable names, this should work:
>>>>>
>>>>>
>>>>> sysuse auto.dta, clear
>>>>> rename make make1
>>>>> rename price price1
>>>>> desc make1 price1
>>>>> foreach var of varlist make1 price1 {
>>>>> label variable `var' "`var'"
>>>>> }
>>>>> desc make1 price1
>>>>>
>>>>>
>>>>>              storage  display     value
>>>>> variable name   type   format      label      variable label
>>>>> ----------------------------------------------------------------------------------------------------------------------------------------------------------------
>>>>> make1           str18  %-18s                  make1
>>>>> price1          int    %8.0gc                 price1
>>>>>
>>>>>
>>>>> Tim
>>>>>
>>>>> On Sat, May 15, 2010 at 10:06 PM, Anna Reimondos <[email protected]> wrote:
>>>>>> Hello,
>>>>>> The following problem has me stumped.
>>>>>> I have a dataset with variables which have been labelled with value
>>>>>> labels. Currently the variables are names as "a1, a2, a3" etc, and  I
>>>>>> need to rename all my variables so that they are listed as "V1, V2,
>>>>>> V3" etc. This I can easily do. The problem is that I also need to
>>>>>> rename all the value label names to match the new variable names.
>>>>>>
>>>>>> For example, the current situation is:
>>>>>>
>>>>>> varname  label name
>>>>>> ------------------------------
>>>>>>
>>>>>> a1            a1
>>>>>> a2            a2
>>>>>> a3            yesno
>>>>>> a4            gender
>>>>>> ------------------------------
>>>>>>
>>>>>> What I need to have is:
>>>>>>
>>>>>> varname  label name
>>>>>> ------------------------------
>>>>>>
>>>>>> V1            V1
>>>>>> V2            V2
>>>>>> V3            V3
>>>>>> V4            V4
>>>>>> ------------------------------
>>>>>>
>>>>>>
>>>>>> Does anyone have any suggestions on how I can rename the label names
>>>>>> to match the variable names? I found a number of similar questions on
>>>>>> Statalist but most seem to be going the other way (i.e from renaming
>>>>>> variables to match the label names)
>>>>>>
>>>>>> Thanks heaps
>>>>>> Anna
>>>>>>
>>>>>> *
>>>>>> *   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/
>>>>
>>>
>>>
>>>
>>> --
>>> To every ω-consistent recursive class κ of formulae there correspond
>>> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
>>> belongs to Flg(κ) (where v is the free variable of r).
>>>
>>> *
>>> *   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/
>>>
>>
>>
>>
>> --
>> To every ω-consistent recursive class κ of formulae there correspond
>> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
>> belongs to Flg(κ) (where v is the free variable of r).
>>
>> *
>> *   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/
>
>
> *
> *   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index