-------------------------------------------------------------------------------
help for mat2txt
-------------------------------------------------------------------------------

Export Matrix to Text File

mat2txt , matrix(matrixname) saving(filename) [ title(text) note(text) format(formatlist) replace append ]

Description

mat2txt exports a Stata matrix to a text file for use in other programs such as word processors or spreadsheets. The matrix row and column names as well as the matrix data values are exported to a tab delimited ASCII file. The user may optionally specify a title and/or a note to add text to the file before and/or after the matrix. Display formats may be specified. The data may be appended to an existing file or replace an existing file.

Options

matrix(matrixname) is required as it specifies the name of the matrix to export. To save estimation results, first copy the matrix out from e() into a regular Stata matrix, then export that matrix.

saving(filename) is required as it provides the name of the ASCII file to save. If no file extension is provided, .txt will be added to the end of the filename.

title(text) specifies text to be output before the matrix is written to the file.

note(text) specifies text to be output after the matrix is written to the file.

format(formatlist) allows the user to specify Stata display formats for the data values. If one value is specified, all columns are output with that format. If more than one space-delimited format is listed, they are mapped 1-to-1 to the columns of the matrix.

replace allows overwriting an existing file.

append specifies that output is to be appended onto an existing file.

Examples

. mat2txt, matrix(mycorr1) saving(mytable) title(Table 1. Correlations) . mat2txt, matrix(mycoef1) saving(mytable) append title(Table 2. Coeffs, St > d Errs, and t stats) format(%6.0f %6.1f %5.3f)

to get summary statistics produced by tabstat into a tab delimited file:

. tabstat price weight, by(foreign) stats(sum) save . tabstatmat matvars . mat2txt, matrix(matvars) saving(mytable1)

(note: tabstatmat is available from SSC)

Authors

Michael Blasnik (M. Blasnik & Associates, Boston, MA) Email: michael.blasnik@verizon.net

Ben Jann (ETH Zurich)