Statalist The Stata Listserver


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

st: Novice question about programs and Mata


From   Venable <venablito@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Novice question about programs and Mata
Date   Fri, 2 Feb 2007 16:17:14 -0500

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/



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