⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2_subscripts.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
📖 第 1 页 / 共 2 页
字号:
{smcl}
{* 25mar2005}{...}
{cmd:help m2 subscripts}
{hline}
{* index subscripts}{...}
{* index list subscripts}{...}
{* index range subscripts}{...}

{title:Title}

{p 4 4 2}
{hi:[M-2] subscripts -- Use of subscripts}


{title:Syntax}

	{it:x}{cmd:[}{it:real vector r}{cmd:,} {it:real vector c}{cmd:]}

	{it:x}{cmd:[|}{it:real matrix sub}{cmd:|]}


{p 4 4 2}
Subscripts may be used on the left or right of the equal-assignment 
operator.


{title:Description}

{p 4 4 2}
Subscripts come in two styles.  

{p 4 4 2}
In {cmd:[}{it:subscript}{cmd:]} syntax -- called list subscripts -- an
element or a matrix is specified:

	{cmd:x[1,2]}                  the 1,2 element of {it:x}; a scalar

        {cmd:x[(1\3\2), (4,5)]}       the 3 {it:x} 2 matrix composed of rows 1, 3, and 2
{col 33}and columns 4 and 5 of {it:x}:
{col 42}{c TLC}            {c TRC}
{col 42}{c |} {it:x_14  x_15} {c |}
{col 42}{c |} {it:x_34  x_35} {c |}
{col 42}{c |} {it:x_24  x_25} {c |}
{col 42}{c BLC}            {c BRC}

{p 4 4 2}
In {cmd:[|}{it:subscript}{cmd:|]} syntax -- called range subscripts -- an
element or a contiguous submatrix is specified

	{cmd:x[|1,2|]}                same as {cmd:x[1,2]}; a scalar

	{cmd:x[|2,3 \ 4,7|]}          3 {it:x} 4 submatrix of {it:x}:
{col 42}{c TLC}                              {c TRC}
{col 42}{c |} {it:x_23  x_24  x_25  x_26  x_27} {c |}
{col 42}{c |} {it:x_33  x_34  x_35  x_36  x_37} {c |}
{col 42}{c |} {it:x_43  x_44  x_45  x_46  x_47} {c |}
{col 42}{c BLC}                              {c BRC}

{p 4 4 2}
Both style subscripts may be used in expressions and may be used on the
left-hand side of the equal-assignment operator.


{title:Remarks}

{p 4 4 2}
Remarks are presented under the headings

	{bf:List subscripts}
	{bf:Range subscripts}
	{bf:When to use list subscripts and when to use range subscripts}
	{bf:A fine distinction}


{title:List subscripts}

{p 4 4 2}
List subscripts -- also known simply as subscripts -- are obtained 
when you enclose the subscripts in square brackets, {cmd:[} and {cmd:]}.
List subscripts come in two basic forms:

{col 9}{it:x}{cmd:[}{it:ivec}{cmd:,}{it:jvec}{cmd:]}{...}
{col 33}matrix composed of rows {it:ivec} and columns {it:jvec}
{col 33}of matrix {it:x}

{col 9}{it:v}{cmd:[}{it:kvec}{cmd:]}{...}
{col 33}vector composed of elements {it:kvec} of vector {it:v}

{p 4 4 2}
where {it:ivec}, {it:jvec}, {it:kvec} may be a vector or a scalar, 
so the two basic forms include

{col 9}{it:x}{cmd:[}{it:i}{cmd:,}{it:j}{cmd:]}{...}
{col 33}scalar {it:i},{it:j} element

{col 9}{it:x}{cmd:[}{it:i}{cmd:,}{it:jvec}{cmd:]}{...}
{col 33}rowvector of row {it:i}, elements {it:jvec}

{col 9}{it:x}{cmd:[}{it:ivec}{cmd:,}{it:j}{cmd:]}{...}
{col 33}colvector of column {it:j}, elements {it:ivec}

