*! 1.0.4 18Jun1997 Jeroen Weesie/ICS STB-39 dm49 program define matmax version 5.0 * scratch tempname A * parse input if "`*'" == "" { exit } parse "`*'", parse(",") local A0 "`1'" capt mat `A' = `A0' if _rc { di in red "`A0' is undefined or an illegal matrix expression" exit 198 } local nr = rowsof(`A') local nc = colsof(`A') mac shift local options "All(str) Column(str) Display Format(str) Row(str)" parse "`*'" if "`format'" != "" { local fmt "format(`format')" } * defaults if "`row'"=="" & "`column'"=="" & "`all'"=="" { local column "." } if "`row'"=="." { tempname Row local row "`Row'" local display "display" } if "`column'"=="." { tempname Col local column "`Col'" local display "display" } if "`all'"=="." { tempname All local all "`All'" local display "display" } * compute maxima if "`row'" != "" { * row maxima as a column vector mat `row' = `A'[1...,1] local j 2 while `j' <= `nc' { local i = 1 while `i' <= `nr' { mat `row'[`i',1] = max(`row'[`i',1],`A'[`i',`j']) local i = `i' + 1 } local j = `j' + 1 } if "`display'" != "" { di in gr _n "row-wise maxima of matrix `A0'[`nr',`nc']" mat list `row', noheader `fmt' } } if "`column'" != "" { * column maxima as a row vector mat `column' = `A'[1,1...] local i 2 while `i' <= `nr' { local j 1 while `j' <= `nc' { mat `column'[1,`j'] = max(`column'[1,`j'],`A'[`i',`j']) local j = `j' + 1 } local i = `i' + 1 } if "`display'" != "" { di in gr _n "column-wise maxima of matrix `A0'[`nr',`nc']" mat list `column', noheader `fmt' } } if "`all'" != "" { * maximum over all elements mat `all' = J(1,1,1E100) local i 1 while `i' <= `nr' { local j = 1 while `j' <= `nc' { mat `all'[1,1] = max(`all'[1,1],`A'[`i',`j']) local j = `j' + 1 } local i = `i' + 1 } if "`display'" != "" { if "`format'" == "" { local format "%10.2g" } di _n in gr "maximum of elements of `A0'[`nr',`nc'] = " /* */ in ye `format' `all'[1,1] } } end