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: mata in a while loop


From   "Ozimek, Adam" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: mata in a while loop
Date   Sat, 8 Oct 2011 12:49:20 -0400

Nick,

Thanks, I've got it working now. And I did see the other comments of yours, they were very helpful. Thanks again.  

Adam 


________________________________________
From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
Sent: Friday, October 07, 2011 6:33 PM
To: [email protected]
Subject: Re: st: mata in a while loop

I wasn't aware that was legal code.

This worked for me

local test = 0
file open finished using outputtest.txt, write text replace

while `test' <10 {
          mata :  fields = tokens(st_local("test"))
          mata :  st_local("output",fields[1])
        file write finished "`output'" _n
        local ++test
}
file close finished

Nick

P.S. note also my three postings in reply to yours of
http://www.stata.com/statalist/archive/2011-09/msg00973.html

On Fri, Oct 7, 2011 at 11:14 PM, Ozimek, Adam <[email protected]> wrote:

> I'm working on a program and I'm having a problem with the part of it where I do some part of it in mata within a while loop in stata. Here is a very simple mockup of what I'm trying to do:
>
>
> local test = 0
> file open finished using outputtest.txt, write text replace
>
>      while `test' <10 {
>            mata {
>                        fields = tokens(st_local("test"))
>                        st_local("output",fields[1])
>            }
>
>        file write finished "`output'" _n
>        local ++test
>     }
>
>
> The while loop runs fine 9 times but then when `test' = 10, it gives me this error:
> "unrecognized command:  } invalid command name"
>
> and my output file looks like this:
>
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 9
>
> What am I doing wrong? ( Please ignore that it is a senseless program in itself, this mockup is broken in the same manner my real program is broken, so if I understand this hopefully I'll understand my full program problem.)

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


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