Home  /  Bookstore  /  Documentation  /  Mata Reference Manual

Mata Reference Manual

Publisher:  Stata Press
Copyright:  2023
ISBN-13:  978-1-59718-388-8
Pages:  1,178
 
Suggested citation

StataCorp. 2023. Stata 18 Mata Reference Manual. College Station, TX: Stata Press.

Supplemental material
Mata Reference Manual for Stata
Download »

Table of contents

Brief contents


[M-0] Introduction to the Mata manual

Intro Introduction to the Mata manual

[M-1] Introduction and advice

Intro Introduction and advice
Ado Using Mata with ado-files
First Introduction and first session
help Obtaining help in Stata
How How Mata works
Interactive Using Mata interactively
LAPACK Linear algebra package (LAPACK) routines
Limits Limits and memory utilization
Naming Advice on naming functions and variables
Permutation An aside on permutation matrices and vectors
Returned args Function arguments used to return results
Source Viewing the source code
Tolerance Use and specification of tolerances

[M-2] Language definition

Intro Language definition
break Break out of for, while, or do loop
class Object-oriented programming (classes)
Comments Comments
continue Continue with next iteration of for, while, or do loop
Declarations Declarations and types
do do ... while (exp)
Errors Error codes
exp Expressions
for for (exp1; exp2; exp3) stmt
ftof Passing functions to functions
goto goto label
if if (exp)... else...
op_arith Arithmetic operators
op_assignment Assignment operator
op_colon Colon operators
op_conditional Conditional operator
op_increment Increment and decrement operators
op_join Row- and column-join operators
op_kronecker Kronecker direct-product operator
op_logical Logical operators
op_range Range operators
op_transpose Conjugate transpose operator
optargs Optional arguments
pointers Pointers
pragma Suppressing warning messages
reswords Reserved words
return return and return(exp)
Semicolons Use of semicolons
struct Structures
Subscripts Use of subscripts
Syntax Mata language grammar and syntax
version Version control
void Void matrices
while while (exp) stmt
 

[M-3] Commands for controlling Mata

Intro Commands for controlling Mata
end Exit Mata and return to Stata
lmbuild Easily create function library
mata Mata invocation command
mata clear Clear Mata's memory
mata describe Describe contents of Mata's memory
mata drop Drop matrix or function
mata help Obtain help in Stata
mata matsave Save and restore matrices
mata memory Report on Mata's memory usage
mata mlib Create function library
mata mosave Save function's compiled code in object file
mata rename Rename matrix or function
mata set Set and display Mata system parameters
mata stata Execute Stata command
mata which Identify function
namelists Specifying matrix and function names

[M-4] Categorical guide to Mata functions

Intro Categorical guide to Mata functions
Dates Date and time functions
IO I/O functions
Manipulation Matrix manipulation
Mathematical Important mathematical functions
Matrix Matrix functions
Programming Programming functions
Scalar Scalar mathematical functions
Solvers Functions to solve AX=B and to obtain A inverse
Standard Functions to create standard matrices
Stata Stata interface functions
Statistical Statistical functions
String String manipulation functions
Utility Matrix utility functions
 

[M-5] Alphabetical index to Mata functions

Intro Alphabetical index to Mata functions


abbrev() Abbreviate strings
abs() Absolute value (length)
adosubdir() Determine ado-subdirectory for file
all() Element comparisons
args() Number of arguments
asarray() Associative arrays
AssociativeArray() Associative arrays (class)
ascii() Manipulate ASCII and byte codes
uchar() Convert code point to Unicode character
assert() Abort execution if false
 
base64encode() Encode string into Base64 format
blockdiag() Block-diagonal matrix
bufio() Buffered (binary) I/O
byteorder() Byte order used by computer
 
C() Make complex
c() Access c() value
callersversion() Obtain version number of caller
cat() Load file into string matrix
chdir() Manipulate directories
cholesky() Cholesky square-root decomposition
cholinv() Symmetric, positive-definite matrix inversion
cholsolve() Solve AX=B for X using Cholesky decomposition
comb() Combinatorial function
cond() Condition number
conj() Complex conjugate
corr() Make correlation matrix from variance matrix
cross() Cross products
crossdev() Deviation cross products
cvpermute() Obtain all permutations
 
