|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: re: question about Mata programming
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
mata:
a = J(2,2,`george')
a
end
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
mata:
void function eye()
{
a = I(`dim')
a
}
end
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
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/