I agree: the two code fragments should
be equivalent. (Stata indulges `j ' for `j'.)
I put this code in my do-file editor and
it ran without problem, so I suspect
some other problem.
tempname newvec rowvec
matrix `rowvec' = J(10,1,1)
matrix `newvec' = J(10,1,2)
local n = 10
mat li `newvec'
forvalues j = 1(1)`n' {
mat `newvec'[`n'-`j'+1,1] = `rowvec'[`j',1]
}
mat li `newvec'
Nick
[email protected]
Michael S. Hanson
> 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?
*
* 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/