📄 matlist.ado
字号:
*! version 1.0.3 04feb2005
program matlist
version 8
#del ;
syntax anything(id="matrix name or matrix expression" name=M)
[,
// options of matrix list
TITle(str) // title to be displayed
TINDent(numlist integer max=1 >=0)
ROWtitle(str) // column header for row names
NAMes2(str) //
noNAMes // no row/culumn names
SHOWCOLEQ(str) // how to deal with column eqns
COLORCOLEQ(str) // color for column equations
KEEPCOLEQ // keeps columns of eqn together
ALIGNCOLNames(str) // how column names are aligned
noBlank // supresses first blank line
noHAlf // display all, even if symmetric
noHeader // allowed, but silently ignored
nodotz // display .z as blanks
UNDERscore // convert _ to blanks in labels
LINESIZE(numlist integer max=1 >=40 <=255) // linesize
// detailed formattng per column
CSPec(str) // column specifications
RSPec(str) // row specifications
// format styles
LINes(str)
FORmat(str)
TWidth(numlist integer max=1 >=5)
LEFT(numlist integer max=1 >=0)
RIGHT(numlist integer max=1 >=0)
BORder
BORder2(str)
// misc
DEBUG // undocumented
] ;
#del cr
tempname m
matrix `m' = `M'
// handling of stripes: names and equations -----------------------------------
if "`names'" != "" & `"`names2'"' != "" {
dis as err "names and names() are exclusive"
exit 198
}
if "`names'" != "" {
local show_rownames = 0
local show_colnames = 0
}
else {
ParseNames `names2'
local show_rownames = inlist("`s(names)'", "all", "rows")
local show_colnames = inlist("`s(names)'", "all", "columns")
}
local c1 = 1 - `show_rownames'
local c1p1 = `c1'+1
local c = colsof(`m')
local cp1 = `c'+1
local r1 = 1 - `show_colnames'
local r1p1 = `r1'+1
local r = rowsof(`m')
local rp1 = `r'+1
local reqns : roweq `m', quote
local show_roweq = (`"`:list uniq reqns'"' != `""_""')
local ceqns : coleq `m', quote
local show_coleq = (`"`:list uniq ceqns'"' != `""_""')
if !`show_coleq' {
if "`keepcoleq'" != "" {
dis as err "column equations not found; " ///
"option keepcoleq invalid"
exit 198
}
if "`colorcoleq'" != "" {
dis as err "column equations not found; " ///
"option colorcoleq() invalid"
exit 198
}
if `"`coleq'"' != "" {
dis as err "column equations not found; " ///
"option coleq() invalid"
exit 198
}
}
ParseSHOWCOLEQ `showcoleq'
local coleq_method `s(showcoleq)'
ParseCOLORCOLEQ `colorcoleq'
local colorcoleq `s(colorcoleq)'
ParseALIGNCOLNames `aligncolnames'
local aligncolnames `s(aligncolnames)'
// misc
if `"`linesize'"' == "" {
local linesize c(linesize)
}
// showlower (for symmetric matrices only)
local loweronly = 0
if `r' == `c' {
local loweronly = issym(`m') & ("`half'" == "")
}
/* ----------------------------------------------------------------------------
cspec() == column formatting
s_spec [c_spec s_spec]*
c_spec: [w#] [b|i|s] [c|e|r|t] %fmt
s_spec: [o#]{|&}[o#]
columns of the table are indexed
where 0 = text
j = column j of the matrix j=1..c
column separators are indexed 0/1..c+1
where j is the separator before column j
and c+1 is the separator after the last column
o# denotes the number of spaces before/after separator
defaults to 1 "inside" table and to 0 on the outside.
macro description
---------------------------------------------------------------
fmt# display format for column #
font# font (bf sf it) for column #
mode# color of column #
wcol# width of column #
align# alignment of column #
bsep# number of leading spaces in colsep #
asep# number of trailing spaces in colsep #
sep# line 0/1 in colsep #
wsep# width of colsep #
-------------------------------------------------------------------
rspec() = row formatting options ([&-]*)
rows of the table are indexed
where 0 = text
i = row i of the matrix i=1..r
macro description
---------------------------------------------------------------
rsep<i> i=0 before text row with column headers
i=1 before numerical row 1
...
i=r before numerical row r (last row)
i=r+1 after numerical row r (last row)
----------------------------------------------------------------------------
*/
if `"`rspec'`cspec'"' != "" {
// style options not allowed
NotAllowed lines() `"`lines'"'
NotAllowed format() `"`format'"'
NotAllowed twidth() `"`twidth'"'
NotAllowed left() `"`left'"'
NotAllowed right() `"`right'"'
NotAllowed border `"`border'"'
// both rspec() and cspec() expected
if `"`rspec'"' == "" {
dis as err "rspec() required with cspec()"
exit 198
}
if `"`cspec'"' == "" {
dis as err "cspec() required with rspec()"
exit 198
}
// parse cspec() -- column specifications
local cspec0 `cspec'
local dflt_sep 0 0 0 1
// column with row names
if `show_rownames' {
GetSepSpec bsep0 sep0 asep0 cspec0 ///
`"`cspec0'"' `dflt_sep'
GetColSpec fmt0 font0 mode0 wcol0 ///
align0 cspec0 `"`cspec0'"' sf txt ralign
local junk : display `fmt0' "a"
local dflt_sep 1 1 1 1
}
// numerical columns
forvalues j = 1 / `c' {
GetSepSpec bsep`j' sep`j' asep`j' cspec0 ///
`"`cspec0'"' `dflt_sep'
GetColSpec fmt`j' font`j' mode`j' wcol`j' ///
align`j' cspec0 `"`cspec0'"' sf res ralign
local junk : display `fmt`j'' 1
local dflt_sep 1 1 1 1
}
// right-most separator
GetSepSpec bsep`cp1' sep`cp1' asep`cp1' cspec0 ///
`"`cspec0'"' 0 0 1 0
if `"`cspec0'"' != "" {
dis as err `"extraneous input in cspec(): `cspec0'"'
exit 198
}
// parse rspec() -- row specifications
local rspec0 `rspec'
forvalues i = `r1' / `rp1' {
// undocumented behavior: | is equivalent to -
gettoken tok rspec0 : rspec0, parse("&-| ")
if `"`tok'"' == "" {
dis as err "too few specifications in rspec()"
exit 198
}
else if !inlist("`tok'","&","-","|") {
dis as err "invalid horizontal separator " ///
"specification `tok'"
exit 198
}
local rsep`i' = ("`tok'" != "&")
}
if `"`rspec0'"' != "" {
dis as err `"extraneous input in rspec(): `rspec0'"'
exit 198
}
}
// display styles -------------------------------------------------------------
else {
ParseLines `lines'
local lstyle `s(lstyle)'
if "`border2'" != "" {
ParseBorder `border2'
local border_arg `s(border)'
}
else if "`border'" != "" {
local border_arg top bottom left right
}
if "`lstyle'" == "" {
local lstyle = cond(`show_roweq'|`show_coleq', ///
"eq" ,"oneline")
}
if (`"`left'"' == "") local left = 0
if (`"`right'"' == "") local right = 0
if (`"`twidth'"' == "") local twidth = 12
if `"`format'"' == "" {
local format %9.0g
}
else {
capture local junk : display `format' 1
if _rc {
dis as err "invalid %format `format'"
exit 120
}
}
if `show_rownames' {
local fmt0 %`twidth's
}
forvalues j = 1 / `c' {
local fmt`j' `format'
}
// initialize settings for all styles
if `show_rownames' {
local font0 sf
local mode0 txt
local align0 ralign
}
forvalues j = 1 / `c' {
local font`j' sf
local mode`j' res
local align`j' ralign
}
// separator: before table
local bsep`c1' = `left'
local sep`c1' = 0
local asep`c1' = 0
// separator: between numerical entries
forvalues j = `c1p1' / `c' {
local bsep`j' = 1
local sep`j' = 0
local asep`j' = 1
}
// separator: after numerical entries
local bsep`cp1' = 1
local sep`cp1' = 0
local asep`cp1' = `right'
forvalues i = `r1' / `rp1' {
local rsep`i' = 0
}
// adjust settings for display styles
if "`lstyle'" == "oneline" {
// the first row and column is divided off the rest
local asep0 = 0
local sep1 = `show_rownames'
local rsep1 = `show_colnames'
}
else if "`lstyle'" == "rowtotal" {
// the first and last row is divided off the rest
local asep0 = 0
local sep1 = `show_rownames'
local rsep1 = `show_colnames'
local rsep`r' = 1
}
else if "`lstyle'" == "coltotal" {
// the first and last column is divided off the rest
local sep1 = `show_rownames'
local rsep1 = `show_colnames'
local sep`c' = 1
}
else if "`lstyle'" == "rctotal" {
// the last row and column is divided off the rest
local asep0 = 0
local sep1 = `show_rownames'
local rsep1 = `show_colnames'
local rsep`r' = 1
local sep`c' = 1
}
else if "`lstyle'" == "cells" {
forvalues j = `c1p1' / `c' {
local sep`j' = 1
}
forvalues i = `r1p1' / `r' {
local rsep`i' = 1
}
}
else if "`lstyle'" == "columns" {
forvalues j = `c1p1' / `c' {
local sep`j' = 1
}
local rsep`r1p1' = `show_colnames'
}
else if "`lstyle'" == "rows" {
forvalues i = `r1p1' / `r' {
local rsep`i' = 1
}
local sep`c1p1' = `show_rownames'
}
else if "`lstyle'" == "eq" {
local sep`c1p1' = `show_rownames'
local rsep`r1p1' = `show_colnames'
// add vertical lines between equations
local ceq : coleq `m' , quote
gettoken eqhold ceq : ceq
forvalues j = 2 / `c' {
gettoken eq ceq : ceq
if `"`eq'"' != `"`eqhold'"' {
local sep`j' = 1
local eqhold `eq'
}
}
// add horizontal lines between equations
local req : roweq `m' , quote
gettoken eqhold req : req
forvalues i = 2 / `r' {
gettoken eq req : req
if `"`eq'"' != `"`eqhold'"' {
local rsep`i' = 1
local eqhold `eq'
}
}
}
else if "`lstyle'" == "none" {
// nothing
}
else {
_stata_internalerror
}
// border
if index("`border_arg'", "top") {
local rsep`r1' = 1 // before first
}
if index("`border_arg'", "bottom") {
local rsep`rp1' = 1 // after last
}
if index("`border_arg'", "left") {
local sep`c1' = 1 // before first
local asep`c1' = 1
}
if index("`border_arg'", "right") {
local sep`cp1' = 1
local bsep`cp1' = 1 // after last
}
}
// initialize stuff before drawing table --------------------------------------
// wcol<j> width of column j, excl white space before/after sep
// Wcol<j> width of column j, incl white space before/after sep
if `show_rownames' {
if ("`wcol0'" == "") local wcol0 0
local wcol0 = max(`wcol0',length(`"`:display `fmt0' "a"'"'))
local Wcol0 = `asep0' + `wcol0' + `bsep1'
}
forvalues j = 1 / `c' {
if ("`wcol`j''" == "") local wcol`j' 0
local temp : display `fmt`j'' 1
local wcol`j' = max(`wcol`j'',length(`"`temp'"'))
local Wcol`j' = `asep`j'' + `wcol`j'' + `bsep`=`j'+1''
}
// the drawing charcaters to be used if a line is wanted.
// The macros with extension 0 are referenced in case no line
// is needed; these should evaluate to "nothing".
local Vch1 "{c |}" // Vertical bar
local TLch1 "{c TLC}" // Top Left
local CLch1 "{c LT}" // Center Left
local BLch1 "{c BLC}" // Bottom Left
local TCch1 "{c TT}" // Top Center
local CCch1 "{c +}"
local BCch1 "{c BT}"
local TRch1 "{c TRC}" // Top Right
local CRch1 "{c RT}"
local BRch1 "{c BRC}"
// prepare string elements of table
// abbreviated strings to be displayed in first column
if `show_rownames' {
local rowtitle = substr(`"`rowtitle'"',1,`wcol0')
local rnames : rownames `m'
forvalues i = 1 / `r' {
gettoken rn rnames : rnames
local rname`i' = abbrev(`"`rn'"',`wcol0')
if "`underscore'" != "" {
local rname`i' = ///
subinstr(`"`rname`i''"',"_"," ",.)
}
}
}
local cnames : colnames `m'
if `"`reqns'"' != "" {
forvalues i = 1 / `r' {
gettoken req`i' reqns : reqns
}
}
// for column headers: merging within equation names
if "`coleq_method'" == "combine" {
local coleq_method combine
local ceq_align rcenter
}
else if "`coleq_method'" == "lcombine" {
local coleq_method combine
local ceq_align lalign
}
else if "`coleq_method'" == "rcombine" {
local coleq_method combine
local ceq_align ralign
}
// debug ----------------------------------------------------------------------
if "`debug'" != "" {
dis as txt _n "Settings: "_n
forvalues j = `c1' / `c' {
#del ;
dis as txt "column `j': fmt={res:`fmt`j''} "
" font={res:`font`j''} "
" mode={res:`mode`j''} "
" align={res:`align`j''} "
" wcol={res:`wcol`j''} "
" Wcol={res:`Wcol`j''}" ;
#del cr
}
dis
forvalues j = 0 / `cp1' {
#del ;
dis as txt "Column sep `j':"
" bsep=" %1s "`bsep`j''"
" sep=" %1s "`sep`j''"
" asep=" %1s "`asep`j''" ;
#del cr
}
dis
forvalues i = 0 / `rp1' {
dis as txt " Row sep `i': rsep=`rsep`i''"
}
}
// ----------------------------------------------------------------------------
// output!
// ----------------------------------------------------------------------------
// title and header
if "`blank'" == "" {
display
}
if `"`title'"' != "" {
if "`tindent'" == "" {
local tindent = 0 // `bsep`c1''
}
dis as txt `"{p `tindent' `tindent' 2}`title'{p_end}"' _n
}
// table, wrapping columns if necessary ---------------------------------------
// tokenize column equations
local j = 0
foreach eq of local ceqns {
local ceq`++j' `eq'
}
local j2 = 0
while `j2' < `c' {
if (`j2' > 0) display
// display columns j1..j2 (boundaries included, row names excluded)
//
// at least column is displayed, j2>=j1, even if it does not fit
//
// if keepcoleq, equations are kept together if possible.
// continue where we left off in previous block
local j1 = `j2'+1
local j1p1 = `j1'+1
// at least one column (j1=j2)
local j2 = `j1'
local jwidth = `bsep`c1''+`sep`c1''+`Wcol`j1''+`sep`cp1''+`asep`cp1''
if `show_rownames' {
local jwidth = `jwidth' + `Wcol0' + `sep1'
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -