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: Assigning values from a list


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Assigning values from a list
Date   Thu, 20 May 2010 21:14:35 -0400

I doubt that code does what you want; in particular, the second
through fourth commands do nothing at all (the first command never
produces a missing value so the if condition is never satisfied).  You
also may run into precision problems; I recommend multiplying your
codes by 100 so they are all integers. Try these two methods to see
which you like better:

clear all
set seed 123
set obs 10000
forv i=1/4 {
 g int var`i'=round(uniform()*3000+5000)
 }
g byte  a=var1==5320|var1==5442|var1==5443|var1==7600|var1==7690
replace a=var2==5320|var2==5442|var2==5443|var2==7600|var2==7690 if a==0
replace a=var3==5320|var3==5442|var3==5443|var3==7600|var3==7690 if a==0
replace a=var4==5320|var4==5442|var4==5443|var4==7600|var4==7690 if a==0
g byte b=0
foreach c in 5320 5442 5443 7600 7690 {
 replace b=1 if inlist(`c',var1,var2,var3,var4)
 }
ta a b

On Thu, May 20, 2010 at 8:49 PM,  <[email protected]> wrote:
> Hi All,
> I was wondering if someone would help me with a basic programming questions.
>
> I have 4 variables that are basically DSM codes and I would like to search
> through those codes.
>
> I would like to define lists of diseases and then pick which cases have those
> diseases
>
> So instead of writing
>
> gen virus=(var1==53.20) |(var1==54.42) |(var1==54.43) | /*
> */ (var1==76.00) |(var1==76.90)
>
> replace virus=((var2==53.20) |(var2==54.42) |(var2==54.43) | /*
> */ (var2==76.00) |(var2==76.90)) if virus==.
>
> replace virus=((var3==53.20) |(var3==54.42) |(var3==54.43) | /*
> */ (var3==76.00) |(var3==76.90)) if virus==.
>
> replace virus=((var4==53.20) |(var4==54.42) |(var4==54.43) | /*
> */ (var4==76.00) |(var4==76.90)) if virus==.
>
>
> Repeat for several other categories of diseases - ends up with very long and
> confusing code.
>
>
> Is there a way of defining a list eg virus={53.20, 54.42, 54.43, 76.00, 76.90}
>
> and checking to see whether var1-4 have values in the list?
>
> Thanks in advance.
>
*
*   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