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: Creating a matrix from an excel table


From   [email protected] (Brendan Halpin)
To   [email protected]
Subject   Re: st: Creating a matrix from an excel table
Date   Fri, 01 Apr 2011 22:21:47 +0100

On Fri, Apr 01 2011, Brendan Halpin wrote:

> On Fri, Apr 01 2011, Diego Canales wrote:
>
>> Does anyone know how could I import my data as a matrix into Stata, or
>> Mata I guess? I'm aware that I am constrained with the matrix size (I
>> have Stata SE, so 11,000 matrix maximum), so I'm planning on deleting
>> observations that are above a certain threshold and come up with a
>> smaller matrix.
>
> Here's a starting point:
>
>
> +-------------------------------------------------------------------
> |input group latj lonj
> |1	56	298.5816873
> |1	55	466.3318352
> |1	2	537.7437382

I misread that badly, probably because I have been extracting too much
data from gpx files recently and (being at 52.5N) read the 56 in line 1
as latitude and didn't think about what 537.7E might mean!

What you want is mata. This example assumes you have every pairwise
combination, and that the distances are not necessarily symmetric:

+----------------------------------------------------------------------
|input i j dist
|1   1   0.0000000
|1   2 466.3318352
|1   3 537.7437382
|2   1 736.950696
|2   2   0.0000000
|2   3 820.9843873
|3   1 832.6894503
|3   2 893.208735
|3   3   0.0000000
|end
|
|sort i j
|
|mata:
|m = st_data(.,"dist")
|ms = rowshape(m, sqrt(length(m)))
|ms
|end
+----------------------------------------------------------------------

If your data is symmetric (more likely) and in "lower triangle" format:

+----------------------------------------------------------------------
|input i j dist
|1   1   0
|1   2 466.3
|1   3 537.7
|1   4 469.1
|2   2   0
|2   3 820.9
|2   4 543.1
|3   3   0
|3   4 832.6
|4   4   0
|end
|
|sort i j
|
|mata:
|m = st_data(.,"dist")
|ms = invvech(m)
|ms
|
|st_matrix("ms", ms)
|
|end
|
|mdsmat ms, dim(2)
+----------------------------------------------------------------------

And note that a 200x200 matrix should be no problem. 


Regards,

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
mailto:[email protected]  http://www.ul.ie/sociology/brendan.halpin.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/


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