MAT-file export plugin
matwrite [anything] using filename [if exp] [in range] [, matrix(namelist) replace ]
matwrite allows you to export data in the MATLAB MAT-file format from within Stata. Variables as specified in anything can be exported as column vectors, and groups of variables can be exported as matrices. Stata matrices as specified in matrix(namelist) are exported as matrices.
anything can contain a varlist, as well as facilitating the export of a group of variables as a matrix. matwrite identifies user specified matrices by the matrix name being followed by a varlist contained within square brackets: matrixname[varlist]. For example, income[y*] will export a matrix named "income" which contains all variables which begin with "y".
matrix(namelist) specifies the Stata matrices that will be exported by matwrite. If any of the specified matrices do not exist, a warning message will be displayed, although an error will not be raised.
If anything is not specified, all variable in the open Stata dataset will be exported as column vectors. Similarly, if matrix(namelist) is not specified, all Stata matrices will be exported.
Missing values in both variables and matrices are recoded as positive infinity in MATLAB.
String variables can not be exported as this is not allowed by the Stata plugin interface.
Variable names and matrix names can not be longer than 19 characters as this is not supported by the Level 4 MAT-File format. A future version of matwrite will support the Level 5 MAT-File format which does not impose this restriction.
. matwrite using c:\matlabfile,replace
. matwrite var1 var2 var3 using c:\matlabfile, mat(mat1 mat2) replace
. matwrite var1 if var2<=10 using c:\matlabfile, mat(mat1 mat2) replace
. matwrite mymat1[var*] var1 var2 using c:\matlabfile, mat(mat1 mat2) replace
MATLAB is a registered trademark of The MathWorks, Inc. Sections of this code make use of the Stata plugin interface.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT WILL THE COPYRIGHT HOLDERS OR THEIR EMPLOYERS, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THIS SOFTWARE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Andrew Shephard, Institute for Fiscal Studies, London, UK mailto:email@example.com.