Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Jonas Krüger <jonas.krueger.h71@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: converting string to numerals |
Date | Wed, 20 Nov 2013 20:48:50 +0100 |
Did you thought about regexr? should be pretty easy to find patterns and replace them. http://www.stata.com/help.cgi?regexm() On Wed, Nov 20, 2013 at 8:15 PM, Nick Cox <njcoxstata@gmail.com> wrote: > -encode- does not understand English in the way that you do. My guess > is that it did not encode your values randomly at all, but as > > 1 agree > 2 disagree > 3 neither ... > 4 strongly agree > 5 strongly disagree > > which is an alphabetical order. > > What you need is covered by the syntax and documentation of -encode-, > namely to define your labels in advance: > > label define mylabels -2 "strongly disagree" <and so forth> > encode var, gen(var1) label(mylabels) > > while at the same time using more evocative variable names. > > Nick > njcoxstata@gmail.com > > > On 20 November 2013 19:07, ramesh <ramesh.ghim@gmail.com> wrote: > > I have a very basic question about coding string variables. My variable is >> expressed as strongly disagree, disagree, neither disagree nor agree, agree, >> and strongly agree. I want to code them -2 if strongly disagree, -1 if >> disagree, 0 if neither disagree nor agree, 1 if agree, and 2 if strongly >> agree. I used encode(var), gen(var1), but it coded the scales randomly. Is >> there any direct way to preserve the order in data coding? > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/