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


From   Maarten Buis <[email protected]>
To   [email protected]
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
"unknown"
"na"
"none"
"adult"
"young"
end

// 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
list, nolabel
*---------------- 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
WZB
Reichpietschufer 50
10785 Berlin
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index