Statalist The Stata Listserver


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

RE: Re: st: How to loop over non-integers?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: Re: st: How to loop over non-integers?
Date   Mon, 11 Jun 2007 11:23:26 +0100

The key point is that the Stata function -min()- requires
a list of arguments and returns the minimum of that list. 
Each argument must be a scalar. This is (almost) explicit in the help. 

Patrick wants a function that looks inside a variable
and returns the minimum. There is no such function in 
Stata. (Mata is a different story, as far as vectors
and matrices are concerned.) 

Scott's first solution is one way to do it. 

I think his second solution is a bit mangled. 
It won't work as posted. 

The spirit of his idea I take to be this: 

gen int obs = _n 
su W, meanonly 
su obs if W == r(min), meanonly 
scalar alpha_hat = alpha[`r(min)'] 

The first solution is thus preferable, 
in my view, as more direct. 

Nick 
[email protected] 

Scott Merryman
 
> On 6/10/07, [email protected] <[email protected]> wrote:
> <snip>
> > The code below nearly gets there. From the plot of the Wald 
> statistic
> > against alpha, the smallest element of alpha (on this 
> coarse grid) is
> > alpha_hat = 29. I could
> >
> > not work out how to use the minimum function to extract 
> this value. I tried
> > things like --- scalar alpha_hat = min(alpha) --- but that 
> won't work.
> > What's the trick
> <snip>
> 
> You could try:
> 
> sort  W
> scalar alpha_hat = alpha[1]
> 
> or
> 
> sum W, meanonly
> if W == r(min) {
> 	 scalar alpha_hat = alpha
>  }

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



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