Statalist


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

RE: st: STATA loop terminating over missing variables


From   "Kieran McCaul" <[email protected]>
To   <[email protected]>
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: [email protected]
http://myprofile.cos.com/mccaul 
_______________________________________________
The fact that no one understands you doesn't make you an artist.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Akshay
SHanker
Sent: Thursday, 4 December 2008 10:25 AM
To: [email protected]
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" <[email protected]> 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 
> [email protected] 
> 
> Maarten buis
> 
> --- Akshay SHanker <[email protected]> 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/



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