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: Destringing variable |
Date | Sat, 12 May 2012 15:14:30 -0700 (PDT) |
Thanks both - Nick and Richard. Aminu ________________________________ From: Nick Cox <njcoxstata@gmail.com> To: statalist@hsphsun2.harvard.edu Sent: Saturday, May 12, 2012 7:57:49 PM Subject: Re: st: Destringing variable I infer from this that Aminu has a string variable -month- with values like "JANUARY" and wants a corresponding numeric variable with values like 1. If so, then -destring- has no role in this conversion. Aminu needs to define a set of labels, e.g. label def MONTH 1 "JANUARY" ... 12 "DECEMBER" (clearly you need to complete the set where I have typed ...) and then use -encode-: encode month, gen(nmonth) label(MONTH) Nick On Sat, May 12, 2012 at 6:10 PM, Richard Goldstein <richgold@ix.netcom.com> wrote: > there are a number of typos in your command; first, you have generated > month2 and set it to 0 for everyone; it therefor can not possibly equal > "january" regardless of case > > second, after changing the variable being referred to in your "if" > statement (e.g., to month), note that strings must be (a) in > doublequotes and (b) in the same case in your command as they are in the > data > > why not use the -destring- command? On 5/12/12 1:04 PM, Shittu, Aminu wrote: >> I am trying to destring the var name -month- using the following command but > the response was "january not found." Was it due to error in writing the > command > or because all months (JANUARY to DECEMBER) were entered in UPPERCASE > letter? >> >> >> gen month2=0 >> replace month2=1 if (month2==january) >> -january not found- >> * * 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/