At 11:09 AM 8/13/2002 +0000, Christopher D Fergusson wrote:
Hello statalisters,
I have a do file which produces a matrix that looks like the following:
. matrix list cruderates
cruderates[16,2]
year cruderate
r1 1985 81.92156
r2 1986 98.751156
[...]
I need to send this matrix to excel and would like the do-file to do this
automatically. Would this be possible? I have looked at the
possibilities of using outfile and outsheet but am not sure if these will
be of any use as they seem to read the dataset, not the matrix.
[...]
Several possibilities:
(1) You could list the matrix in a log; snip out that segment of the log
and then have excel read it. But those latter steps would be manual.
(2) There is some Stata program that brings a matrix into a data set (and
maybe another one that goes the other way). Sorry, I don't recall what
that is and whether it is part of standard Stata. I believe that Nick Cox
wrote it. You should be able to find it.
(In doing this, you may want to first -preserve- the existing data set, so
you can get it back afterwards -- unless this is built into that program.)
Once you have it in a data set, save it. Then invoke StatTrasfer to
convert it to Excel. StatTrasfer is a separate program from an independent
provider. (See www.stattransfer.com; it's also mentioned in the Stata
manuals. If you work for an educational institution, you may be able to get
it cheaply through your institution.) You should use its command-processor
mode, NOT its menu system. Then you can invoke the StatTransfer commands
(in a .stc file.) via a shell command in your Stata do-file.
(You could, alternatively, use -outsheet-. But then, again, you need to
invoke Excel and go through the manual steps of reading in the file --
unless there is some way of scripting the Excel commands; I don't know if
there is.)
All of this requires a lot of set-up work. Presumably you want to do it
repeatedly many times, and so it will be worthwhile. Otherwise, if you are
doing it just a few times, the first method is easier.
I hope this helps.
--David
David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404
*
* 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/