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]

From |
Ozgur Ererdem <ozgur.ererdem@ecopa.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Use of "Goto" command in Mata |

Date |
Mon, 2 Jan 2012 03:04:46 -0800 |

Thank you very much Nick. I will check the use of select() as you recommended. I need Mata for this operation. I wrote down a very simplified version of the code in my previous message. Actually what I am trying to do is to solve non-linear equation systems for each block of observation (about 7000). Thank you again. Ozgur 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/ * * 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/

**Follow-Ups**:**Re: st: Use of "Goto" command in Mata***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: Use of "Goto" command in Mata***From:*Ozgur Ererdem <ozgur.ererdem@ecopa.com>

**Re: st: Use of "Goto" command in Mata***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Use of "Goto" command in Mata** - Next by Date:
**st: _matplot** - Previous by thread:
**Re: st: Use of "Goto" command in Mata** - Next by thread:
**Re: st: Use of "Goto" command in Mata** - Index(es):