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, 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 <>
To   "''" <>
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

-----Original Message-----
From: [] On Behalf Of Nick Cox
Sent: 06 February 2012 13:16
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.


On Mon, Feb 6, 2012 at 1:11 PM, Maarten Buis <> 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:
> )

*   For searches and help try:

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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index