Actually, I see that things improve _slightly_ if I use the
parentheses properly in the st_local() lines, but my program is still
not quite right.
--- new LittleProgram.do ---
clear
capture program drop MyLittleProgram
program define MyLittleProgram
args one two
mata:
one = st_local("one")
one
two = st_local("two")
two
end
MyLittleProgram Test1 Test2
--- end LittleProgram.do --
This accomplishes a little, but still crashes at the end so I suspect
I am doing something wrong -- from the Results:
--- begin [Results] ---
. capture program drop MyLittleProgram
.
. program define MyLittleProgram
1. args one two
2. mata:
3. one = st_local("one")
4. one
5. two = st_local("two")
6. two
7. end
.
. /*
program define MyLittleProgram
args one two
display "`one'"
display "`two'"
end
*/
. MyLittleProgram Test1 Test2
Test1
Test2
unexpected end of file (end statement missing)
r(612);
end of do-file
r(612);
--- end [Results] ---
I experimented with adding an "end" in a couple of places (right after
the first "end", right after the call to MyLittleProgram), but this
did not help.
On 2/2/07, Venable <[email protected]> wrote:
Hi, I am fairly new to both programs / ado and Mata, so I apologize in
advance if this is a dumb question or has been addressed elsewhere.
I am trying to learn to write programs that use Mata code, so I wrote
the following very simple example just to try to start to figure
things out.
--- (begin LittleProgram.do-file) ---
clear
capture program drop MyLittleProgram
program define MyLittleProgram
args one two
mata:
one = st_local("`one'")
one
two = st_local("`two'")
two
end
end
MyLittleProgram Test1 Test2
--- (end LittleProgram.do-file) ---
I was expecting the do-file to do the following: load the program,
then call MyLittleProgram with arguments Test1 and Test2. Then
MyLittleProgram would fire up Mata and Mata would read in and read
back the two arguments. However, I get the following:
--- begin results from [Results] ---
. do LittleProgram
. clear
. capture program drop MyLittleProgram
. program define MyLittleProgram
1. args one two
2. mata:
3. one = st_local("`one'")
4. two = st_local("`two'")
5. end
. end
unrecognized command: end
r(199);
end of do-file
r(199);
--- (end of [Results]) ---
It seems that the "end" command I would usually use to get out of Mata
does that but then also is interpreted as the end of the program. So I
dropped the second "end" from the do-file , made no other changes, and
ran it again. Here's what I got:
--- (begin [Results]) ---
. do LittleProgram
. clear
. capture program drop MyLittleProgram
.
. program define MyLittleProgram
1. args one two
2. mata:
3. one = st_local("`one'")
4. one
5. two = st_local("`two'")
6. two
7. end
.
. MyLittleProgram Test1 Test2
unexpected end of file (end statement missing)
r(612);
end of do-file
r(612);
--- (end of [Results]) ---
Now it seems like it wants the "end" back in!
I am confused. I would very much appreciate any tips. If you see other
mistakes or things I am getting wrong but haven't noticed yet, I would
love to know about those.
If there are any examples of very simple, highly annotated toy
programs using Mata that would be useful for a novice to study, I
would love to see them.
Many thanks, and again I apologize if this is a dumb posting.
*
* 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/