Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: highest scalar of a matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: highest scalar of a matrix
Date   Fri, 6 Jun 2003 15:05:04 +0100

Joao Pedro W. de Azevedo [mailto:[email protected]] 

> > I'm looking for a function or a routine in Stata7 which would 
> > give me the
> > highest scalar of a matrix [n x 1].
> > For example if I have a matrix such as  B[6,1]=(1\2\3\4\5\6) 
> > this function
> > should give me a scalar or local with the value 6.

Nick Winter
 
> I imagine Nick Cox has done this already, but if not, the following
> routine will do it:
> 
> program define matmax, rclass
>   version 7
>   args M
>   tempname val
>   local rows = rowsof(`M')
>   local cols = colsof(`M')
>   scalar `val' = `M'[1,1]
>   local mr 1
>   local mc 1
>   forval r=1/`rows' {
>     forval c=1/`cols' {
>       if `M'[`r',`c']>`val' {
>         scalar `val'=`M'[`r',`c']
>         local mr `r'
>         local mc `c'
>       }
>     }
>   }
>   di
>   di "{txt}Largest value is 
> {res}`M'{txt}[{res}`mr'{txt},{res}`mc'{txt}]
> = {res}" `val'
>   return scalar largest=`val'
> end

I didn't need to; there is a -matmax- in 
Jeroen Weesie's -matfunc- package. 

More importantly, 

. search matrix 

or 

. findit matrix 

finds extras. 

Nick 
[email protected] 
*
*   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