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: adding variable name to value label


From   "Roger B. Newson" <[email protected]>
To   [email protected]
Subject   Re: st: adding variable name to value label
Date   Thu, 26 Sep 2013 18:11:27 +0100

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/


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