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: adding variable name to value label
From
"Song, Lin" <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: adding variable name to value label
Date
Thu, 26 Sep 2013 18:14:14 +0000
Joe, David and Roger, Thank you so much for your help.
I modified David's program and made it work. Originally, the program added the variable label to the value label instead of the variable name.
Here is what the program looks like after modification:
sysuse voter, clear
foreach v of varlist candidat-pop{
label var `v' "`v'" /*changing the variable label to the variable name*/
levelsof `v', local(levs)
foreach l of local levs {
label define `:value label `v'' `l' `"`:var lab `v''-`:lab (`v') `l''"', modify
}
}
I will study the programs by Joe and Roger too.
Thanks again.
Lin
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Roger B. Newson
Sent: Thursday, September 26, 2013 10:11 AM
To: [email protected]
Subject: Re: st: adding variable name to value label
This looks like a possible job for -sencode- and -sdecode-, which you can download from SSC. If the variables are all numbered and prefixed with Q, and the value labels have the same names as the variable and have, then your program code might be:
tempvar tempfac;
foreach Y of var Q* {;
gene tempfac=`Y';
sdecode `Y', replace;
lab drop `Y';
replace `Y'=`"`Y'-"'+`Y';
sencode `Y', gsort(tempfac) replace;
drop tempfac;
};
describe Q*;
The -sencode- and -sdecode- packages are "super" versions of -encode- and -decode-, and are discussed in Newson (2013).
I hope this helps.
Best wishes
Roger
References
Newson RB. Creating factor variables in resultssets and other datasets.
Presented at the 19th UK Stata User Meeting, 12-13 September, 2013.
Download from
http://ideas.repec.org/p/boc/usug13/01.html
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group National Heart and Lung Institute Imperial College London Royal Brompton Campus Room 33, Emmanuel Kaye Building 1B Manresa Road London SW3 6LR UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
Opinions expressed are those of the author, not of the institution.
On 26/09/2013 17:47, Song, Lin wrote:
> Hi Steve,
>
> Thanks for your reply.
>
> Since I have over 100 variables, I was looking for a simple program that can add the variable name to the value label automatically.
>
> Lin
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Steve
> Nakoneshny
> Sent: Thursday, September 26, 2013 9:43 AM
> To: [email protected]
> Subject: Re: st: adding variable name to value label
>
> Lin,
>
> From -h label-:
>
> Define value label
>
> label define lblname # "label" [# "label" ...] [, add modify
> replace nofix]
>
> The -modify- option should be what you're after.
>
> Steve
>
>
> On 2013-09-26, at 10:37 AM, Song, Lin wrote:
>
>> Hi Stata users:
>>
>> I'd like to add variable names to value labels. For example, I have the following variables:
>>
>> Q1: 1=yes, 2=no
>> Q2: 1=male, 2=female
>>
>> I'd like to convert the value labels to something like below:
>>
>> Q1: 1="Q1-yes" 2="Q1-no"
>> Q2: 1="Q2-male" 2 "Q2-female"
>>
>> This is for matching two files generated by tabout. Because of zero count for certain values, the two files cannot be matched sequentially.
>>
>> Is there a simple way to do this?
>>
>> Thanks a lot.
>>
>> Lin
>> Lin Song
>> Epidemiologist
>> Public Health - Seattle & King County
>> (206) 263-8773
>>
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/