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]

Re: st: Assigning values from a list


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Assigning values from a list
Date   Fri, 21 May 2010 10:15:47 -0400

Nick--
Thanks for re-emphasizing the integer comparison point.  Also, I was
assuming the list of codes might be quite long (possibly 255+ codes),
but the list of variables that could hold those codes is small (maybe
more than 4, but fewer than 255), which is why I reversed the
comparison shown below.  I.e. I prefer stepping through

inlist(`code',var1,var2, etc.)

to a single long

inlist(var1,`codelist')|inlist(var2,`codelist')|etc.

since my approach is robust to having a codelist with 255 or more
elements. Also, it's far from clear to me that you would want to
restrict to nonmissing varX, since a missing value might indicate no
diagnosis, or no third diagnosis, or what have you.  Perhaps the
original poster can clarify what var3<. and var4==. would mean.

On Fri, May 21, 2010 at 7:23 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Maarten's code can be tweaked further.
>
> As Austin Nichols emphasised testing decimals for equality is a recipe for difficulty if not disaster. Work with integers instead
>
> In addition the | operator can be used to streamline
>
> gen byte virus = (                        ///
>                 inlist(var1, `list') +   ///
>                 inlist(var2, `list') +   ///
>                 inlist(var3, `list') +   ///
>                 inlist(var4, `list')     ///
>                 ) > 1                    ///
>                 if !missing(var1, var2, var3, var4)
>
> to
>
> gen byte virus = inlist(var1, `list') |   ///
>                 inlist(var2, `list') |   ///
>                 inlist(var3, `list') |   ///
>                 inlist(var4, `list')     ///
>                 if !missing(var1, var2, var3, var4)
>
> (I guess > 1 was a typo for > 0.)
>
> Nick
> n.j.cox@durham.ac.uk
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index