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: Looping Variable Labels Define


From   Nick Cox <[email protected]>
To   [email protected]
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
<[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index