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]

Re: st: Use of "Goto" command in Mata


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Use of "Goto" command in Mata
Date   Mon, 2 Jan 2012 10:32:44 +0000

It is not clear that you need Mata at all here. But the problem arises
because "end" is ambiguous. So, you can't do it this way.

Assuming that there is a case for Mata  I would read all the data into
Mata and loop over 1..4 and use -select()- to select blocks of
observations. -goto- could probably be made to work but is not needed
when you know you want to loop over 1..4.

Nick

On Mon, Jan 2, 2012 at 10:02 AM, Ozgur Ererdem <ozgur.ererdem@ecopa.com> wrote:

> 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);
>

*
*   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