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

st: re: question about Mata programming

From   Kit Baum <>
Subject   st: re: question about Mata programming
Date   Thu, 25 Oct 2007 11:46:07 -0400

To more carefully state the point of my last posting:

local macros _are_ dereferenced on demand in Mata's interactive mode. Thus

local george 123
a = J(2,2,`george')

works. But that is not very useful, as you can't handily update the value of the local macro, which must be defined in Stata (or via st_local()). Furthermore, you can't use local macros in Mata functions in any useful sense. If you do something like

mata: mata clear
void function eye()
a = I(`dim')

Mata will not compile the code because `dim' evals to nothing. If you preface this with

local dim 2

Mata will gladly compile the code, but will _hard wire_ the number 2 into the function, and doing

local dim 3
mata: eye()

will not do what you might think. (This issue---of compile-time values---is discussed in the Mata manual). So in summary: don't try to use local macros in Mata. Use Mata to access locals and create and store new values in Stata's macros, but don't try to use them as counter variables as you do in ado-file code.


Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

* For searches and help try:

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