New Stata command
include is a variation on
do and
run
and is useful for implementing #include for
header files in advanced programming situations. See [P]
include and type
viewsource optimize.mata for an example of use.
Mata now has structures, which will be of special interest to those
writing large systems. See [M-2]
struct and [M-5]
liststruct().
Mata now engages in more thorough type checking, and produces better code,
for those who explicitly declare arguments and variables.
Mata inherits all of Stata’s formats and functions for dealing
with the new date/time variables and values; see [M-5]
date() and [M-5]
fmtwidth().
New functions inbase() and
frombase perform base conversions; see [M-5]
inbase().
New function floatround() returns values rounded
to float precision. This is Mata’s equivalent of Stata’s
float()
function. See [M-5]
floatround().
New function nameexternal() returns the name of
an external; see [M-5]
findexternal().
Concerning matrix manipulation,
Matrix multiplication is now faster when one of the matrices contains
many zeros, as is function
cross().
Appending rows or columns to a matrix using , and \
is now faster.
New function _diag() replaces the principal
diagonal of a matrix with a specified vector or scalar; see [M-5]
_diag().
New functions select() and
st_select() select rows or columns of a
matrix on the basis of a criterion; see [M-5]
select().
Existing functions
rowsum(),
colsum(),
sum(),
quadrowsum(),
quadcolsum(), and
quadsum()
now allow an optional second argument that determines how missing
values are handled; see [M-5]
sum().
New functions
runningsum(),
quadrunningsum(),
_runningsum(), and
_quadrunningsum()
return the running sum of a vector; see [M-5]
runningsum().
New functions minindex() and
maxindex() return the indices of minimums
and maximums (including tied values) of a vector; see [M-5]
minindex().
Concerning statistics,
New Mata function optimize() performs
minimization and maximization. You can code just the function, the
function and its first derivatives, or the function and its first and
second derivatives. Optimization techniques include
Newton–Raphson, Davidon–Fletcher–Powell,
Broyden–Fletcher–Goldfarb–Shanno,
Berndt–Hall–Hall–Hausman, and the simplex method
Nelder–Mead. See [M-5]
optimize().
New function cvpermute() forms permutations;
see [M-5]
cvpermute().
New function ghk() provides the
Geweke–Hajivassiliou–Keane multivariate normal
simulator; see [M-5]
ghk().
New function ghkfast() is faster but a
little more difficult to use; see [M-5]
ghkfast().
New functions halton(),
_halton(), and ghalton() compute
Halton and Hammersley sets; see [M-5]
halton().
The new density and probability functions available in Stata are also
available in Mata, including
binomial(),
binomialtail(),
gammaptail(),
invgammaptail(),
invbinomialtail(),
ibetatail(),
invibetatail(),
lnnormal(), and
lnnormalden();
see [M-5]
normal().
Also, as in Stata, convergence and accuracy of many of the
cumulatives, reverse cumulatives, and density functions have been
improved.
Existing Mata functions
mean(),
variance(),
quadvariance(),
meanvariance(),
quadmeanvariance(),
correlation(), and
quadcorrelation()
now make the weight argument optional.
If not specified, unweighted estimates are returned. See
[M-5] mean().
Concerning string processing,
New function stritrim() replaces multiple,
consecutive internal spaces with one space; see [M-5]
strtrim().
New functions strtoreal() and
_strtoreal() convert strings to numeric
values; see [M-5]
strtoreal().
New function _substr() substitutes a
substring into an existing string; see [M-5]
_substr().
New function invtokens() is the inverse of
the existing function tokens(); see [M-5]
invtokens().
New function tokenget() performs advanced
parsing; see [M-5]
tokenget().
Concerning I/O,
New function adosubdir() returns the subdirectory in
which Stata would search for a file; see [M-5]
adosubdir().
New function
pathsearchlist(fn)
returns a row vector of full paths/filenames specifying all the
locations, in order, where Stata would look for the specified
fn along the official Stata ado-path; see [M-5]
pathjoin().
New function byteorder() returns 1 if the
computer is HILO and returns 2 if the computer is LOHI; see [M-5]
byteorder().
New undocumented function st_fopen()
makes opening files easier; see
help mata
st_fopen().
New functions bufput() and
bufget() copy elements into and out of
buffers; see [M-5]
bufio().
Existing function cat() now allows optional
second and third arguments that specify the beginning and ending lines
of the file to read; see [M-5]
cat().
New functions ferrortext() and
freturncode() obtain error messages and return
codes following an I/O error; see [M-5]
ferrortext().
Concerning the Stata interface,
New function stataversion() returns the version of Stata
that you are running, and new function statasetversion()
allows setting it. See [M-5]
stataversion().
New function setmore() allows turning
more on and off. New function
setmoreonexit() allows restoring
more to its original setting when execution
ends. See [M-5]
more().
New undocumented function st_lchar() allows
storing exceedingly long strings (such as a varlist) in Stata dataset
characteristics. See
help mata
st_lchar().
We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.
Cookie Settings
Privacy policy
Last updated: 16 November 2022
StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.
These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.
Advertising and performance cookies
This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.
Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.