Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Looping Variable Labels Define


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Looping Variable Labels Define
Date   Tue, 19 Feb 2013 08:07:59 +0000

Better to think in terms of -egen-'s -group()- function with the
-label- option. See also

SJ-7-4  dm0034  . . . Stata tip 52: Generating composite categorical variables
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/07   SJ 7(4):582--583                                 (no commands)
        tip on how to generate categorical variables using
        tostring and egen, group()

http://www.stata-journal.com/article.html?article=dm0034

egen code_outlet_topic=.group(code_outlet code_topic), label

Nick

On Tue, Feb 19, 2013 at 7:47 AM, Beatrice Benavidez
<beatricestata1711@gmail.com> wrote:

> I generated value labels for variables code_outlet and code_topic -
> code_outlet: 1 "Restaurant"     2 "Lounge" 3 "Bar" 4 "Minibar" 5 "Room Service"
>
> code_topic: 1 "Breakfast" 2 "Lunch" 3 "Afternoon Tea" 4 "Dinner" 5
> "Night" 6 "Minibar"
>
> I loop the creation of code_outlet_topic which is an amalgamation of
> code_outlet and code_topic-
>
> generate code_outlet_topic=.
>
> forvalues o=1/5{
>
> forvalues to=1/6{
>
> replace code_outlet_topic=`o'`to'0 if ( code_outlet==`o' | code_topic==`to')
>
> }
>
> }
>
>
>
> I would like to then have labels for code_outlet_topic such as:
>
> label define code_outlet topic 110 "Restaurant - Breakfast" 120
> "Restaurant - Lunch" ... 550 "Room Service - Night
>
> Would there be a way to do label the variable without having to do
> them one by one as it is composed purely of other variable labels and
> a dash?
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index