⇤ ← Revision 1 as of 2023-06-08 00:42:57
Size: 264
Comment:
|
Size: 2157
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 13: | Line 13: |
To define a matrix, use either the `matrix` or `matrix input` command. The latter only allows literals in the definition, while the former allows expressions like `1/3` or `_pi`. The former also allows assignment by matrix arithmetic. The matrix's values are bounded by parentheses (`(` and `)`). Values in a row are delimited with a comma (`,`). Rows are delimited with a backslash (`\`). {{{ . matrix input A = (1,2\3,4) . matrix list A A[2,2] c1 c2 r1 1 2 r2 3 4 }}} Matrices can be defined with other matrices as well. {{{ . matrix B = (A,A) . matrix list B B[2,4] c1 c2 c1 c2 r1 1 2 1 2 r2 3 4 3 4 . matrix C = (A\A) . matrix list C C[4,2] c1 c2 r1 1 2 r2 3 4 r1 1 2 r2 3 4 }}} A '''vector''' is simply a special case of a matrix. === Rows and Columns === A newly-defined matrix's rows and columns have sequential names (`r1`, `r2`, and so on). Many commands return matrices with names rows and columns. Many more commands are able to parse passed matrices ''only'' because rows and columns are named in a structured way. |
|
Line 19: | Line 62: |
Matrixes can be joined in either direction. {{{ . matrix A = (1) . matrix B = A , (2) . matrix list B B[1,2] c1 c2 r1 1 2 . matrix C = B \ (3,4) . matrix list C C[2,2] c1 c2 r1 1 2 r2 3 4 }}} A matrix is indexed by `NAME[ROW,COL]`. Indexing starts at 1. `C[1,2]` is 2 in the above example. Addition (and subtraction) is defined for any like-sized matrices. Multiplication is defined for any ''a x b'' and ''b x c'' matrices, the result being ''a x c''. The transpose of matrix `A` is defined with `A'`. The negation of matrix `A` is defined with `-A`. Division by [[Stata/Scalars|scalar]] is performed with the forward slash (`/`) operator. The Kronecker product is performed with the hash (`#`) operator. |
Stata Matrices
Matrices are a data type used for meta programming in the Stata programming language. See also scalars.
Contents
Definition
To define a matrix, use either the matrix or matrix input command. The latter only allows literals in the definition, while the former allows expressions like 1/3 or _pi. The former also allows assignment by matrix arithmetic.
The matrix's values are bounded by parentheses (( and )). Values in a row are delimited with a comma (,). Rows are delimited with a backslash (\).
. matrix input A = (1,2\3,4) . matrix list A A[2,2] c1 c2 r1 1 2 r2 3 4
Matrices can be defined with other matrices as well.
. matrix B = (A,A) . matrix list B B[2,4] c1 c2 c1 c2 r1 1 2 1 2 r2 3 4 3 4 . matrix C = (A\A) . matrix list C C[4,2] c1 c2 r1 1 2 r2 3 4 r1 1 2 r2 3 4
A vector is simply a special case of a matrix.
Rows and Columns
A newly-defined matrix's rows and columns have sequential names (r1, r2, and so on).
Many commands return matrices with names rows and columns. Many more commands are able to parse passed matrices only because rows and columns are named in a structured way.
Usage
Matrixes can be joined in either direction.
. matrix A = (1) . matrix B = A , (2) . matrix list B B[1,2] c1 c2 r1 1 2 . matrix C = B \ (3,4) . matrix list C C[2,2] c1 c2 r1 1 2 r2 3 4
A matrix is indexed by NAME[ROW,COL]. Indexing starts at 1. C[1,2] is 2 in the above example.
Addition (and subtraction) is defined for any like-sized matrices.
Multiplication is defined for any a x b and b x c matrices, the result being a x c.
The transpose of matrix A is defined with A'.
The negation of matrix A is defined with -A.
Division by scalar is performed with the forward slash (/) operator.
The Kronecker product is performed with the hash (#) operator.