Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: mata in ado file question: how to have stata lines between the mata code blocks


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: mata in ado file question: how to have stata lines between the mata code blocks
Date   Sun, 1 Apr 2012 08:47:50 +0100

As you say, the block of code

 local o1 "o1"
 local po1 "*p.o1"
di "loop of locals"
forv i=2/10 {
         local o`i' "`o`=`i'-1'', o`i'"
         local po`i' "`po`=`i'-1'', *p.o`i'"
}

is outside any -program-. So even if your code is legal nothing done
in this block can be seen by anything else. Presumably this has
side-effects elsewhere.

It is a convention to put Mata segments at the end of a program, but
it is not a rule, I believe. Remember that there are two quite
distinct actions, defining a program and later executing it. The
distinction is even sharper in Mata than in Stata, as the Mata code is
compiled. But the whole of the program, including Mata code, has to be
defined before it can possibly be executed.

Nick

2012/3/31 László Sándor <[email protected]>:

> I think I am following the existing and the "missing" manual on Stata
> (i.e. Bill's UKSUG10 slides), but I might have zeroed in on why my
> code does not run (on Stata 12.1 MP for mac).
>
> Basically, I wanted to define several mata functions and as I cannot
> simply upload existing libraries to my server, I thought I would also
> paste in the source code for -moremata- functions my Mata code used.
> The code compiled now, but gives me the rare and poorly documented
> error r(9611). Some Googling taught me this is about a loop going
> wrong. Now I have an idea where, but perhaps it's better for all to
> ask you what the code should look like in the first place.
>
> Currently it has blocks like
>
> program define…
> …
> end
>
> mata:
> …
> end
>
> mata:
> …
> end
>
> local o1 "o1"
> local po1 "*p.o1"
> di "loop of locals"
> forv i=2/10 {
>         local o`i' "`o`=`i'-1'', o`i'"
>         local po`i' "`po`=`i'-1'', *p.o`i'"
> }
>
> mata:
> …
> end
>
> Maybe the Stata loop that one of the Mata definitions uses is just
> hanging there (outside of all blocks that end with and "end"). Where
> should I place it? Is it OK to have all these "mata: … end" blocks in
> the first place?
>
> Sorry it was not clear to me from the manuals.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index