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: Generating new variable with new values from the old one

From   Maarten Buis <>
Subject   Re: st: Generating new variable with new values from the old one
Date   Wed, 5 Sep 2012 17:28:25 +0200

On Wed, Sep 5, 2012 at 5:11 PM, Shittu, Aminu wrote:
> I am interested in generating a new "agecat" variable and then rename every value in the original "age_category" named "NA," "NONE" and "UNKNOWN" to mean the same, I will call all of the as "NONE." However, I am interested in keeping those values such as "ADULT," and "YOUNG" to mean the same as in the original "age_category" variable.

*--------------- begin example -------------
// create some example data
clear all
input str7 agecat

// get what you ask for
gen str7 agecat2 = agecat
replace agecat2 = "none" ///
    if inlist(agecat2,"unknown","na")

// get what you should have asked for
label define agecat3 1 "adult"    ///
                     2 "young"    ///
                     3 "none"     ///
                     4 "na"       ///
                     5 "unknown"
encode agecat, gen(agecat3) label(agecat3)
mvdecode agecat3, mv(3 4 5)

// see the results
list, nolabel
*---------------- end example --------------
(For more on examples I sent to the Statalist see: )

Hope this helps,
Maarten L. Buis
Reichpietschufer 50
10785 Berlin

*   For searches and help try:

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