Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: while vs. forvalues


From   "Michael S. Hanson" <mshanson@mac.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: while vs. forvalues
Date   Sat, 7 Aug 2004 01:14:46 -0400

I tried the following code snippet in a program, but I kept getting an "invalid syntax" error at the -forvalues- command (according to -trace-):

forvalues j = 1(1)`n' {
mat `newvec'[`n'-`j'+1,1] = `rowvec'[`j',1]
}

When I replaced that code with the following, the program completed as expected:

local j = 1
while `j '<= `n' {
mat `newvec'[`n'-`j'+1,1] = `rowvec'[`j',1]
local ++j
}

I'm puzzled by this, as my reading of p.214 of the User's Guide suggests these two approaches should be equivalent. Any ideas?

-- Mike

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index