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


From   Tim Evans <Tim.Evans@wmciu.nhs.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 06 February 2012 13:16
To: statalist@hsphsun2.harvard.edu
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 <maartenlbuis@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index