Bookmark and Share

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


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

st: Use of "Goto" command in Mata


From   Ozgur Ererdem <[email protected]>
To   "[email protected]" <[email protected]>
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 
mata 
id = st_data(.,"id")
y=0
B1: y=y+1 
mata stata use "Results.dta",clear 
st_numscalar("y", y)
mata stata keep if id==y 
beta = st_data(., "beta")
beta 
y
if (y<4) goto B1 
end

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
r(3000);

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



Özgür Kaan Ererdem
Economist 
ECOPA


Tél: +33 4 95 31 40 47 
Fax: +33 5 67 69 91 06
[email protected] 
www.ecopa.com



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index