{col 9}{it:v}{cmd:[}{it:k}{cmd:]}{...}
{col 33}scalar {it:k}th element of vector {it:v}

{p 4 4 2}
In addition, missing value may be specified to mean all the rows or 
all the columns:

{col 9}{it:x}{cmd:[}{it:i}{cmd:,.]}{...}
{col 33}rowvector of row {it:i} of {it:x}
{col 9}{it:x}{cmd:[.,}{it:j}]{...}
{col 33}colvector of column {it:j} of {it:x}

{col 9}{it:x}{cmd:[}{it:ivec}{cmd:,.]}{...}
{col 33}matrix of rows {it:ivec}, all columns
{col 9}{it:x}{cmd:[.,}{it:jvec}]{...}
{col 33}matrix of columns {it:jvec}, all rows

{col 9}{it:x}{cmd:[.,.]}{...}
{col 33}the entire matrix

{p 4 4 2} 
Finally, Mata assumes missing value when you omit the argument entirely:

{col 9}{it:x}{cmd:[}{it:i}{cmd:,]}{...}
{col 33}same as {it:x}{cmd:[}{it:i}{cmd:,.]}
{col 9}{it:x}{cmd:[}{it:ivec}{cmd:,]}{...}
{col 33}same as {it:x}{cmd:[}{it:ivec}{cmd:,.]}
{col 9}{it:x}{cmd:[,}{it:j}{cmd:]}{...} 
{col 33}same as {it:x}{cmd:[.,}{it:j}]
{col 9}{it:x}{cmd:[,}{it:jvec}{cmd:]}{...} 
{col 33}same as {it:x}{cmd:[.,}{it:jvec}]
{col 9}{it:x}{cmd:[,]}{...}
{col 33}same as {it:x}{cmd:[.,.]}

{p 4 4 2}
Good style is to specify {it:ivec} as a colvector and {it:jvec} as a
rowvector, but that is not required:

{col 9}{it:x}{cmd:[(1\2\3), (1,2,3)]}{...}
{col 33}good style
{col 9}{it:x}{cmd:[(1,2,3), (1,2,3)]}{...}
{col 33}same as {it:x}{cmd:[(1\2\3), (1,2,3)]}
{col 9}{it:x}{cmd:[(1\2\3), (1\2\3)]}{...}
{col 33}same as {it:x}{cmd:[(1\2\3), (1,2,3)]}
{col 9}{it:x}{cmd:[(1,2,3), (1\2\3)]}{...}
{col 33}same as {it:x}{cmd:[(1\2\3), (1,2,3)]}

{p 4 4 2}
Similarly, good style is to specify {it:kvec} as a column when {it:v} is 
a column vector and to specify {it:kvec} as a row when {it:v} is a row vector,
but that is not required and what is returned is a column vector if {it:v} is
a column and a rowvector if {it:v} is a row:

{col 9}{it:rowv}{cmd:[(1,2,3)]}{...}
{col 33}good style for specifying row vector
{col 9}{it:rowv}{cmd:[(1\2\3)]}{...}
{col 33}same as {it:rowv}{cmd:[(1,2,3)]}

{col 9}{it:colv}{cmd:[(1\2\3)]}{...}
{col 33}good style for specifying column vector
{col 9}{it:colv}{cmd:[(1,2,3)]}{...}
{col 33}same as {it:colv}{cmd:[(1\2\3)]}

{p 4 4 2}
Subscripts may be used in expressions following a variable name:

        {cmd:first = list[1]}

	{cmd:multiplier = x[3,4]}
        
	{cmd:result = colsum(x[,j])}

{p 4 4 2}
Subscripts may be used following an expression to extract a submatrix 
from a result:

	{cmd:allneeded = invsym(x)[(1::4), .] * multiplier}

