📄 matlist.ado
字号:
if "`keepcoleq'" == "" {
// increase j2 to maximal value that still fits
local trymore = (`j2'<`c') & (`jwidth'<`linesize')
while `trymore' {
local j2p = `j2'+1
local jwidthp = `jwidth' + `sep`j2p'' + `Wcol`j2p''
if `jwidthp' <= `linesize' {
local j2 = `j2p'
local jwidth = `jwidthp'
local trymore = `j2' < `c'
}
else {
local trymore = 0
}
}
}
else {
// increase j2 to maximal value with same eq
local trymore = (`j2'<`c') & (`jwidth'<`linesize')
while `trymore' {
local j2p = `j2'+1
local jwidthp = `jwidth' + `sep`j2p'' + `Wcol`j2p''
if (`jwidthp' <= `linesize') & ///
("`ceq`j1''" == "`ceq`j2p''") {
local j2 = `j2p'
local jwidth = `jwidthp'
local trymore = `j2' < `c'
}
else {
local trymore = 0
}
}
// we have j1..j2; add only "complete" equations
local trymore = (`j2'<`c') & (`jwidth'<`linesize')
while `trymore' {
local j3 = `j2'+1
local j4 = `j3'
while "`ceq`j3''"=="`ceq`j4''" & `j4'<=`c' {
local ++j4
}
local --j4
// width including j3..j4
local jwidthp = `jwidth'
forvalues j = `j3'/`j4' {
local jwidthp = `jwidthp' + `sep`j''+`Wcol`j''
}
// add if extra equation fits
if `jwidthp' < `linesize' {
local j2 = `j4'
local jwidth = `jwidthp'
local trymore = (`j2' < `c')
}
else {
local trymore = 0
}
}
}
// horizonal line : top-style
if `rsep`r1'' {
dis as txt "{space `bsep`c1''}`TLch`sep`c1'''" _c
if `show_rownames' {
dis "{hline `Wcol0'}`TCch`sep`c1p1'''" _c
}
forvalues j = `j1' / `=`j2'-1' {
local jp1 = `j'+1
dis "{hline `Wcol`j''}`TCch`sep`jp1'''" _c
}
dis "{hline `Wcol`j2''}`TRch`sep`cp1'''"
}
// display header for columns j1..j2
// (a) column equations
if `show_colnames' & `show_coleq' {
dis as txt "{space `bsep`c1''}`Vch`sep`c1'''" _c
if `show_rownames' {
dis "{space `Wcol0'}`Vch`sep`c1p1'''" _c
}
if "`coleq_method'" == "each" {
// repeat equation names above each column
forvalues j = `j1' / `j2' {
local jp1 = `j'+1
if `wcol`j'' > 4 {
local ceq = ///
abbrev("`ceq`j''", `wcol`j'')
}
else {
local ceq = ///
substr("`ceq`j''",1,`wcol`j'')
}
#del ;
dis as `colorcoleq'
`"{space `asep`j''}"'
`"{ralign `wcol`j'':`ceq'}"'
`"{space `bsep`jp1''}"'
as txt cond(`j'==`j2',
"`Vch`sep`cp1'''",
"`Vch`sep`jp1'''" ) _c ;
#del cr
}
dis
}
else if "`coleq_method'" == "first" {
// repeat eq names only when it first occurs
local ceqhold
forvalues j = `j1' / `j2' {
local jp1 = `j'+1
gettoken ceq ceqns : ceqns
if `"`ceq'"' != `"`ceqhold'"' {
if `wcol`j'' > 4 {
local ceqab = ///
abbrev(`"`ceq'"', `wcol`j'')
}
else {
local ceqab = ///
substr(`"`ceq'"',1,`wcol`j'')
}
#del ;
dis as `colorcoleq'
`"{space `asep`j''}"'
`"{lalign `wcol`j'':`ceqab'}"'
`"{space `bsep`jp1''}"' _c ;
#del cr
local ceqhold `ceq'
}
else {
dis as txt `"{space `Wcol`j''}"' _c
}
dis as txt cond(`j'==`j2', ///
`"`Vch`sep`cp1'''"', ///
`"`Vch`sep`jp1'''"') _c
}
dis
}
else if "`coleq_method'" == "combine" {
// combine columns with same equation name
// and display header above with ceq_align alignment
// column sep lines "inside" are not drawn
gettoken ceqhold ceqns : ceqns
local eqw = `wcol`j1''
local beq = `asep`j1''
forvalues j = `= `j1'+1' / `j2' {
gettoken ceq ceqns : ceqns
local jp1 = `j'+1
if `"`ceq'"' == `"`ceqhold'"' {
local eqw = `eqw' + `asep`j'' + ///
`sep`j'' + `bsep`jp1'' + `wcol`j''
}
else {
if `eqw' > 4 {
local ceqab = ///
abbrev(`"`ceqhold'"', `eqw')
}
else {
local ceqab = ///
substr(`"`ceqhold'"',1,`eqw')
}
#del ;
dis as `colorcoleq'
`"{space `beq'}"'
`"{`ceq_align' `eqw':`ceqab'}"'
`"{space `bsep`j''}"'
as txt
`"`Vch`sep`j'''"' _c ;
#del cr
local ceqhold `ceq'
local eqw = `wcol`j''
local beq = `asep`j''
}
}
if `eqw' > 4 {
local ceqab = abbrev(`"`ceqhold'"', `eqw')
}
else {
local ceqab = substr(`"`ceqhold'"',1,`eqw')
}
#del ;
dis as `colorcoleq'
`"{space `beq'}"'
`"{`ceq_align' `eqw':`ceqab'}"'
`"{space `bsep`cp1''}"'
as txt `"`Vch`sep`cp1'''"' ;
#del cr
}
else {
_stata_internalerror
}
}
// (b) column names
if `show_colnames' {
dis as txt "{space `bsep`c1''}`Vch`sep`c1'''" _c
if `show_rownames' {
dis `"{space `asep0'}"' ///
`"{ralign `wcol0':`rowtitle'}"' ///
`"{space `bsep1'}`Vch`sep`c1p1'''"' _c
}
forvalues j = `j1' / `j2' {
local jp1 = `j'+1
local cnj : word `j' of `cnames'
if `wcol`j'' > 4 {
local abvj = abbrev("`cnj'", `wcol`j'')
}
else {
local abvj = substr("`cnj'",1,`wcol`j'')
}
if "`underscore'" != "" {
local abvj = subinstr(`"`abvj'"',"_"," ",.)
}
#del ;
dis `"{space `asep`j''}"'
`"{`aligncolnames' `wcol`j'':`abvj'}"'
`"{space `bsep`jp1''}"'
as txt
cond(`j'==`j2',"`Vch`sep`cp1'''",
"`Vch`sep`jp1'''" ) _c ;
#del cr
}
dis
}
// display data columns j1..j2
local reqhold
local lowi = cond(`loweronly',`j1',1)
forvalues i = `lowi' / `r' {
if !`loweronly' {
local showhline = ///
`rsep`i'' & (`i'!=1 | `show_colnames')
}
else {
local showhline = cond(`i'==`lowi', ///
`rsep1' & `show_colnames', `rsep`i'')
}
if `showhline' {
dis as txt "{space `bsep`c1''}`CLch`sep`c1'''" _c
if `show_rownames' {
dis "{hline `Wcol0'}`CCch`sep`c1p1'''" _c
}
forvalues j = `j1' / `=`j2'-1' {
local jp1 = `j'+1
dis "{hline `Wcol`j''}`CCch`sep`jp1'''" _c
}
dis "{hline `Wcol`j2''}`CRch`sep`cp1'''"
}
// line with equation name
if (`show_rownames') & (`show_roweq') & ///
(`"`req`i''"' != `"`reqhold'"') {
if `wcol0' > 4 {
local reqab = abbrev(`"`req`i''"', `wcol0')
}
else {
local reqab = substr(`"`req`i''"',1,`wcol0')
}
#del ;
dis as txt
`"{space `bsep`c1''}"'
`"`Vch`sep`c1'''"'
`"{res:{lalign `Wcol0':`reqab'}}"'
`"`Vch`sep`c1p1'''"' _c ;
#del cr
forvalues j = `j1' / `=`j2'-1' {
local jp1 = `j'+1
dis "{space `Wcol`j''}`Vch`sep`jp1'''" _c
}
dis "{space `Wcol`j2''}`Vch`sep`cp1'''"
local reqhold `req`i''
}
// data lines
dis as txt "{space `bsep`c1''}`Vch`sep`c1'''" _c
if `show_rownames' {
dis `"{space `asep0'}"' ///
`"{ralign `wcol0':`rname`i''}"' ///
`"{space `bsep1'}`Vch`sep`c1p1'''"' _c
}
forvalues j = `j1' / `j2' {
#del ;
local ifcond =
(("`dotz'" != "") & (`m'[`i',`j']==.z))
|
((`loweronly') & (`j' > `i')) ;
#del cr
if `ifcond' {
local fmtm "{space `wcol`j''}"
}
else {
local fmtm : display `fmt`j'' `m'[`i',`j']
}
local jp1 = `j'+1
#del ;
dis "{space `asep`j''}"
"{`align`j'' `wcol`j'':{`mode`j'':{`font`j'':`fmtm'}}}"
"{space `bsep`jp1''}"
as txt
cond(`j'==`j2', "`Vch`sep`cp1'''",
"`Vch`sep`jp1'''") _c ;
#del cr
}
dis
}
// horizonal line : bottom-style
if `rsep`rp1'' {
dis as txt "{space `bsep`c1''}`BLch`sep`c1'''" _c
if `show_rownames' {
dis as txt "{hline `Wcol0'}`BCch`sep`c1p1'''" _c
}
forvalues j = `j1' / `=`j2'-1' {
local jp1 = `j'+1
dis "{hline `Wcol`j''}`BCch`sep`jp1'''" _c
}
dis "{hline `Wcol`j2''}`BRch`sep`cp1'''"
}
} // loop over blocks
end
// ----------------------------------------------------------------------------
// parsing subroutines
// ----------------------------------------------------------------------------
program NotAllowed
args optname value
if `"`value'"' != "" {
dis as err ///
`"option `optname' not allowed with rspec() and cspec()"'
exit 198
}
end
program ParseLines, sclass
local 0 ,`0'
syntax [, CElls COlumns COLTotal eq None Oneline ///
Rows RCTotal ROWTotal ]
local opt `cells' `columns' `coltotal' `eq' `none' `oneline' ///
`rows' `rctotal' `rowtotal'
if `:list sizeof opt' > 1 {
dis as err "lines() expects a single lstyle specification"
exit 198
}
sreturn clear
sreturn local lstyle `opt'
end
program ParseBorder, sclass
local 0 ,`0'
syntax [, Top Left Right Bottom COLumns ROWs ALL None ]
if "`all'" != "" {
local columns columns
local rows rows
}
if "`columns'" != "" {
local left left
local right right
}
if "`rows'" != "" {
local top top
local bottom bottom
}
sreturn clear
sreturn local border `top' `bottom' `left' `right'
end
program ParseNames, sclass
local 0 ,`0'
syntax [, All Columns Rows None ]
local opt `all' `columns' `rows' `none'
if "`opt'" == "" {
local opt all
}
opts_exclusive "`opt'" names
sreturn clear
sreturn local names `opt'
end
program ParseSHOWCOLEQ, sclass
local 0 ,`0'
syntax [, Each Combine First Lcombine Rcombine ]
local opt `each' `combine' `first' `lcombine' `rcombine'
if "`opt'" == "" {
local opt first
}
opts_exclusive "`opt'" showcoleq
sreturn clear
sreturn local showcoleq `opt'
end
program ParseCOLORCOLEQ, sclass
local 0 ,`0'
syntax [, Res Txt ]
local opt `res' `txt'
if "`opt'" == "" {
local opt txt
}
opts_exclusive "`opt'" colorcoleq
sreturn clear
sreturn local colorcoleq `opt'
end
program ParseALIGNCOLNames, sclass
local 0 , `0'
syntax [, Center Ralign Lalign ]
local opt `center' `ralign' `lalign'
if "`opt'" == "" {
local opt ralign
}
opts_exclusive "`opt'" aligncolnames
sreturn clear
sreturn local aligncolnames `opt'
end
// parses off from input the specification of the next column
// returning in rest the remainder of the input
//
program GetColSpec
args fmt font mode wcol align rest input ///
Dfont Dmode Dalign
local Font `Dfont'
local Mode `Dmode'
local Align `Dalign'
gettoken spec Rest : input , parse("o|&") // note: no space
while trim(`"`spec'"') != "" {
gettoken tok spec : spec
local tok = trim("`tok'")
if substr(`"`tok'"',1,1) == "%" {
local Fmt `tok'
}
else if substr(`"`tok'"',1,1) == "w" {
local Wcol = substr("`tok'",2,.)
confirm integer number `Wcol'
}
else if "`tok'" == "s" {
local Font sf
}
else if "`tok'" == "b" {
local Font bf
}
else if "`tok'" == "i" {
local Font it
}
else if "`tok'" == "L" {
local Align lalign
}
else if "`tok'" == "R" {
local Align ralign
}
else if "`tok'" == "C" {
local Align center
}
else if "`tok'" == "t" {
local Mode txt
}
else if "`tok'" == "r" {
local Mode res
}
else if "`tok'" == "e" {
local Mode err
}
else if "`tok'" == "c" {
local Mode cmd
}
else {
dis as err `"option cspec() invalid; "' ///
`"unknown input `tok'"'
exit 198
}
}
c_local `fmt' `Fmt'
c_local `font' `Font'
c_local `mode' `Mode'
c_local `wcol' `Wcol'
c_local `align' `Align'
c_local `rest' `Rest'
end
// parses off the information for the next separator
//
program GetSepSpec
args bsep /// number of spaces before
sep /// 1 specifies hline, otherwise 0
asep /// number of spaces after
rest /// remainder of input after parsing of separator
///
input /// input string
bsep_d0 /// default: bsep if sep==0
asep_d0 /// default: asep if sep==0
bsep_d1 /// default: bsep if sep==1
asep_d1 // default: asep if sep==1
gettoken tok input : input, parse(" |&")
if substr(`"`tok'"',1,1) == "o" {
local b = substr(`"`tok'"',2,.)
confirm integer number `b'
gettoken tok input : input, parse(" |&")
}
if !inlist(`"`tok'"',"&","|") {
dis as err `"& or | expected, `tok' found"'
exit 198
}
local s = ("`tok'" == "|")
gettoken tok : input, parse(" |&")
if substr(`"`tok'"',1,1) == "o" {
gettoken tok input : input, parse(" |&")
local a = substr(`"`tok'"',2,.)
confirm integer number `a'
}
if ("`b'" == "") local b = cond(`s',`bsep_d1',`bsep_d0')
if ("`a'" == "") local a = cond(`s',`asep_d1',`asep_d0')
c_local `bsep' `b'
c_local `sep' `s'
c_local `asep' `a'
c_local `rest' `input'
end
exit
Future extensions
cspec: compact syntax to declare formatting of multiple columns at once
rspec: default to "one line"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -