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: Concatenating two numerical variables with labels
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Concatenating two numerical variables with labels
Date
Mon, 6 Feb 2012 13:15:35 +0000
Note that Maarten's code corresponds exactly to what -egen, concat()
decode p(" ")- does on your behalf.
Nick
On Mon, Feb 6, 2012 at 1:11 PM, Maarten Buis <[email protected]> wrote:
> On Mon, Feb 6, 2012 at 1:56 PM, Tim Evans wrote:
>> I'm trying to generate a new string variable in Stata 11.2 which contains the concatenated result of two numeric variables which have labels. What I want is the name from the label of each variable rather than 1 1 for instance.
>
> You can create string variables containing the contents of the labels
> instead of the numbers using -decode-, after that you can "add" them
> as you would any string variable:
>
> *----------- begin example ------------
> sysuse auto, clear
> label define rep78 1 "Poor" ///
> 2 "Fair" ///
> 3 "Average" ///
> 4 "Good" ///
> 5 "Excellent"
> label value rep78 rep78
>
> decode foreign, gen(str_for)
> decode rep78, gen(str_rep)
>
> gen conc = str_for + "_" + str_rep
> drop str_for str_rep
>
> list foreign rep78 conc in 1/10
> *------------ end example -------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
>
*
* 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/