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]

st: Matching rows of the matrix with corresponding observations


From   Eilya Torshizian <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Matching rows of the matrix with corresponding observations
Date   Tue, 4 Mar 2014 20:39:54 +0000

Dear Statalisters,

I am looking for a way to allocate the rows of a matrix, derived from Mata, to their corresponding observation in the dataset. This is very similar to what option 'id()' does in -getmata-. I have a dataset with 10000 observations. There is a grouping variable, let's call it G, with 3000 unique values. First, I need to find the values of a variable (V) for each of the unique values of G, and then to import these values to Mata. Maybe I can do it as follows:
bys G:  gener _dup = cond(_N==1,0,_n)
gener _M = V if _dup < 2
*HERE I AM IMPORTING VARIABLE _M TO MATA. IS THERE ANY WAY TO MAKE THE ROWNAMES OF THIS MATRIX EQUAL TO THE CORRESPONDING UNIQUE VALUES OF THE 'G' VARIABLE?
putmata _M, omit replace
mata
*SOME COMMANDS THAT DERIVE MATRIX _M[3000,1]
end
*Here, i need to import the matrix _M[3000,1] from Mata. After sorting observations by variable G, I should allocate each row of the matrix to an observation with a unique value of G. It was desirable if I could use -getmata, id()-, however, as I don't have the rownames for the _M matrix, it is not possible to do so.

Thanks,
Eilya.



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


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