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: Concatenating two numerical variables with labels


From   Tim Evans <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Concatenating two numerical variables with labels
Date   Mon, 6 Feb 2012 15:43:35 +0000

Nick, Maarten,

Once again, thank you for deciphering exactly what I needed and providing a solution.

Best wishes
Tim


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 06 February 2012 13:16
To: [email protected]
Subject: Re: st: Concatenating two numerical variables with labels

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/

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.


*
*   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/


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