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

From |
Kit Baum <baum@bc.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
re: st: row number corresponding to a column maximum |

Date |
Tue, 28 Jul 2009 18:04:24 -0400 |

<> Gabi proposed real scalar maxneighbor(real matrix A, real scalar i, real scalar j) { real scalar k, r, max r=rows(A) max=colmax(A)[1,j] k=1 while(A[k,j]<max) { k=k+1 } return(A[k,i]) }

A solution to the problem, I believe, is capture mata mata drop maxneighbor() mata x = 1,55 \ 2,44 \ 3,33 \ 2,22 \ 2,11 real scalar maxneighbor(real matrix A, real scalar i, real scalar j) { real scalar k, max maxindex(A[.,j], 1, ii, w) return(A[ii[1,1],i]) } ival = maxneighbor( x, 2, 1) ival end

Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html

An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html * * 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/

- Prev by Date:
**re: st: row number corresponding to a column maximum** - Next by Date:
**Re: st: row number corresponding to a column maximum** - Previous by thread:
**re: st: row number corresponding to a column maximum** - Next by thread:
**Re: st: row number corresponding to a column maximum** - Index(es):

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