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: how to change matrix names with each iteration of a loop in Mata


From   Limin Fang <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: how to change matrix names with each iteration of a loop in Mata
Date   Sun, 8 Sep 2013 00:48:00 +0000

Dear Statalist users,

I am trying to automatically create a number of matrices inside a loop in a Mata function, and I want the names of the matrices to be associated with each iteration index. I am having a lot of trouble with it since I cannot use macro in Mata. Here is an example of what I want to achieve:

version 10
mata:
void indx(string scalar varlist, string scalar touse) 
{
	…..
	
	k = 1
	
	while (k <= kvar) {
		
		xk = J(k, k, k)

		k++
	}
	…..

}
end

Note that in the above script, "xk" stands for x1, x2, x3 …., i.e. in the first iteration, x1 matrix is created, and in the second one, x2 is created, and so on. 
What should I write to achieve this? I noticed that Mata doesn't have an eval() function as in MatLab, making this very hard to do.

Could anyone possibly help me with this?

Thank you very much in advance!

Regards,

Limin Fang
University of Toronto

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index