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: Loops in Mata
From 
 
Nick Cox <[email protected]> 
To 
 
[email protected] 
Subject 
 
Re: st: Loops in Mata 
Date 
 
Wed, 26 Jan 2011 10:24:54 +0000 
It seems that you may be expecting Mata's -for- to behave a bit like
Stata's -foreach- and perform a kind of macro substitution. -for- does
not work like this.
On Wed, Jan 26, 2011 at 10:18 AM, Nick Cox <[email protected]> wrote:
> As far as Mata is concerned, it looks as if you are asking it to do
> the same calculation 379 times on a variable called -Pi-.
>
> You want Mata to cycle over 379 different variables, which is a very
> different problem. It's probably better to read in all the data at
> once to a  matrix, then loop over the column vectors.
>
> Nick
>
> On Wed, Jan 26, 2011 at 10:08 AM, gsborker <[email protected]> wrote:
>
>> I am trying to do the following in mata
>>
>> mata
>>
>>        for (i=1; i<=379; i++) {
>>
>>                xi = st_data(.,"Pi") ;
>>                yi = (xi)' ;
>>                polyroots(yi) ;
>>
>>                }
>> end
>>
>> where P* are (674x1) column vectors. I am trying to run the "polyroots"
>> command 379 times on (1x674) row vectors. This is not working and I'm
>> getting recurrent errors.
>
*
*   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/