Friday, March 03, 2006

st: RE: RE: How to convert a MATA matrix into a STATA matrix?

Hej Jesper,

hm, I still don't know how that would work. My Mata code is

mata m_all = st_matrix("all") nom = m_all[1...,2] denom = m_all[1...,3] denom = (denom:/denom)-denom lr = nom :/ denom out = m_all[1...,1], lr, m_all[1...,4], m_all[1...,5] end

and I'd like to turn "out" into data format.

Any ideas?


-----Original Message----- From: on behalf of Jesper Kjær Hansen Sent: Fri 3/3/2006 1:02 PM To: Subject: st: RE: How to convert a MATA matrix into a STATA matrix? > can anybody tell me how to convert a matrix generated in MATA > into STATA format? > > What I am looking for is hence the reverse of st_matrix. > > What I would like to ultimately do is to convert my MATA > matrix into data (like "svmat" for STATA matrics). > > > Best regards, > > UK >


as far as I can see, you can both obtain and put matrices using st_matrix().

From the online help:

Obtain: real matrix st_matrix(string scalar name) string matrix st_matrixrowstripe(string scalar name) string matrix st_matrixcolstripe(string scalar name)

Put: void st_matrix(string scalar name, real matrix X) void st_matrixrowstripe(string scalar name, string matrix s) void st_matrixcolstripe(string scalar name, string matrix s) void st_replacematrix(string scalar name, real matrix X)

But you can also go directly from a Mata matrix to a Stata data set.

Use the st_store() function, e.g. in a do file like this:

----------------------------------------------------------- mata:

void function StoreData(real matrix X) { real rowvector varidx varidx = st_addvar("double", st_tempname(cols(X))) st_addobs(rows(X)) st_store(.,varidx,X) }



qui describe local nvars = `r(k)' unab varlist: _all local count 1 foreach var of local varlist { rename `var' var`count++' }



Kind regards,

Jesper Kjær Hansen Student Assistant Department of Statistics University of Southern Denmark ____________________________________________

* * For searches and help try: * * *

* * For searches and help try: * * *


Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?