Statalist The Stata Listserver


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

st: RE: Saving to locals in Mata


From   "Maarten Buis" <[email protected]>
To   <[email protected]>
Subject   st: RE: Saving to locals in Mata
Date   Wed, 25 Apr 2007 17:40:10 +0200

The local is only present after mata has finished, as you can see in the example below. 

*---------- begin example --------------
program example
	version 9.2
	mata: example()
	di `"my_local after mata has finished is `my_local'"'  /* <-- new */
end

mata:
	void example()
	{
		t = "string"
		st_local("my_local",t)
		stata(`" di "my_local is `my_local'""')
	}	
end

example
*---------- end example ---------------------
(For more on how to use examples I sent to the Statalist, see:
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Julian Reif
Sent: woensdag 25 april 2007 17:26
To: [email protected]
Subject: st: Saving to locals in Mata

Hi,

I am having trouble saving to locals using Mata. The following ADO code demonstrates my problem:

***example.ado code***

        program example
                version 9.2

                mata: example()
        end

        mata:
                void example()
                {
                        t = "string"
                        st_local("my_local",t)
                        stata(`" di "my_local is `my_local'""')
                }      
        end

***end example.ado code***

my_local is displayed as blank instead of "string". However, if I run the three lines of mata code inside of example() interactively, my_local has the contents "string". Why does this work interactively but not in my program? How should this have been coded so that it works?

The same problem happens if I use globals instead of locals.

Julian


*
*   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/

*
*   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