Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: re: How to do a basic task in MATA that I cannot explain in English


From   "Sergiy Radyakin" <[email protected]>
To   [email protected]
Subject   Re: st: re: How to do a basic task in MATA that I cannot explain in English
Date   Mon, 5 Jan 2009 11:33:30 -0500

To add to what Kit has written already, Tiago, you might consider
three-dimensional matrices useful here. Instead of having 100
two-dimensional objects, just work with one three-dimensional object.
Mata does not handle directly higher-dimension arrays, but you will
find an example using pointers for this purpose here:
http://www.ssc.wisc.edu/sscc/pubs/4-26print.htm

A second way of working with these 100 matrices would be to store them
in Stata, see help for st_matrix(). You address these matrices by a
string name, which you can have in the form "TEST_"+strofreal(i) and
have one or two matrices in Mata as buffers if necessary.

First method is probably favourable for speed, second may be useful if
the matrices already exist/defined in a Stata program. Hope this
helps.

Best regards, Sergiy Radyakin



On Mon, Jan 5, 2009 at 8:54 AM, Kit Baum <[email protected]> wrote:
> <>
> Tiago said
>
> Taking the simple lines below, is it possible to create matrices TEST_1 to
> TEST_100 too?
>
>
> */-----------------START--------------
>
> clear
> set obs 100
> gene MATA = round(uniform()*45)
> gene RULES = round(uniform()*15)
> mata
> X = st_data(.,("MATA", "RULES"))
> Y = st_data(.,("RULES", "MATA"))
> for (i=1; i<=100; i++) {
> TEST = X[i,1]\Y[i,1]\X[i,1]\Y[i,1]
> }
> end
> */-----------------END-----------------
>
>
> No. See http://ideas.repec.org/a/tsj/stataj/v8y2008i3p401-412.html  for
> details.  You are redefining the matrix TEST 100 times, not creating 100
> matrices. To do the latter it is most helpful to use pointers.
>
> Kit
>
> Kit Baum, Boston College Economics and DIW Berlin
> http://ideas.repec.org/e/pba1.html
> An Introduction to Modern Econometrics Using Stata:
> http://www.stata-press.com/books/imeus.html
>
>
> *
> *   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/
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index