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]
st: How to save a series of vector from a double loop in mata
From
Preeya Mohan <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: How to save a series of vector from a double loop in mata
Date
Mon, 22 Jul 2013 20:29:23 -0400
Dear Statalisters,
I am having a problem saving a series of vectors from a double loop using mata. I am working with Stata 12.1 for Windows.
I calculate distance between two locations using the haversine formula from a double loop in mata. Let's call the two locations location A and B. I create two matrices A and B each containing the latitude and longitude coordinates. For each A location, I calculate out the distance to each B location, that is, if each A and B matrix contain 4 rows each in the end I should get 16 distances calculated as shown below. Each time the loop runs however 4 column vectors are created containing only 4 distances each and I can only save the last vector. I would however like to store each vector into one large matrix with all 16 distances.
Thank you for your time in reading this.
A B distance
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
4 1
4 2
4 3
4 4
Yours,
Preeya
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/