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 results in false match - merge/joinby


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: encode results in false match - merge/joinby
Date   Fri, 11 Feb 2011 00:49:53 +0000

Not quite. Stata by default uses alphabetical order of strings encountered.

. clear

. set obs 5
obs was 0, now 5

. input str1 mystring

      mystring
  1. z
  2. y
  3. x
  4. w
  5. v

. encode mystring, gen(mynum)

. l

     +------------------+
     | mystring   mynum |
     |------------------|
  1. |        z       z |
  2. |        y       y |
  3. |        x       x |
  4. |        w       w |
  5. |        v       v |
     +------------------+

. l, nola

     +------------------+
     | mystring   mynum |
     |------------------|
  1. |        z       5 |
  2. |        y       4 |
  3. |        x       3 |
  4. |        w       2 |
  5. |        v       1 |
     +------------------+

For ways of encoding otherwise, see Roger Newson's -sencode- (SSC, SJ)
or my -labmask- (SSC, SJ).

Nick

On Thu, Feb 10, 2011 at 9:32 PM, Eric Booth <[email protected]>
wrote in an otherwise clear and useful explanation:

> When you encode a string variable, Stata will assign values starting at 1 for the first obs (unless you use -encode-'s label option to change this).
*
*   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