Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: mata: minindex vs permutation vector for finding closest values

From   László Sándor <>
Subject   Re: st: mata: minindex vs permutation vector for finding closest values
Date   Mon, 14 May 2012 10:54:59 -0400

Thanks, Brendan, indeed this was the route to take.

However, for my purposes, I think I needed a more complicated
convolution of -order- and -invorder- and the permutation vectors they
provide, though I might be missing some potential simplification here.

Basically, I need to lookup the "rank" in the ordering of a vector
(for an application with matching on a single dimension, like the
propensity score), calculate ranks close to that rank, and get back
indices of observations with those ranks. I had a hard time noticing
that I had it backwards with -order- and -invorder-.

Below is a little example. Notice that real applications should
truncate the indices provided to be in the range of possible indices.
Also notice that if you run minindex on the now-selected, short
vector, you'll get back indices relevant to the selected vector, not
the original population, you need to translate those back. Though I
think the last argument that -minindex- returns is good as it is (FYI:
the matrix relevant for ties).

* test
x = 10*jumble(range(1,10,1))
y = range(20,11,-1)
p = order(x,1)
invp = invorder(p)
p[|2-1,1 \ 2+1,1|]
yki = y[p[|invp[2]-1,1 \ invp[2]+1,1|]]

On Sat, May 12, 2012 at 4:57 AM, Brendan Halpin <> wrote:
> This may contain the kernel of a solution:
> mata: x = runiform(5,1)
> mata: y = (1,2,3,4,5)
> mata: x2 = x[order(x,1)']
> mata: y2 = y[order(x,1)']
> Brendan
> --
> Brendan Halpin,   Department of Sociology,   University of Limerick,
> Ireland
> Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-009 x
> 3147
>    ULSociology on Facebook:
> twitter:@ULSociology
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index