Statalist


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

Re: st: re: question about Mata programming


From   "Xiaoheng Zhang" <[email protected]>
To   [email protected]
Subject   Re: st: re: question about Mata programming
Date   Thu, 25 Oct 2007 19:23:12 +0100

Thanks Kit and Abdel Rahmen El Lahga.I know what I cannot do in mata.Cheers!

Xiaoheng

On 25/10/2007, Abdel Rahmen El Lahga <[email protected]> wrote:
> The solution is given by Bill Gould in this message
> www.stata.com/statalist/archive/2006-03/msg01044.html
> HTH
> AbdelRahmen El Lahga
>
> 2007/10/25, Kit Baum <[email protected]>:
> > 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/
> >
>
>
> --
> AbdelRahmen El Lahga
> *
> *   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/
>
>


-- 
Greetings,

Xiaoheng Zhang (Kevin)
*
*   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/



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