Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Does Stata offer courses on Mata?

From (William Gould, Stata)
Subject   Re: st: Does Stata offer courses on Mata?
Date   Mon, 31 Jul 2006 08:16:07 -0500

Tim Mak <> asked, 

> If I enroll in the Advanced Programming course on Stata, will I get 
> introduced to Mata? [...] I haven't figured 
> out what the relationship is between Mata and Stata yet. 

No, we do not yet offer a NetCourse that includes Mata.

The best "outside" source of information on Mata, other than my responses 
here on Statalist, is my Matter Matters Column of the Stata Journal.

Mata, as Tim says, is about programming.  Or partly about programming, because
you can use Mata interactively and in some cases, you can do that to avoid
programming.  In fact, my next Matter Matters column is about just that.

But let's stay with programming.  Tim is not the only one confused about the
relationship between Stata and Mata.  There are three ways of programming

    1.  do-files.  

    2.  ado-files.

    3.  Mata.

Do-files are sequential; they perform one step after another, just as you do
when you work with Stata interactively.  Do-files are about reproducibility.
You write do-files to perform an analysis.

Ado-files allow you to add new commands to Stata.  Ado-files provide parsing
features and ado-files allow looping.  Ado-file looping is usually over
variables and not observations, but nothing besides performance stops you 
from looping over observations.  Many Stata features have been implemented
by ado-files, both by us and by users.

Mata is another programming language for Stata.  Mata is not better than ado,
it is different.  For some programming problems, ado-files are better and, for
others, Mata is better.  Mata has two advantages over ado-files:  it is faster
at looping and Mata has a full matrix language.  The matrix features are
useful when programming certain mathematical procedures.  The faster looping
is useful when you need to loop over observations.

At a technical level, the difference between Ado and Mata is that 
Ado is interpreted and Mata is compiled.

In advanced programming applications, Mata is often used to implement 
subroutines for use by ado-files.  That is one way we at StataCorp are 
using Mata.  Stata's multilevel regression -xtmixed- was implemented in 
just this way, and so was, to take a very different kind of example, 
-adupdate-.  We at StataCorp use Mata to avoid writing internal C 

Because of how we at StataCorp are using Mata, many users think Mata 
is only for advanced programming.  That's not true, and that's why 
my next Mata Matters column focuses on interactive use of Mata.
The best way to learn Mata is to use it interactively.

One reason there are so many ado programmers is that ado an extension of
how one uses Stata interactively.  Ado is easy to learn because, mostly, it is
one statement after another, any or all of which could have been performed
interactively.  I'm not saying there's nothing to learn, but I am 
emphasizing it is easy to learn that extra because you are already familiar 
with the bulk of the language.

Mata's the same way; it's just that you have used it interactively yet.

-- Bill
*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index