date() Date and time manipulation
deriv() Numerical derivatives
designmatrix() Design matrices
det() Determinant of matrix
_diag() Replace diagonal of a matrix
diag() Create diagonal matrix
diag0cnt() Count zeros on diagonal
diagonal() Extract diagonal into column vector
dir() File list
direxists() Whether directory exists
direxternal() Obtain list of existing external globals
display() Display text interpreting SMCL
displayas() Set display level
displayflush() Flush terminal-output buffer
Dmatrix() Duplication matrix
_docx*() Generate Office Open XML (.docx) file
dsign() FORTRAN-like DSIGN() function
 
e() Unit vectors
editmissing() Edit matrix for missing values
edittoint() Edit matrix for roundoff error (integers)
edittozero() Edit matrix for roundoff error (zeros)
editvalue() Edit (change) values in matrix
eigensystem() Eigenvectors and eigenvalues
eigensystemselect() Compute selected eigenvectors and eigenvalues
eltype() Element type, organizational type, and type name of object
epsilon() Unit roundoff error (machine precision)
_equilrc() Row and column equilibration
error() Issue error message
errprintf() Format output and display as error message
exit() Terminate execution
exp() Exponentiation and logarithms
 
factorial() Factorial and gamma function
favorspeed() Whether speed or space is to be favored
ferrortext() Text and return code of file error code
fft() Fourier transform
fileexists() Whether file exists
_fillmissing() Fill matrix with missing values
findexternal() Find, create, and remove external globals
findfile() Find file
floatround() Round to float precision
fmtwidth() Width of %fmt
fopen() File I/O
fullsvd() Full singular value decomposition
 
geigensystem() Generalized eigenvectors and eigenvalues
ghessenbergd() Generalized Hessenberg decomposition
ghk() Geweke–Hajivassiliou–Keane (GHK) multivariate normal simulator
ghkfast() GHK multivariate normal simulator using pregenerated points
gschurd() Generalized Schur decomposition
 
halton() Generate a Halton or Hammersley set
hash1() Jenkins's one-at-a-time hash function
hessenbergd() Hessenberg decomposition
Hilbert() Hilbert matrices
 
I() Identity matrix
inbase() Base conversion
indexnot() Find byte not in list
invorder() Permutation vector manipulation
invsym() Symmetric real matrix inversion
invtokens() Concatenate string rowvector into string scalar
isascii() Whether string scalar contains only ASCII codes
isdiagonal() Whether matrix is diagonal
isfleeting() Whether argument is temporary
isreal() Storage type of matrix
isrealvalues() Whether matrix contains only real values
issamefile() Whether two file paths are pointing to the same file
issymmetric() Whether matrix is symmetric (Hermitian)
isview() Whether matrix is view
 
J() Matrix of constants
 
Kmatrix() Commutation matrix
 
lapack() Linear algebra package (LAPACK) functions
ldl() Bunch–Kaufman decomposition
LinearProgram() Linear programming
liststruct() List structure's contents
Lmatrix() Elimination matrix
logit() Log odds and complementary log–log
lowertriangle() Extract lower or upper triangle
lud() LU decomposition
luinv() Square matrix inversion
lusolve() Solve AX=B for X using LU decomposition
 
makesymmetric() Make square matrix symmetric (Hermitian)
matexpsym() Exponentiation and logarithms of symmetric matrices
matpowersym() Powers of a symmetric matrix
mean() Means, variances, and correlations
mindouble() Minimum and maximum nonmissing value
minindex() Indices of minimums and maximums
minmax() Minimums and maximums
missing() Count missing and nonmissing values
missingof() Appropriate missing value
mod() Modulus
moptimize() Model optimization
more() Create –more– condition
mvnormal() Compute multivariate normal distributions and derivatives
 
_negate() Negate real matrix
norm() Matrix and vector norms
normal() Cumulatives, reverse cumulatives, and densities
 
optimize() Function optimization
 
panelsetup() Panel-data processing
panelsum() Panel sums
pathjoin() File path manipulation
Pdf() Create a PDF file
pinv() Moore–Penrose pseudoinverse
polyeval() Manipulate and evaluate polynomials
printf() Format output
 
qrd() QR decomposition
qrinv() Generalized inverse of matrix via QR decomposition
qrsolve() Solve AX=B for X using QR decomposition
quadcross() Quad-precision cross products
Quadrature() Numerical integration
 
