mata
A = (1,2,3\4,5,6)
C = J(2,3,.)
for (i=1; i<=2; i++) {
C[i,.] = A[i,.]
C[i,.] // display
}
end
I tried to make a simple modification to this so that each element in
the matrix was assigned in nested -for- loops rather than assigning a
row at a time.
mata
A = (1,2,3\4,5,6)
C = J(2,3,.)
for (i=1; i<=2; i++) {
for (j=1, j<=3, j++) {
C[i,j] = A[i,j]
}
}
C
end
But this generates the error:
unexpected end of line
--------------------------------------------
r(3000);
end of do-file
r(3000);
The nested loop works fine in other simple examples such as
mata
C = J(2,3,.)
for (i = 1; i<=rows(C);i++) {
for (j = 1; j<=cols(C);j++) {
C[i,j] = i+j
}
}
C
end
But not when I make the element by element assignment C[i,j] = A[i,j]
above.
Thanks for your consideration,
Dave Harless
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept
**********************************************************************
*
* 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/