COL (x);
The COL function is part of the IMLMLIB library . The COL function returns a matrix that has the same dimensions as the x matrix and whose jth column has the value j. You can use the COL and ROW function to extract elements of a matrix. For example, the following statements fill the subdiagonal, superdiagonal, and main diagonal of a matrix with a sequence of numbers:
x = j(5, 5, 0); /* allocate 5 x 5 matrix of zeros */ r = row(x); /* create helper matrices */ c = col(x); idx = loc(abs(r-c)<= 1); /* indices of sub-, super-, and main diagonal */ x[idx] = 1:ncol(idx); /* fill with 1,2,3,... */ print x[format=Best3.];
If r = row(m)
and c = col(m)
are two matrices, then you can use logical comparisons of r
and c
to describe certain submatrices, such as in Table 25.1:
Table 25.1: Some Common Submatrices
Submatrix |
Index by LOC of |
---|---|
Diagonal |
|
Upper triangular |
|
Lower triangular |
|
Banded with radius d |
|
Antidiagonal |
|
You can also use the COL function to generate an ID variable when you convert data from a wide format to a long format. For example, the following statements show how to generate a column vector with values :
NumSubjects = 5; /* number of subjects */ NumRepeated = 3; /* number of repeated obs per subject */ Y = col(j(NumSubjects, NumRepeated)); Repl = shape(Y, 0, 1); /* {1, 2, 3, 1, 2, 3, ..., 1, 2, 3} */