📄 mf_st_matrix.hlp
字号:
{smcl}
{* 23mar2005}{...}
{cmd:help mata st_matrix()}
{hline}
{* index stata matrices}{...}
{* index st_matrix()}{...}
{* index st_matrixrowstripe()}{...}
{* index st_matrixcolstripe()}{...}
{* index st_replacematrix()}{...}
{title:Title}
{p 4 28 2}
{bf:[M-5] st_matrix() -- Obtain and put Stata matrices}
{title:Syntax}
{p 8 12 2}
{it:real matrix}{bind: }
{cmd:st_matrix(}{it:string scalar name}{cmd:)}
{p 8 12 2}
{it:string matrix}
{cmd:st_matrixrowstripe(}{it:string scalar name}{cmd:)}
{p 8 12 2}
{it:string matrix}
{cmd:st_matrixcolstripe(}{it:string scalar name}{cmd:)}
{p 8 12 2}
{it:void}{bind: }
{cmd:st_matrix(}{it:string scalar name}{cmd:,}
{it:real matrix X}{cmd:)}
{p 8 12 2}
{it:void}{bind: }
{cmd:st_matrixrowstripe(}{it:string scalar name}{cmd:,}
{it:string matrix s}{cmd:)}
{p 8 12 2}
{it:void}{bind: }
{cmd:st_matrixcolstripe(}{it:string scalar name}{cmd:,}
{it:string matrix s}{cmd:)}
{p 8 12 2}
{it:void}{bind: }
{cmd:st_replacematrix(}{it:string scalar name}{cmd:,}
{it:real matrix X}{cmd:)}
{p 4 8 2}
where
{p 8 12 2}
1. All functions allow {it:name} to be
{p_end}
{p 16 20 2}
a. global matrix name such as {cmd:"mymatrix"}
{p_end}
{p 16 20 2}
b. {cmd:r()} matrix such as {cmd:"r(Z)"}
{p_end}
{p 16 20 2}
c. {cmd:e()} matrix such as {cmd:"e(V)"}
{p 8 12 2}
2.
{cmd:st_matrix(}{it:name}{cmd:)} returns J(0,0,.)
if the matrix does not exist.
{p 8 12 2}
3.
The contents of {cmd:r()} and {cmd:e()} may be replaced
except for the estimation results {cmd:e(b)} and {cmd:e(V)}.
{p 8 12 2}
4.
{cmd:st_matrix(}{it:name}{cmd:,} {it:X}{cmd:)}
deletes the specified Stata matrix if {it:X}==J(0,0,.).
{title:Description}
{p 4 4 2}
{cmd:st_matrix(}{it:name}{cmd:)} returns the contents of Stata's matrix
{it:name}, or it returns J(0,0,.) if the matrix does not exist.
{p 4 4 2}
{cmd:st_matrixrowstripe(}{it:name}{cmd:)} returns the row stripe associated
with the matrix {it:name}, or it returns J(0,2,"") if the matrix does not
exist.
{p 4 4 2}
{cmd:st_matrixcolstripe(}{it:name}{cmd:)} returns the column stripe
associated with the matrix {it:name}, or it returns J(0,2,"") if the
matrix does not exist.
{p 4 4 2}
{cmd:st_matrix(}{it:name}, {it:X}{cmd:)} sets or resets the contents of the
Stata matrix {it:name} to be {it:X}. If the matrix did not previously exist,
a new matrix is created. If the matrix did exist, the new contents replace
the old. Either way, the row and column stripes are also reset to contain
"r1", "r2", ..., and "c1", "c2", ...
{p 4 4 2}
{cmd:st_matrix(}{it:name}, {it:X}{cmd:)}
deletes the Stata matrix {it:name} when {it:X} is 0 {it:x} 0:
{cmd:st_matrix(}{it:name}{cmd:, J(0,0,.))} deletes Stata matrix {it:name}
or does nothing if {it:name} does not exist.
{p 4 4 2}
{cmd:st_matrixrowstripe(}{it:name}, {it:s}{cmd:)} and
{cmd:st_matrixcolstripe(}{it:name}, {it:s}{cmd:)}
change the contents to be {it:s} of the row and column stripe
associated with the already existing Stata matrix {it:name}.
In either case, {it:s} must be {it:n} {it:x} 2, where {it:n} = the number of
rows (columns) of the underlying matrix.
{p 4 4 2}
{cmd:st_matrixrowstripe(}{it:name}, {it:s}{cmd:)} and
{cmd:st_matrixcolstripe(}{it:name}, {it:s}{cmd:)}
reset the row and column stripe to be "r1", "r2", ..., and
"c1", "c2", ..., when {it:s} is 0 {it:x} 2 (i.e., J(0,2,"")).
{p 4 4 2}
{cmd:st_replacematrix(}{it:name}, {it:X}{cmd:)} resets the contents of the
Stata matrix {it:name} to be {it:X}. The existing Stata matrix must have
the same number of rows and columns as {it:X}. The row stripes and column
stripes remain unchanged.
{title:Remarks}
{p 4 4 2}
Remarks are presented under the headings
{bf:Processing Stata's row and column stripes}
{bf:Stata's matsize is irrelevant}
{p 4 4 2}
Also see {bf:{help mf_st_global:[M-5] st_global()}}
and
{bf:{help mf_st_rclear:[M-5] st_rclear()}}.
{title:Processing Stata's row and column stripes}
{p 4 4 2}
Both row stripes and column stripes are presented in the same way:
each row of {it:s} represents the {it:eq}{cmd::}{it:op}{cmd:.}{it:name}
associated with a row or column of the underlying matrix. The first column
records {it:eq}, and the second column records {it:op}{cmd:.}{it:name}. For
instance, given the following Stata matrix
eq2: eq2:
L. L.
turn turn turn turn
mpg 1 2 3 4
L.mpg 5 6 7 8
eq2:mpg 9 10 11 12
eq2:L.mpg 13 14 15 16
{p 4 4 2}
{cmd:st_matrixrowstripe(}{it:name}{cmd:)} returns the 4 {it:x} 2 string matrix
"" "mpg"
"" "L.mpg"
"eq2" "mpg"
"eq2" "L.mpg"
{p 4 4 2}
and {cmd:st_matrixcolstripe(}{it:name}{cmd:)} returns
"" "turn"
"" "L.turn"
"eq2" "turn"
"eq2" "L.turn"
{title:Stata's matsize is irrelevant}
{p 4 4 2}
Matrices in Stata are limited to {helpb matsize}, a number between 40 and
11,000. Mata matrices have no such limits.
{p 4 4 2}
When getting a matrix, the matsize limit plays no role.
{p 4 4 2}
When putting a matrix, the matsize limit is ignored; meaning that, to
use the matrix in Stata, the user may have to reset {cmd:matsize} or, if the
matrix is too large, the user may not be able to use the matrix at all.
{title:Conformability}
{cmd:st_matrix(}{it:name}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:result}: {it:m x n} (0 {it:x} 0 if not found)
{cmd:st_matrixrowstripe(}{it:name}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:result}: {it:m x} 2 (0 {it:x} 2 if not found)
{cmd:st_matrixcolstripe(}{it:name}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:result}: {it:n x} 2 (0 {it:x} 2 if not found)
{cmd:st_matrix(}{it:name}{cmd:,} {it:X}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:X}: {it:r x c} (0 {it:x} 0 means delete)
{it:result}: {it:void}
{cmd:st_matrixrowstripe(}{it:name}{cmd:,} {it:s}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:s}: {it:r x} 2 (0 {it:x} 2 means default "r1", "r2", ...)
{it:result}: {it:void}
{cmd:st_matrixcolstripe(}{it:name}{cmd:,} {it:s}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:s}: {it:c x} 2 (0 {it:x} 2 means default "c1", "c2", ...)
{it:result}: {it:void}
{cmd:st_replacematrix(}{it:name}{cmd:,} {it:X}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:X}: {it:m x n} (0 {it:x} 0 means delete)
{it:result}: {it:void}
{title:Diagnostics}
{p 4 4 2}
{cmd:st_matrix(}{it:name}{cmd:)},
{cmd:st_matrixrowstripe(}{it:name}{cmd:)}, and
{cmd:st_matrixcolstripe(}{it:name}{cmd:)}
abort with error if {it:name} is malformed.
In addition,
{p 8 12 2}
1.
{cmd:st_matrix(}{it:name}{cmd:)}
returns J(0,0,.) if Stata matrix {it:name} does not exist.
{p 8 12 2}
2.
{cmd:st_matrixrowstripe(}{it:name}{cmd:)} and
{cmd:st_matrixcolstripe(}{it:name}{cmd:)}
return J(0,2,"") if Stata matrix {it:name} does not exist. There is no
possibility that matrix {it:name} might exist and not have row and column
stripes.
{p 4 4 2}
{cmd:st_matrix(}{it:name}{cmd:,} {it:X}{cmd:)},
{cmd:st_matrixrowstripe(}{it:name}{cmd:,} {it:s}{cmd:)}, and
{cmd:st_matrixcolstripe(}{it:name}{cmd:,} {it:s}{cmd:)}
abort with error if {it:name} is malformed.
In addition,
{p 8 12 2}
1.
{cmd:st_matrixrowstripe(}{it:name}{cmd:,} {it:s}{cmd:)}
aborts with error if {cmd:rows(}{it:s}{cmd:)} is not equal to the
number of rows of Stata matrix {it:name} and
{cmd:rows(}{it:s}{cmd:)}!=0, or if {cmd:cols(}{it:s}{cmd:)}!=2.
{p 8 12 2}
2.
{cmd:st_matrixcolstripe(}{it:name}{cmd:,} {it:s}{cmd:)}
aborts with error if {cmd:rows(}{it:s}{cmd:)} is not equal to the
number of columns of Stata matrix {it:name} and
{cmd:rows(}{it:s}{cmd:)}!=0, or if {cmd:cols(}{it:s}{cmd:)}!=2.
{p 4 4 7}
{cmd:st_replacematrix(}{it:name}{cmd:,} {it:X}{cmd:)}
aborts with error if
Stata matrix {it:name} does not have the same number of rows and
columns as {it:X}.
{cmd:st_replacematrix()} also aborts with error if
Stata matrix {it:name} does not exist and
{it:X}!=J(0,0,.); {cmd:st_replacematrix()} does nothing if
the matrix does not exist and {it:X}==J(0,0,.).
{cmd:st_replacematrix()} aborts with error if {it:name} is malformed.
{title:Source code}
{p 4 4 2}
Functions are built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] st_matrix()}
{p 4 13 2}
Online: help for
{bf:{help mf_st_rclear:[M-5] st_rclear()}};
{bf:{help m4_stata:[M-4] stata}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -