Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Use of "Goto" command in Mata

From   Ozgur Ererdem <>
To   "" <>
Subject   st: Use of "Goto" command in Mata
Date   Mon, 2 Jan 2012 02:02:18 -0800

Dear all, 

I am trying to run a loop within Mata by calling, at each loop, a different part of Stata results, distinguished by a variable named "id". For example, during the first loop, only results with id==1 will be used, then the ones with id==2 etc. 

I thought that the most adapted way to do it was to use the old-style "goto" command. Here's what I wrote: 

clear mata 
id = st_data(.,"id")
B1: y=y+1 
mata stata use "Results.dta",clear 
st_numscalar("y", y)
mata stata keep if id==y 
beta = st_data(., "beta")
if (y<4) goto B1 

When I do this, the loop does not start. Thus I obtain only results for y==1. The error I get is the following: 

: if (y<4) goto B1 
> end 
unexpected end of line

I also tried to run the loop by typing "if (y<4) {} goto B1" but I get the following message: 

system error:  UDpaddr

Any suggestions on how to use this command would be most welcome. Thank you all in advance 

Özgür Kaan Ererdem

Tél: +33 4 95 31 40 47 
Fax: +33 5 67 69 91 06

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index