Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Shittu, Aminu" <ameen_vet@yahoo.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Generating new variable with new values from the old one |
Date | Wed, 5 Sep 2012 09:55:37 -0700 (PDT) |
Dear all, Thanks very much! The following works for me: gen agecat=age_category replace agecat="UNKNOWN" if agecat=="NA" replace agecat="UNKNOWN" if agecat=="NONE" replace agecat="UNKNOWN" if agecat=="OTHER" Regards, Aminu. ________________________________ From: Richard Goldstein <richgold@ix.netcom.com> To: statalist@hsphsun2.harvard.edu Sent: Wednesday, September 5, 2012 4:21:53 PM Subject: Re: st: Generating new variable with new values from the old one when you type "gen agecat=." you are setting up a numeric variable (be careful of the typo in your code below) however, "adult" is not a number further if the entries in age_category are in caps, your statement needs to be in caps also you are probably better off by using (1) encode to get a new numeric variable and then (2) recode or a replace to change the values you want to change rich On 9/5/12 11:11 AM, Shittu, Aminu wrote: > Dear Statalisters, > > 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. I used the following initially but the response is always "adult not found," is there a way I can do it in Stata? Here are my command lines: > > gen agacat=. > replace agecat=adult if age_category==adult > > Please note all the entries in var "age_category" are in CAPS. > > Thanks > > Aminu * * 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/ ; * * 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/