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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: 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   Re: st: Encoding string variables: the one var that has no variance encodes differently than the rest
Date   Thu, 9 May 2013 09:08:10 -0400

Thank you so much Nick!

Best,

David

On Tue, May 7, 2013 at 7:01 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> What you did was -encode- your variables separately; thus there is no
> necessary correspondence between the value labels assigned to each.
>
> Note that -encode- does have a -label()- option that lets you specify
> a particular set of value labels to be used. That is official Stata's
> way of allowing you to insist on consistent label sets.
>
> In particular, -encode- orders distinct values alphabetically, and in
> your last case there was only one distinct value and it was assigned
> value 1.
>
> I wrote a program -multencode- (SSC) which encodes a set of variables jointly.
>
> Typing -findit encode- within Stata would have pointed you to this.
>
> Nick
> njcoxstata@gmail.com
>
>
> On 7 May 2013 23:50, David de Jong <davidcdejong@gmail.com> wrote:
>
>> 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.
> *
> *   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/



-- 
~
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