Bookmark and Share

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


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

Re: st: correlation-like table to dyadic pairs transformation


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: correlation-like table to dyadic pairs transformation
Date   Wed, 19 Jan 2011 10:04:22 -0600

matrix D = (input your distance matrix here)
clear
set obs 5
generate byte i = _n
expand 5
bysort i : generate byte j = _n
generate double distance = .
generate str7 points = ""
local thenames "ABW AFG AGO ALB ANT"
forvalues i=1/5 {
  replace points = "`: word `i' of `thenames''" if i == `i'
  forvalues j=1/5 {
    replace distance = D[`i',`j'] if i == `i' & `j' == j
    replace points = points + "-" + "`: word `j' of `thenames'" if i
== `i' & `j' == j
  }
}

There are other solutions of course; it would probably be a little
shorter in Mata, but you'd need to transfer the results back to Stata.

On Wed, Jan 19, 2011 at 8:20 AM, Sorin Krammer <[email protected]> wrote:
>
> Dear All,
>
> I have a problem in transforming a table that looks like this:
>
>            ABW    AFG            AGO                            ALB
>            ANT
> ABW    0    13074,04493    10155,77746    9108,047048    135,1991754
> AFG    13074            0          7072,696531    4052,529947    13005,47268
> AGO    10156    7072,69653                   0      5958,121764  10020,59095
> ALB    9108    4052,52995    5958,121764    0
>  9025,064452
> ANT    135    13005,47268    10020,59095    9025,064452                0
>
>
> This is distance data between two points.
>
> What I need is basically a dyadic dataset:
>
> ABW - AFG        13074,04493
> ABW- AGO        10155,77746
> ABW-ALB            9108,047048
> ..............
>
> ALB-ANT                9025,064452
>
> Any suggestions are welcomed. My programming is basic so I incline for
> command-based solution , if possible.
>
> Many thanks,
> Sorin
> *
> *   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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

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


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