Mata: Stata’s Endgame

Asjad Naqvi
The Stata Guide
Published in
22 min readJun 24, 2021

--

In this article we will shed some light on Stata’s secret weapon: Mata. While most people have heard of it, and some might have even dabbled with Mata commands, very few have ventured deep inside its territory to explore what really lies beyond the obvious applications of some matrix algebra.

In fact, Mata is a very separate world from Stata, functioning with its own set of rules and procedures. To date, only two books have been written on this language. One by William Gould, the president of StataCorp, and the second one by senior developer, Christopher (Kit) Baum, who is also the gatekeeper of Stata programs. Both the books are linked at the end of this article. Beside these two books, and some blog posts on the Stata website, very little exists on a systematic introduction to the various facets of this language.

While Stata is sufficient for day-to-day use, and is smart enough to understand generic commands, Mata, a low level language, is faster, and more agile than Stata, but it is not so forgiving. It requires precision and discipline. Precision, because it is dealing with matrices where conformability matters and the syntax needs to be 100% correct. And discipline because, little support and knowledge base exists. Besides some discussions on the Stata forums that do provide some tips and hints, one mostly relies on Mata help files to figure things out.

--

--

Asjad Naqvi
The Stata Guide

Here you will find stuff on Stata, data visualizations, data wrangling, workflows, and programming.