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

Re: st: RE: Using Mata within a foreach loop = r(1)

From   Pablo Mitnik <[email protected]>
To   [email protected]
Subject   Re: st: RE: Using Mata within a foreach loop = r(1)
Date   Fri, 07 Dec 2007 08:08:35 -0600

This is rather inconvenient when you have a longer code to run in Mata; and I haven't found any explanation in the manuals why the code with "mata" and "end" shouldn't work -- my bet is that this is a bug. Anyway, thanks Abdel and Nick for the workaround.

Nick Cox wrote:

Abdel was quite correct to leave out an -end- statement. His example was a series of separate invocations of Mata.
Pablo Mitnik

Thanks for your answer -- but observe you left the end statement out. I
want to get out of Mata and continue doing stuff in the loop. When you
add the end command, the error I described is generated.

Abdel Rahmen El Lahga wrote:

I don't understand your loop but the code below work *===================== foreach i in 1 2 {
mata: A=1,2
mata: A
mata: mata clear

2007/12/7, Nick Cox <[email protected]>:

My guess is that you have to respect much more the fact that Stata and Mata are different languages. I don't think you can mix them quite like this.

Something like

foreach ... {
myprog ...

where -myprog- is a Stata program that calls Mata is more likely to succeed.

As your real problem is different, further advice may wait upon details.

Pablo Mitnik

When I try to do stuff in Mata within a loop, in a do file, I receive

the following error message:


end of do-file


I looked up r(1), and it says:

[P] error . . . . . . . . . . . . . . . . . . . . . . . . .

code 1
You pressed Break. This is not considered an error.

(Of course, I don't press break while the loop is executing.)

The following very simple loop reproduces the error I get

foreach i in 1 2 {
mata clear

Any clue about what my mistake is?
* For searches and help try:
Pablo A. Mitnik
University of Wisconsin-Madison ( )
Department of Sociology (
Center on Wisconsin Strategy ( )
1180 Observatory Drive
Room 7114A
Madison, WI 53706
TEL (608) 2621839
E-mail: [email protected]

* For searches and help try:

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