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]

AW: st: Assigning values from a list


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: Assigning values from a list
Date   Fri, 21 May 2010 12:54:18 +0200

<> 

" So I'm not sure what the random number generator is for?"


I think it was meant to provide example data to illustrate the code that
follows (hence the -set seed- to make the data replicable). You should omit
it and just from " g byte  a=var1==5320|var1..." onwards...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Freitag, 21. Mai 2010 12:42
An: [email protected]
Betreff: Re: st: Assigning values from a list

Thanks for your reply. You are right, I paraphrased the code and should have
put

if virus==0
instead of
if virus==.

I should have been clearer about what var1-4 are: they contain DSM9.0 codes,
so
can contain numbers 00.1 up to 999.99. I am trying to find diseases with the
codes 53.20, 54.42, 54.43, 76.00, 76.90 so I want to find which cases of
var1-4
contain these codes and assign that to a new variable virus.

So I'm not sure what the random number generator is for?


____________________________________________________________

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?
>
*
*   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/


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