|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: re: question about Mata programming
Xiaoheng listed a chunk of Mata code which wasn't working for him:
-------------------------- mata (type end to exit)
-------------------------------
: for (k=1; k<=2; k++) {
> r`k' = rowmin(D)
> C`k' = J(3 , 3 , 2)
> for (i=1; i<=3; i++) {
> for (j=1; j<=3; j++) {
> if (D[ i , j ] == r`k'[ i , 1 ])
> C`k'[ i , j ] = 1
> D[ i , j ] = D[ i , j ] + 10000
> else C`k'[ i , j ] = 0
'else' found where almost anything else expected
r(3000);
The problem is that you cannot use local macros in Mata. You can
access Stata's local macros (and change them) but you cannot create
objects using local (or global) macro names. To Mata,
C = C`k' = C`anythingelse'
If you want multiple objects, you must use other techniques to create
them.
David Drukker posted a Mata solution to the nearest-neighbor problem
recently. Have a look at his posting.
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/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/