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]

From |
marietherese.kelly@flinders.edu.au |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Assigning values from a list |

Date |
Fri, 21 May 2010 20:12:16 +0930 |

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, <marietherese.kelly@flinders.edu.au> 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/

**Follow-Ups**:**AW: st: Assigning values from a list***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**RE: st: Assigning values from a list***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: extract hours, minutes and seconds from date** - Next by Date:
**RE: st: AW: Doubt on the exexcution of a do file?** - Previous by thread:
**st: RE: Assigning values from a list** - Next by thread:
**RE: st: Assigning values from a list** - Index(es):