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


From   "Ozimek, Adam" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: mata in a while loop
Date   Fri, 7 Oct 2011 18:14:47 -0400

Statalist users,

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

Thanks, 

Adam 

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