Statalist


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

st: RE: single line Mata do-while cycle


From   "Newson, Roger B" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: single line Mata do-while cycle
Date   Tue, 22 Sep 2009 18:39:56 +0100

I think the problem you are having is that Mata is a compilable language, and not an interpretable language like Stata. To make loops work in Mata, you have to put them inside a function (which will be compiled after it is written), and then call the function.

I hope this helps.

Best wishes

Roger


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected] 
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stas Kolenikov
Sent: 22 September 2009 18:32
To: [email protected]
Subject: st: single line Mata do-while cycle

I was expecting this snippet of code to work:

mata:
k=0
do k=k+1 while (k<10)

but...

: k=0

: do k=k+1 while (k<10)
'while' found where almost anything else expected
r(3000);

Breaking this into multiple lines does not help:

: do k=k+1
nothing found where 'while' expected
r(3000);

However, this one works:

do k=k+1; while (k<10)

Is that the case of "significant" semicolons per [M-2] semicolons? I
know that I sometimes need to use semicolons after -if- to indicate
absence of -else- statement in crooked branching code.

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
*   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