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

st: RE: highest scalar of a matrix


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: highest scalar of a matrix
Date   Fri, 6 Jun 2003 09:38:49 -0400

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
			


-----------------------------------------------------------
 Nicholas Winter, Ph.D.                     P 202.939.5343
 Policy Studies Associates                  F 202.939.5732
 1718 Connecticut Avenue, NW     [email protected]
 Washington, DC 20009-1148           www.policystudies.com
----------------------------------------------------------- 

> -----Original Message-----
> From: Joao Pedro W. de Azevedo [mailto:[email protected]] 
> Sent: Friday, June 06, 2003 5:59 AM
> To: [email protected]
> Subject: st: highest scalar of a matrix
> 
> 
> Hello all,
> 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.
> Any help would be much appreciated.
> Cheers,
> JP/
> 
> 
> 
> 
> 
> 
> *
> *   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/
> 

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