cabiplot.ado
来自「是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到」· ADO 代码 · 共 277 行
ADO
277 行
*! version 1.0.1 16mar2005
program cabiplot
version 9.0
if "`e(cmd)'" != "ca" {
error 301
}
local md = `e(f)'
#del ;
syntax [,
noROW noCOlumn
DIM(numlist integer min=2 max=2 >=1 <=`md')
FActors(numlist integer min=2 max=2 >=1 <=`md') // undocumented
XNEGate YNEGate
MAXlength(numlist integer max=1 >0 <32)
ROWopts(string)
COLopts(string)
ASPECTratio(str)
*
] ;
#del cr
local gopt `options'
if ("`row'" == "norow" & "`column'" == "nocolumn") {
display as error ///
"options norow and nocolumn may not be combined"
exit 198
}
if "`dim'" != "" & "`factors'" != "" {
dis as err "dim() and factors() are synonyms"
exit 198
}
else if "`factors'" != "" {
local axes `factors'
}
else if "`dim'" != "" {
local axes `dim'
}
if "`axes'" != "" {
local ax1 : word 2 of `axes'
local ax2 : word 1 of `axes'
}
else {
local ax1 = 1
local ax2 = 2
}
if "`maxlength'" == "" {
local maxlength = 12
}
// Parse out row-suppopts
local 0 , `rowopts'
syntax , [SUPpopts(string) *]
local rowopts `options'
local rsupp_opt `suppopts'
// Parse out column-suppopts
local 0 , `colopts'
syntax , [SUPpopts(string) *]
local colopts `options'
local csupp_opt `suppopts'
.atk = .aspect_axis_toolkit.new
.atk.setPreferredLabelCount 6
_parse comma aspect_ratio placement : aspectratio
if "`aspect_ratio'" != "" {
confirm number `aspect_ratio'
.atk.setPreferredAspect `aspect_ratio'
.atk.setShowAspectTrue
}
else {
.atk.setAutoAspectTrue
}
// parsing is done
tempname R C
matrix `R' = e(TR)
matrix `C' = e(TC)
if colsof(`R') < 2 | colsof(`C') < 2 {
dis as txt "(no plot with dimension < 2)"
exit
}
local Rnames : rownames `R'
local Cnames : rownames `C'
local nr = rowsof(`R')
local nc = rowsof(`C')
if "`e(PR_supp)'" == "matrix" {
tempname SR
matrix `SR' = e(TR_supp)
local nr_supp = rowsof(`SR')
local SRnames : rownames `SR'
}
else {
local nr_supp = 0
}
if "`e(PC_supp)'" == "matrix" {
tempname SC
matrix `SC' = e(TC_supp)
local nc_supp = rowsof(`SC')
local SCnames : rownames `SC'
}
else {
local nc_supp = 0
}
local nrc = `nr' + `nr_supp' + `nc' + `nc_supp'
if `nrc' > c(N) {
preserve
quietly set obs `nrc'
}
// we store all coordinates and names in variables,
// even if we plot only rows or columns
tempvar dim1 dim2 class names
quietly gen `dim1' = .
quietly gen `dim2' = .
quietly gen `class' = .
quietly gen str32 `names' = ""
local ij = 0
forvalues i = 1/`nr' {
local ++ij
quietly replace `class' = 1 in `ij'
quietly replace `dim1' = `R'[`i',`ax1'] in `ij'
quietly replace `dim2' = `R'[`i',`ax2'] in `ij'
gettoken name Rnames : Rnames
quietly replace `names' = `"`name'"' in `ij'
}
forvalues i = 1/`nr_supp' {
local ++ij
quietly replace `class' = 2 in `ij'
quietly replace `dim1' = `SR'[`i',`ax1'] in `ij'
quietly replace `dim2' = `SR'[`i',`ax2'] in `ij'
gettoken name SRnames : SRnames
quietly replace `names' = `"`name'"' in `ij'
}
forvalues i = 1/`nc' {
local ++ij
quietly replace `class' = 3 in `ij'
quietly replace `dim1' = `C'[`i',`ax1'] in `ij'
quietly replace `dim2' = `C'[`i',`ax2'] in `ij'
gettoken name Cnames : Cnames
quietly replace `names' = `"`name'"' in `ij'
}
forvalues i = 1/`nc_supp' {
local ++ij
quietly replace `class' = 4 in `ij'
quietly replace `dim1' = `SC'[`i',`ax1'] in `ij'
quietly replace `dim2' = `SC'[`i',`ax2'] in `ij'
gettoken name SCnames : SCnames
quietly replace `names' = `"`name'"' in `ij'
}
if "`xnegate'" != "" {
quietly replace `dim1' = -`dim1'
}
if "`ynegate'" != "" {
quietly replace `dim2' = -`dim2'
}
quietly replace `names' = substr(`names',1,`maxlength')
quietly summarize `dim1' if !missing(`class') , meanonly
local xmin = r(min)
local xmax = r(max)
quietly summarize `dim2' if !missing(`class') , meanonly
local ymin = r(min)
local ymax = r(max)
local pr1 : display %4.1f `=100*el(e(Sv),1,`ax1')^2/e(inertia)'
local pr2 : display %4.1f `=100*el(e(Sv),1,`ax2')^2/e(inertia)'
.atk.getAspectAdjustedScales , xmin(`xmin') ///
xmax(`xmax') ymin(`ymin') ymax(`ymax')
local aspect aspectratio(`s(aspectratio)'`placement')
local rn `e(Rname)'
local cn `e(Cname)'
local symbolR O
local symbolC T
local symbolRS Oh
local symbolCS Th
local Ropt pstyle(p1) mlab(`names')
local Rscatter (scatter `dim2' `dim1' if `class'==1, ///
msymbol(`symbolR') `Ropt' `rowopts')
if `nr_supp' > 0 {
local Rscatter `Rscatter' ///
(scatter `dim2' `dim1' if `class'==2, ///
msymbol(`symbolRS') `Ropt' `rsupp_opt')
}
local Copt pstyle(p2) mlab(`names')
local Cscatter (scatter `dim2' `dim1' if `class'==3, ///
msymbol(`symbolC') `Copt' `colopts')
if `nc_supp' > 0 {
local Cscatter `Cscatter' ///
(scatter `dim2' `dim1' if `class'==4, ///
msymbol(`symbolCS') `Copt' `csupp_opt')
}
local xytitle xtitle("Dimension `ax1' (`pr1'%)") ///
ytitle("Dimension `ax2' (`pr2'%)")
local title Correspondence analysis biplot
local note1 coordinates in `e(norm)' normalization
local titles `xytitle' title(`title', span) ///
note(`"`note1'"', span)
// row and column points
if "`row'" != "norow" & "`column'" != "nocolumn" {
local ij = 1
local legend label(`ij++' `rn')
if `nr_supp' {
local legend `legend' label(`ij++' supplementary `rn')
}
local legend `legend' label(`ij++' `cn')
if `nc_supp' {
local legend `legend' label(`ij++' supplementary `cn')
}
local legend legend(`legend' span)
twoway `Rscatter' `Cscatter', ///
`s(scales)' `aspect' `legend' `titles' `gopt'
}
// only row points
else if "`row'" != "norow" {
if `nr_supp' {
local legend legend(label(1 `rn') ///
label(2 supplementary points for `rn') span)
}
twoway `Rscatter', ///
`s(scales)' `aspect' `legend' `titles' `gopt'
}
// only column points
else {
if `nc_supp' {
local legend legend(label(1 `cn') ///
label(2 supplementary points for `cn') span)
}
twoway `Cscatter', ///
`s(scales)' `aspect' `legend' `titles' `gopt'
}
end
exit
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?