[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Sander <avirulence@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Foreach when dealing with a list of observations |

Date |
Sat, 29 Mar 2008 18:00:18 +0100 |

Hi, I was wondering if it's possible to go over a list of observations with the foreach command. What I mean is the following: I have a data set with persons identified by a (for the person) unique number, called rin. However, when personal characteristics of the people in the data set changed, a new record was made with the same identification number. Now the problem is, that if certain characteristics for a person have changed (which gives a mutation code of 1 (mutcode==1)), I want that person out of the data set. What I tried is the following. The list of identification numbers that I want out of the dataset can be obtained by this command: list rin if mutcode==1 However, I don't want to run "drop if rin==number" by hand, since there are many observations. Therefore, I tried the following: foreach x of l rin if mutcode==1 { drop if rin=="`x'" } Which doesn't work, unfortunately. I tried some other commands as well: foreach x of rin if mutcode==1 { drop if rin=="`x'" } and foreach x in l rin if mutcode==1 { drop if rin=="`x'" } Which also don't work. I'm probably doing something very wrong here, but I would really appreciate it if someone could take the time to help me out with this. Thanks, Sander * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: Re: Foreach when dealing with a list of observations***From:*"Michael Blasnik" <michael.blasnik@verizon.net>

- Prev by Date:
**Re: st: median regressin and survey data!** - Next by Date:
**Re: st: Stepping through do file** - Previous by thread:
**st: regression with categorical covariate** - Next by thread:
**st: Re: Foreach when dealing with a list of observations** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |