[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Output to Excel
At 11:09 AM 8/13/2002 +0000, Christopher D Fergusson wrote:
I have a do file which produces a matrix that looks like the following:
. matrix list cruderates
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.
(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
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.
Institute for Policy Studies
Johns Hopkins University
* For searches and help try: