[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Kit Baum <[email protected]> |

To |
[email protected] |

Subject |
st: re: question about Mata programming |

Date |
Thu, 25 Oct 2007 11:27:47 -0400 |

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/

- Prev by Date:
**Re: st: problem with .png graph export in Stata 10** - Next by Date:
**st: re: question about Mata programming** - Previous by thread:
**Re: st: conditional logistic** - Next by thread:
**st: re: question about Mata programming** - Index(es):

© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |