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

From |
"Jann Ben" <ben.jann@soz.gess.ethz.ch> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: Temporary objects in Mata |

Date |
Tue, 1 Nov 2005 22:55:37 +0100 |

Hi, I have the following Mata problem: In an ado program I use various Mata subroutines and it would be convenient if earlier Mata functions could leave behind objects to be picked up by later Mata functions. Here's an artificial example: . program define test 1. mata: test1(x=., y=.) 2. mata: test2(x, y) 3. end . mata: : void test1(x, y) > { > x = "one" > y = "two" > } : void test2(x, y) display(x + y) : end . test onetwo The problem is that after completion of -test-, "x" and "y" are still in Mata's memory: . mata: mata d # bytes type name and extent ------------------------------------------------------------- 120 void test1() 104 void test2() 11 string scalar x 11 string scalar y ------------------------------------------------------------- That is, "x" and "y" have to be removed manually at the end of -test- (mata: mata drop x y). I don't like that and I am looking for a way to drop "x" and "y" automatically. I am aware that embedding test1() and test2() in a third Mata function would solve the problem, but this is not convenient in my case for other reasons. Furthermore, x and y could be stored as Stata objects (e.g. Stata scalars) and picked up from there. But that's not a good solution in my case either. My first guess was to use tempnames, but that doesn't work: . program define test 1. tempname x y 2. mata: test1(`x'=., `y'=.) 3. mata: test2(`x', `y') 4. end . mata: : void test1(x, y) > { > x = "one" > y = "two" > } : void test2(x, y) display(x + y) : end . test onetwo . mata: mata d # bytes type name and extent -------------------------------------------------------------- 120 void test1() 104 void test2() 11 string scalar __000000 11 string scalar __000001 -------------------------------------------------------------- Does anyone have a suggestion how to handle this problem? Any help will be appreciated, ben * * 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/

- Prev by Date:
**st: RE: RE: Block or hierarchical regression** - Next by Date:
**Re: st: Block or hierarchical regression** - Previous by thread:
**st: RE: RE: Block or hierarchical regression** - Next by thread:
**Re: st: Temporary objects in Mata** - Index(es):

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