Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: How to convert matrix to variables in MATA


From   "Rodrigo Martell" <[email protected]>
To   <[email protected]>
Subject   st: RE: How to convert matrix to variables in MATA
Date   Tue, 12 Dec 2006 11:10:31 +1100

I think you can use the -st_matrix- command in mata to send D3 to Stata, and then use -outsheet- to save D3 as a text or csv file or whatever the options are in outhseet.

So you'll have a few lines looking like this:
******* start here
st_matrix("D3",D3)
end
***** the "end" above is to get out of mata. from now on you're back into Stata
svmat double D3, name(D3)
outsheet D3 using "C:/test1.csv", comma
************ end here

I hope this helps and/or works.

Cheers,

Rodrigo


Rodrigo Martell

 <http://www.frontier-economics.com> 	
Frontier Economics Pty. Ltd.
395 Collins Street
Melbourne VIC 3000
Australia
www.frontier-economics.com 	
switch:
direct:
fax:
mobile:
email:


+61 (0)3 9620 4488
+61 (0)3 9613 1518
+61 (0)3 8614 2711
+61 (0)407 909 811
[email protected] <mailto:[email protected]> 


This e-mail, including any attachments, may contain confidential and privileged information for the sole use of the intended recipient(s). Any review, use, disclosure or distribution by others is strictly prohibited. If you are not the intended recipient (or authorised to receive information for the recipient), please contact the sender by reply e-mail and delete all copies of this message. Thank you.

	



-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Bamidele Tayo
Sent: Tuesday, 12 December 2006 10:57 AM
To: [email protected]
Subject: st: How to convert matrix to variables in MATA


Dear Stata Users,

I am using Stata 9.2 and I would appreciate if someone can help me
with how to convert matrix to variables in MATA. What I want to do is
(i) read some values from stata file into column vector "D1", (ii)
convert column vector "D1" to a symmetric matrix "D2", (iii) convert
matrix "D2" to column vector "D3", and (iv) save "D3" to either
existing/new stata file or ASCII file. Steps (i) - (iii) work well,
but I can get to accomplish step (iv) with any of the commands in the
MATA manual. Perhaps, what I want is how to perform the same task
that "savmat" command does in the old matrix language of Stata. Below
are the codes I am using.

log using "c:\test1.log", replace
use "C:\test1.dta", clear
mata
D1 = st_data((1,6),"wt")
D2 =invvech(D1)
D3 =vec(D2)
D1
D2
D3
/* want to save D3 to an ASCII or Stata file here */
end
log close

Thanks in advance for your help.

Bamidele Tayo


 
____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index