[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Kieran McCaul" <kamccaul@meddent.uwa.edu.au> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: STATA loop terminating over missing variables |

Date |
Thu, 4 Dec 2008 11:19:25 +0900 |

I don't think this would work anyway, even without the problem of missing data because, on each pass through the loop, there is only every one variable in the -min- function. You appear to want the minimum of up to 13 variables, is that correct? If that's the case, you don't need the m loop. The -egen- function -rowmin- will give you the minimum, excluding missing values. Try: forvalues i =1/49{ forvalues j=1/13{ forvalues k=1/49{ capture egen mindiff`i'_`j'__x_`k' = rowmin(diff`i'_`j'__*_`k') } } } ______________________________________________ Kieran McCaul MPH PhD WA Centre for Health & Ageing (M573) University of Western Australia Level 6, Ainslie House 48 Murray St Perth 6000 Phone: (08) 9224-2140 Fax: (08) 9224 8009 email: kamccaul@meddent.uwa.edu.au http://myprofile.cos.com/mccaul _______________________________________________ The fact that no one understands you doesn't make you an artist. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Akshay SHanker Sent: Thursday, 4 December 2008 10:25 AM To: statalist@hsphsun2.harvard.edu Subject: Re: st: STATA loop terminating over missing variables Thanks for this, this seems to work. I have an extension to the question, suppose i have the following loop: forvalues i =1/49{ forvalues j=1/13{ forvalues k=1/49{ forvalues m =1/13{ capture gen mindiff`i'_`j'__x_`k' = min(capture diff`i'_`j'__`m'_`k') } } } } I am trying to get the min of diff for a particular i,j and k over a list of m. Now again not all diff`i'_`j'__`m'_`k' exist, so while the capture allows the loop to keep running, the min function does not work unless all the specified variables exist. Is there any way around this? I could just generate missing vars for every diff`i'_`j'__`m'_`k' but that would be about .5. million vars - not possible. Thanks again, this is very helpful! Akshay On 2/12/08 1:15 AM, "Nick Cox" <n.j.cox@durham.ac.uk> wrote: > The original question seems backwards. The purpose of the loop as > written is to create (e.g.) mindiff1_2 from mindiff1 and mindiff_2, so > that far from being a problem, the prior non-existence of mindiff1_2 is > expected. Perhaps the questioner meant that some of the > mindiff1-mindiff15 may not exist, in which case a better syntax is (as > indicated by Maarten) > > forval i = 1/15 { > forval j = 1/15 { > capture gen mindiff`i'_`j' = mindiff`i' - mindiff`j' > } > } > > Note correction of typo ``i' to `i'. > > Nick > n.j.cox@durham.ac.uk > > Maarten buis > > --- Akshay SHanker <ashanker@optusnet.com.au> wrote: >> I am running the following simple loop which i need some help with: >> >> forvalues i =1/15 { >> forvalues j=1/15{ >> gen mindiff`i'_`j' = mindiff``i' - mindiff`j' >> } >> } >> >> The problem is that not all combinations of i and j exist , so for >> example mindiff1_2 may not exist. Everytime the loop goes over such a >> variable, the loop terminates and thus stops running the loop over >> all consecutive variables which may exist. How do i stop the loop >> from terminating? > > see: -help capture- > > > * > * 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/ * * 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/

**References**:**Re: st: STATA loop terminating over missing variables***From:*Akshay SHanker <ashanker@optusnet.com.au>

- Prev by Date:
**Re: st: Video from multiple graph exports** - Next by Date:
**Re: st: Video from multiple graph exports** - Previous by thread:
**Re: st: STATA loop terminating over missing variables** - Next by thread:
**RE: st: STATA loop terminating over missing variables** - Index(es):

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