range() Vector over specified range
rank() Rank of matrix
Re() Extract real or imaginary part
reldif() Relative/absolute difference
rows() Number of rows and number of columns
rowshape() Reshape matrix
runiform() Uniform and nonuniform pseudorandom variates
runningsum() Running sum of vector
 
schurd() Schur decomposition
select() Select rows, columns, or indices
setbreakintr() Break-key processing
sign() Sign and complex quadrant functions
sin() Trigonometric and hyperbolic functions
sizeof() Number of bytes consumed by object
solve_tol() Tolerance used by solvers and inverters
solvelower() Solve AX=B for X, A triangular
solvenl() Solve systems of nonlinear equations
sort() Reorder rows of matrix
soundex() Convert string to soundex code
spline3() Cubic spline interpolation
sqrt() Square root
st_addalias() Add alias variable to current Stata dataset
st_addobs() Add observations to current Stata dataset
st_addvar() Add variable to current Stata dataset
st_data() Load copy of current Stata dataset
st_dir() Obtain list of Stata objects
st_dropvar() Drop variables or observations
st_frame*() Data frame manipulation
st_global() Obtain strings from and put strings into global macros
st_isalias() Properties of alias variable
st_isfmt() Whether valid %fmt
st_isname() Whether valid Stata name
st_local() Obtain strings from and put strings into Stata macros
st_macroexpand() Expand Stata macros in string
st_matrix() Obtain and put Stata matrices
st_numscalar() Obtain values from and put values into Stata scalars
st_nvar() Numbers of variables and observations
st_rclear() Clear r(), e(), or s()
st_store() Modify values stored in current Stata dataset
st_subview() Make view from view
st_tempname() Temporary Stata names
st_tsrevar() Create time-series op.varname variables
st_updata() Determine or set data-have-changed flag
st_varformat() Obtain/set format, etc., of Stata variable
st_varindex() Obtain variable indices from variable names
st_varname() Obtain variable names from variable indices
st_varrename() Rename Stata variable
st_vartype() Storage type of Stata variable
st_view() Make matrix that is a view onto current Stata dataset
st_viewvars() Variables and observations of view
st_vlexists() Use and manipulate value labels
stata() Execute Stata command
stataversion() Version of Stata being used
strdup() String duplication
strlen() Length of string in bytes
ustrlen() Length of Unicode string in Unicode characters
udstrlen() Length of Unicode string in display columns
strmatch() Determine whether string matches pattern
strofreal() Convert real to string
strpos() Find substring in string
ustrpos() Find substring in Unicode string
strreverse() Reverse string
ustrreverse() Reverse Unicode string
strtoname() Convert a string to a Stata 13 compatible name
ustrtoname() Convert a Unicode string to a Stata name
strtoreal() Convert string to real
strtrim() Remove blanks
ustrtrim() Remove Unicode whitespace characters
strupper() Convert ASCII letter to uppercase (lowercase)
ustrupper() Convert Unicode string to uppercase, lowercase, or titlecase
subinstr() Substitute text
usubinstr() Replace Unicode substring
sublowertriangle() Return a matrix with zeros above a diagonal
_substr() Substitute into string
_usubstr() Substitute into Unicode string
substr() Extract substring
usubstr() Extract Unicode substring
udsubstr() Extract Unicode substring based on display columns
sum() Sums
svd() Singular value decomposition
svsolve() Solve AX=B for X using singular value decomposition
swap() Interchange contents of variables
 
Toeplitz() Toeplitz matrices
tokenget() Advanced parsing
tokens() Obtain tokens from string
trace() Trace of square matrix
_transpose() Transposition in place
transposeonly() Transposition without conjugation
trunc() Round to integer
 
uniqrows() Obtain sorted, unique values
unitcircle() Complex vector containing unit circle
unlink() Erase file
urlencode() Convert URL into percent-encoded ASCII format
ustrcompare() Compare or sort Unicode strings
ustrfix() Replaces invalid UTF-8 sequences in Unicode string
ustrnormalize() Normalize Unicode string
ustrsplit() Split string into parts based on a Unicode regular expression
ustrto() Convert a Unicode string to or from a string in a specified encoding
ustrunescape() Convert escaped hex sequences to Unicode strings
ustrword() Obtain Unicode word from Unicode string
 
valofexternal() Obtain value of external global
Vandermonde() Vandermonde matrices
vec() Stack matrix columns
 
xl() Excel file I/O class

[M-6] Mata glossary of common terms