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: Encode string variables without following the default alphanumeric ordering


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Encode string variables without following the default alphanumeric ordering
Date   Mon, 9 Sep 2013 17:07:38 +0100

-sencode- is from SJ.

Your criticisms seem unjust. -encode- uses alphabetical order by
default and -sencode- uses order of occurrence in dataset by default.
Evidently you want neither, so you need to do something else. You need
to define a set of value labels explicitly, then -encode- in a loop.

Alternatively, -multencode- (SSC) will ensure _consistent_ labelling,
but not necessarily the right order as you see it.

Nick
[email protected]


On 9 September 2013 16:50, Adama Konseiga <[email protected]> wrote:
> Dear Statlisters
>
> I am dealing with a questionnaire where one question leads to rating
> an activity on a scale from 0 to 10.
>
> There are about 25 variables from that question which are currently in
> a string format, including missing and text such as "0 - Activity not
> interesting at all".
>
> I engaged in automatizing the process of encoding the 25 variables
> into numeric. But neither -encode- nor super encode are doing the job
> properly.
> They are based on alphanumeric order of appearance of the string
> values, which leads to numeric values having completely different
> meanings accross the variables.
>
> Does anyone has some suggestions how to improve my following codes.
>
> -------
>
> Stata version: Stata 10.1
>
> u mydataset, clear
>
> /*
> tab activitym1, miss
>
> br activitym1
> egen tag=tag(activitym1)
>
> list activitym1 if tag
> ****Confirm that the order of apperance of string values are different
> in the 25 variables
> */
>
> foreach var of varlist activitym* {
> sencode `var', replace label(scores, replace)
>  }
> recode activitym1 (1=8) (2=5) (3=0) (4=6) (5=9) (6=2) (7=10) (8=7)
> (9=4) (10=3) (11=1)
> .....
> -----
>
> recode activitym4 (1=0) (2=2) (3=6) (4=7) (5=8) (6=5) (7=9) (8=10)
> (9=1) (10=3) (11=4)
>
>
> --
>
> Adama Konseiga
> *
> *   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index