Stata Technical Bulletin
z[10,1]
z
rl 2
r2 4
r3 3
r4 5
r5 7
гб 6
г7 8
r8 10
r9 1
TlO 9
The variables can be restricted using if and in subcommands as well.
. mkmat x if z<9 in 7/1
. mat 1 x
x[2,l]
x
rl 7
r2 9
Note that mkmat uses the variable name to name the single column in the vector. This feature guarantees that the variable
name will be carried along in any additional matrix calculations. This feature is also useful when vectors are combined in a
general matrix.
. matrix drop _all
. mkmat x у z, matrix(xyzmat)
. matrix dir
xyzmat[10,3]
z [10,1]
у [10,1]
X[10,1]
. matrix list xyzmat
xyzm |
at [10 |
,3] | |
x |
У |
z | |
rl |
1 |
10 |
2 |
r2 |
2 |
9 |
4 |
r3 |
3 |
8 |
3 |
r4 |
4 |
7 |
ε |
r5 |
ε |
6 |
7 |
r6 |
6 |
ε |
6 |
r7 |
7 |
4 |
8 |
r8 |
8 |
3 |
10 |
r9 |
9 |
2 |
1 |
rlθ |
10 |
1 |
9 |
Caveats
The size of any matrix will be restricted by your matsize specification. A variable can have a maximum of 399 observations
under Unix and Intercooled versions of Stata and 40 for regular versions of Stata. Variables containing more data points will
not fit into a single vector.
Finally, if one of the variables has missing values, you will receive an error message and no matrices will be created.
. matrix drop _all
. replace у = . in 5
(1 real change made, 1 to missing)
. mkmat x у z
matrix у would have missing values
r(504);
. matrix dir
This problem can be taken care of by restricting the matrix to nonmissing values.