{p 4 4 2}
Subscripts may be used on the left-hand side of the equal-assignment 
operator:

        {cmd:x[1,1] = 1}

	{cmd:x[1,.] = y[3,.]}

        {cmd:x[(1::4), (1..4)] = I(4)}



{title:Range subscripts}

{p 4 4 2}
Range subscripts appear inside the difficult to type {cmd:[|} and {cmd:|]}
brackets.  Range subscripts come in four basic forms:

{col 9}{it:x}{cmd:[|}{it:i}{cmd:,}{it:j}{cmd:|]}{...}
{col 33}{it:i},{it:j} element; same result as {it:x}{cmd:[}{it:i}{cmd:,}{it:j}{cmd:]}

{col 9}{it:v}{cmd:[|}{it:k}{cmd:|]}{...}
{col 33}{it:k}th element of vector; same result as {it:v}{cmd:[}{it:k}{cmd:]}

{col 9}{it:x}{cmd:[|}{it:i}{cmd:,}{it:j} {cmd:\} {it:k}{cmd:,}{it:l}{cmd:|]}{...}
{col 33}submatrix, vector, or scalar formed using 
{col 33}({it:i},{it:j}) as top-left corner and ({it:k},{it:l}) as 
{col 33}bottom-right corner

{col 9}{it:v}{cmd:[|}{it:i} {cmd:\} {it:k}{cmd:|]}{...}
{col 33}subvector or scalar of elements {it:i} through {it:k};
{col 33}result is rowvector if {it:v} is rowvector, 
{col 33}colvector if {it:v} is colvector

{p 4 4 2}
Missing value may be specified for a row or column to mean all rows or 
all columns when a 1{it:x}2 or 1{it:x}1 subscript is specified: 

{col 9}{it:x}{cmd:[|}{it:i}{cmd:,.|]}{...}
{col 33}row {it:i} of {it:x}; same as {it:x}{cmd:[}{it:i}{cmd:,.]}
{col 9}{it:x}{cmd:[|.,}{it:j}{cmd:|]}{...}
{col 33}column {it:j} of {it:x}; same as {it:x}{cmd:[.,}{it:j}{cmd:]}
{col 9}{it:x}{cmd:[|.,.|]}{...}
{col 33}entire matrix; same as {it:x}{cmd:[.,.]}
{col 9}{it:v}{cmd:[|.|]}{...}
{col 33}entire vector; same as {it:v}{cmd:[.]}

{p 4 4 2}
In addition, missing may be specified to mean the number of rows 
or the number of columns of the matrix being subscripted when a 
2{it:x}2 subscript is specified:

{col 9}{it:x}{cmd:[|1,2 \ 4,.|]}{...}
{col 33}equivalent to {it:x}{cmd:[|1,2 \ 4,cols(}{it:x}{cmd:)|]}
{col 9}{it:x}{cmd:[|1,2 \ .,3|]}{...}
{col 33}equivalent to {it:x}{cmd:[|1,2 \ rows(}{it:x}{cmd:),3|]}
{col 9}{it:x}{cmd:[|1,2 \ .,.|]}{...}
{col 33}equivalent to {it:x}{cmd:[|1,2 \ rows(}{it:x}{cmd:),cols(}{it:x}{cmd:|]}


{p 4 4 2}
With range subscripts, what appears inside the square brackets is in all 
cases interpreted as a matrix expression, so in

	{cmd:sub = (1,2)}
	... {cmd:x[|sub|]} ...

{p 4 4 2}
{cmd:x[sub]} refers to {cmd:x[1,2]}.

{p 4 4 2}
Range subscripts may be used in all the same contexts as list subscripts; 
they may be used in expressions following a variable name

	{cmd:submat = result[|1,1\3,3|]}

{p 4 4 2}
they may be used to extract a submatrix from a calculated result

	{cmd:allneeded = invsym(x)[|1,1 \ 4,4|]}

{p 4 4 2}
and they may be used on the left-hand side of the equal-assignment operator:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -