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: Question concerning pointers in Mata


From   Matthew J Baker <[email protected]>
To   [email protected]
Subject   st: Question concerning pointers in Mata
Date   Wed, 23 Mar 2011 09:56:28 -0400 (EDT)

Hello Everyone - 

I'm curious why the following two snippets of mata code produce 
different results. The observation is that if one defines a 
temporary matrix and then "points" to this matrix, the result is 
different than if one just simply "points" to the definition. 
Accordingly, I'm a bit curious about how exactly the pointer and 
the pointed is storing results. Here is an example:

/* Beginning of example */

mata
Y=J(10,1,NULL)
for (k=1;k<=10;k++) {
Y[k]=&J(k,k,1)
}
Z=J(10,1,NULL)
for (k=1;k<=10;k++) {
Temp=J(k,k,1)
Z[k]=&Temp
}
/* Compare contents of Y[1] and Z[1]  */
*Y[1]
*Z[1]

/* End of example */

Any insights appreciated!

Best,

Matt Baker

Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
*
*   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