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   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Concatenating two numerical variables with labels
Date   Mon, 6 Feb 2012 14:11:36 +0100

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 )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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