Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Median for all pairwise differences

    Dear Stata forum,
    I'm interesting in performing the following operation:
    Suppose I have a variable called a with 5 rows, that takes the values 0, and 1 as shown below

    **** view from data editor***
    var1
    row1 a1
    row2 a2
    row3 a3
    row4 a4
    row5 a5
    row6 b1
    row7 b2
    row8 b3
    row9 b4
    row10 b5
    ****end view from data editor***

    I'm interesting in calculating all different pairwise differences between a's (a1 - a2, a1-a3, a1-a4, a1-a5, a2-a3, a2-a4...) These are all the elements above the diagonal of a matrix with values a1-a5 on the rows, and a1-a5 on the columns.

    Once all these differences are calculated, I want to get the median.

    After that, I want to do the same two steps with the b values, and so forth.

    Are you aware of any function that could allow me to do this? I was looking for an egen-type function, but I couldnt find any that performs this calculation.

    Thanks in advance for all your help as always.

    Laurie


  • #2
    I doubt that there are functions to do this, but commands yes.

    This is the Hodges-Lehmann location summary, is it not? There is an answer somewhere in one of Roger Newson's packages. If I find out which before Roger answers, I will post the details.

    Laurie: Please use family name (surname) as well as given name. FAQ Advice explains why and how to change your registration.

    Comment


    • #3
      http://www.stata-journal.com/article...article=st0007 and

      Code:
       
      search cendif

      Comment


      • #4
        Hi Nick, and thanks very much for your reply, it's been extremely useful.
        I didn't know that before, but you are right, this is the Hodges-Lehman statistic.
        The cendif function works very well for the problem I described originally.

        I'm interested however in a very small modification and I don't see from the documentation how to do it:

        Is it possible to get the median of the 'absolute value' of the pairwise differences?

        Thanks very much again.

        Laurie Molina

        I'm already working on getting my last name on my profile, for now, I'll just sign it here.

        Comment


        • #5
          Is that different? Otherwise put, if we look at all pairwise differences then for pairs x, y (x - y) is equal in magnitude and opposite in sign to (y - x) and the median pairwise difference is inevitably and uselessly zero.

          Comment


          • #6
            I think it is different. You are right in that with the cendif command I'm getting all zeros.
            If I understand correctly, those commands are to test whether two samples come from the same population.
            In the notation of my first post, this is as taking the full matrix of differences where a1-a5 are in the columns, and b1-b5 are in the rows.
            In my case, this is as if I were interested in taking the above diagonal part of a matrix that has a1-a5 in the columns, and also a1-a5 in the rows. I think this last part is closer to taking the full matrix, but with entries equal to the absolute value of the difference. (I'm still not sure how to deal with the diagonal zeros yet).

            Comment

            Working...
            X