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

From |
"Xiaoheng Zhang" <zhangx@tcd.ie> |

To |
statalist <statalist@hsphsun2.harvard.edu>, "Ole Boysen" <boyseno@tcd.ie> |

Subject |
st: Q about programming in mata re. syntax |

Date |
Thu, 25 Oct 2007 12:55:12 +0100 |

hello all,I am just beginning programming in mata.I am using Stata 9.2.Suppose I have such a distance matrix of three firms.Distance of a firm to itself should be 0 but I intentionally add a very large number 10000 to it. : D [symmetric] 1 2 3 +-------------------------+ 1 | 10000 | 2 | 5 10000 | 3 | 7 2 10000 | +-------------------------+ Then I run this programme and want to generate k=2 indicator matrice but can only get error messenge. two indicator matrice I need to get are C1= 0 1 0 0 0 1 0 1 0 C2= 0 0 1 1 0 0 1 0 0 Where C1 indicating the nearest neighour of each firm by '1' and C2 indicating the second nearest neighour by'1'. You need to read along each row.For example C1,first row means the nearest firm to firm 1 is firm2, and so on. . do "D:\Zhang documents\generate indicator matrix.do" . mata -------------------------- 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); : } expression invalid r(3000); : } expression invalid r(3000); : } expression invalid r(3000); : end ----------------------------------------------------------- . end of do-file I really want to make it run but guess the part arond "else" should have some syntax error. Or maybe r`k' is wrong in mata? Return code 3000 (message varies) There is an error in what you have typed. Mata cannot interpret what you mean. Could anyone help me?Thanks. Kevin Zhang * * 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: reverse prediction - confidence interval for x at given y in nonlinear model** - Next by Date:
**RE: st: Problem with stset and sttocc** - Previous by thread:
**st: reverse prediction - confidence interval for x at given y in nonlinear model** - Next by thread:
**Re: st: Q about programming in mata re. syntax** - Index(es):

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