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]

st: RE: [Mata] naming matrices in a loop


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: [Mata] naming matrices in a loop
Date   Thu, 18 Mar 2010 15:33:06 -0000

In a word, pointers. 

Another answer: Although experience in Stata can lead you to want to
program in this way, I often find that the problem can be structured to
avoid it. 

Nick 
[email protected] 

Antoine Terracol

There must be an obvious way to solve my problem, but I just seem to be 
unable to find it...

In a Mata loop, I want to store the result of each pass into a separate 
matrix whose name depends on the value of the counter

It would look like:

for (n=1;n<=10;n++){
		...
		name_that_depends_on_n=<result of the calculation>
		}

so that I get 10 matrices named, for example, result1, result2, ..., 
result10.

In Stata, I would do something like

forvalues i=1/10 {
		...
		result`i'=<result of the calculation>
		}

	

How can this be done in Mata?

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