Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Encoding string variables: the one var that has no variance encodes differently than the rest


From   David de Jong <davidcdejong@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Encoding string variables: the one var that has no variance encodes differently than the rest
Date   Tue, 7 May 2013 18:50:00 -0400

Hi all,

New Stata (12.1) user here, and I'm a first time poster. I hope
someone might be able to help with something. I've searched the web,
help files, and archives to no avail.

I tried to encode a series of variables (type str5), with the following:

qui foreach v of var var1-var10 {
    encode `v', generate(`v'_encoded)
}

All of the variables seemed to convert as they should (to type long),
except for the only variable that also happened to have no variance:
all cases in the original variable had the string "TRUE." Instead of
converting to a "2" as did all instances of "TRUE" in the other
variables, it was converted to "1."

The same problem appears when I try it like this:

encode var1, generate(var1_encoded)

I'd be very grateful for any insights into what might be going on.

D. de Jong

~
Department of Clinical and Social Sciences in Psychology
University of Rochester
498c Meliora Hall
Rochester, NY 14627
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index