Home  /  Products  /  Stata 11  /  Mata

Updates to matrix programming (Mata) were introduced in Stata 11.

See the latest version of Mata. See all of Stata's matrix programming features.

See the new features in Stata 18.

Order

What’s new in Mata

  • Mata now allows full object-oriented programming! A class is a set of variables, related functions, or both tied together under one name. One class can be derived from another via inheritance. Variables can be public, private, protected, or static. Functions can be public, private, protected, static, or virtual. Members, whether variables or functions, can be final. Classes, member functions, and access to member variables and calls to member functions are fully compiled—not interpreted—meaning there is no speed penalty for casting your program in terms of a class.
  • The new moptimize() suite of functions comprises Stata’s new optimization engine used by ml and thereby, either directly or indirectly, by nearly all official Stata estimation commands. moptimize() provides full support for Stata’s new factor variables.

    moptimize is important. The full story is that Stata’s ml is implemented in terms of Mata’s moptimize(), which in turn is implemented in terms of Mata’s optimize(). optimize() finds parameters p = (p1, p2, ..., pn) that maximize or minimize f(p). moptimize() finds coefficients b = (b1, b2, ..., bn), where p1 = X1b1, p2 = X2b2, ..., pn = Xnbn.
  • New function suite deriv() produces numerically calculated first and second derivatives of vector functions.
  • Improvements have been made to optimize():

    • optimize() with constraints is now faster for evaluator types d0 and v0 and for all gradient-based techniques. Also, it is faster for evaluator types d1 and v1 when used with constraints and with the nr (Newton–Raphson) technique.
    • Gauss–Newton optimization, also known as quadratic optimization, is now available as technique gn. Evaluator functions must be of type ‘q’.
    • optimize() can now switch between techniques bhhh, nr, bfgs, and dfp (between Berndt–Hall–Hall–Hausman, Newton–Raphson, Broyden–Fletcher–Goldfarb–Shanno, and Davidon–Fletcher–Powell).
    • optimize(), when output of the convergence values is requested in the trace log, now displays the identity and value of the convergence criterion that is closest to being met.
    • optimize() has 15 new initialization functions:
      optimize_init_cluster()optimize_init_trace_dots()
      optimize_init_colstripe()optimize_init_trace_gradient()
      optimize_init_conv_ignorenrtol()optimize_init_trace_Hessian()
      optimize_init_conv_warning()optimize_init_trace_params()
      optimize_init_evaluations()optimize_init_trace_step()
      optimize_init_gnweightmatrix()optimize_init_trace_tol()
      optimize_init_iterid()optimize_init_trace_value()
      optimize_init_negH()
      Also, new function optimize_result_evaluations() reports the number of times the evaluator is called.
  • Existing functions st_data() and st_view() now allow the variables to be specified as a string scalar with space-separated names, as well as a string row vector with elements being names. Also, when a string scalar is used, you now specify either or both time-series–operated variables (e.g., l.gnp) and factor variables (e.g., i.rep78).
  • Thirty-four LAPACK (Linear Algebra PACKage) functions are now available in as-is form, and more are coming. LAPACK is the premier software for solving systems of simultaneous equations, eigenvalue problems, and singular value decompositions. Many of Mata’s matrix functions are and have been implemented using LAPACK. We are now in the process of making all the double-precision LAPACK real and complex functions available in raw form for those who want to program their own advanced numerical techniques.
  • New function suite eigensystemselect() computes the eigenvectors for selected eigenvalues.
  • New function suite geigensystem() computes generalized eigenvectors and eigenvalues.
  • New function suites hessenbergd() and ghessenbergd() compute the (generalized) Hessenberg decompositions.
  • New function suites schurd() and gschurd() compute the (generalized) Schur decompositions.
  • New function _negate() quickly negates a matrix in place.
  • New functions Dmatrix(), Kmatrix(), and Lmatrix() compute the duplication matrix, commutation matrix, and elimination matrix used in computing derivatives of functions of symmetric matrices.
  • New function sublowertriangle() extracts the lower triangle of a matrix, where lower triangle means below a specified diagonal.
  • New function hasmissing() returns whether a matrix contains any missing values.
  • New function strtoname() performs the same actions as Stata’s strtoname() function: it converts a general string to a string meeting the Stata naming conventions.
  • New function abbrev() performs the same actions as Stata’s abbrev() function: it returns abbreviated variable names.
  • New function _st_tsrevar() is a handle-the-error-yourself variation of existing function st_tsrevar().
  • Existing functions ghk() and ghkfast(), which evaluate multivariate normal integrals, have improved syntax.
  • Existing functions vec() and vech() are now faster for both real and complex matrices.
  • Mata has 13 new distribution-related functions: hypergeometric() and hypergeometricp(); nbinomial(), nbinomialp(), and nbinomialtail(); invnbinomial() and invnbinomialtail(); poisson(), poissonp(), and poissontail(); invpoisson() and invpoissontail(); and binomialp().
  • Mata has nine new random-variate functions for beta, binomial, chi-squared, gamma, hypergeometric, negative binomial, normal, Poisson, and Student’s t: rbeta(), rbinomial(), rchi2(), rgamma(), rhypergeometric(), rnbinomial(), rnormal(), rpoisson(), and rt(), respectively.

    Also, rdiscrete() is provided for drawing from a general discrete distribution.

    Old functions uniform() and uniformseed() are replaced with runiform() and rseed(). All random-variate functions start with r.
  • Existing functions sinh(), cosh(), asinh(), and acosh() now have improved accuracy.
  • New function soundex() returns the soundex code for a name and consists of a letter followed by three numbers. New function soundex_nara() returns the U.S. Census soundex for a name and also consists of a letter followed by three numbers, but is produced by a different algorithm.
  • Existing function J(r, c, val) now allows val to be specified as a matrix and creates an r*rows(val) × c*cols(val) result. The third argument, val, was previously required to be 1 × 1. Behavior in the 1 × 1 case is unchanged.
  • Existing functions sort(), _sort(), and order() sorted the rows of a matrix based on up to 500 of its columns. This limit has been removed.
  • New function asarray() provides associative arrays.
  • New function hash1() provides Jenkins’ one-at-a-time hash function.
  • Mata object-code libraries (.mlib’s) may now contain up to 2,048 functions and may contain up to 1,024 by default. Use mlib create’s new size() option to change the default. The previous fixed maximum was 500.
  • Mata on 64-bit computers now supports matrices larger than 2 gigabytes when the computer has sufficient memory.
  • One hundred and nine existing functions now take advantage of multiple cores when using Stata/MP. They are
    acos() factorial() mm()
    ark() Fden() mmC()
    asin() floatround() mod()
    atan2() floor() mofd()
    atan() Ftail() month()
    betaden() gammaden() msofhours()
    binomial() gammap() msofminutes()
    binomialtail() gammaptail() msofseconds()
    binormal() halfyear() nbetaden()
    ceil() hh() nchi2()
    chi2() hhC() nFden()
    chi2tail() hofd() nFtail()
    Cofc() hours() nibeta()
    cofC() ibeta() normal()
    Cofd() ibetatail() normalden()
    cofd() invbinomial() npnchi2()
    comb() invbinomialtail() qofd()
    cos() invchi2() quarter()
    day() invchi2tail() round()
    dgammapda() invF() seconds()
    dgammapdada() invFtail() sin()
    dgammapdadx() invgammap() sqrt()
    dgammapdx() invgammaptail() ss()
    dgammapdxdx() invibeta() tan()
    digamma() invibetatail() tden()
    dofC() invnchi2() trigamma()
    dofc() invnFtail() trunc()
    dofd() invnibeta() ttail()
    dofh() invnormal() week()
    dofm() invttail() wofd()
    dofq() ln() year()
    dofw() lnfactorial() yh()
    dofy() lngamma() ym()
    dow() lnnormal() yq()
    doy() lnnormalden() yw()
    exp() mdy()
    F() minutes()

Back to highlights