📄 ca.ado
字号:
*! version 1.0.0 30mar2005
program ca, byable(onecall)
version 9.0
if replay() {
if _by() {
error 190
}
if "`e(cmd)'" != "ca" {
error 301
}
camat `0'
exit
}
if _by() {
by `_byvars'`_byrc0' : Estimate `0'
}
else {
Estimate `0'
}
end
program Estimate, eclass byable(recall)
#del ;
syntax varlist(numeric min=2 max=2) [if] [in] [fw aw iw]
[,
MISsing
DIMensions(passthru) // documented as dim()
FActors(passthru) // undocumented
NORMalize(passthru)
ROWSupp(str)
COLSupp(str)
// display options
noROWPoints
noCOLPoints
COMPact
PLOT
MAXlength(passthru)
];
#del cr
local display_opts `rowpoints' `colpoints' `compact' `plot' `maxlength'
// sample
local rowname : word 1 of `varlist'
local colname : word 2 of `varlist'
Integer `rowname'
Integer `colname'
marksample touse, novarlist
if "`missing'" == "" {
markout `touse' `varlist'
}
quietly count if `touse'==1
if r(N) == 0 {
error 2000
}
// form table to be analyzed
tempname P Rcoding Ccoding
if "`weight'" != "" {
local wght `"[`weight'`exp']"'
}
_bigtab `rowname' `colname' if `touse' `wght', `missing'
matrix `P' = r(F)
matrix `Rcoding' = r(rowcoding)'
matrix `Ccoding' = r(colcoding)
local nr = colsof(`Rcoding')
local nc = colsof(`Ccoding')
if `nr' == 1 {
dis as err "variable `rowname' does not vary"
exit 198
}
if `nc' == 1 {
dis as err "variable `colname' does not vary"
exit 198
}
LabList `colname' `Ccoding'
matrix colnames `P' = `r(lab)'
LabList `rowname' `Rcoding'
matrix rownames `P' = `r(lab)'
if "`rowsupp'" != "" {
confirm matrix `rowsupp'
if colsof(`rowsupp') != `nc' {
dis as err "rowsupp() invalid; " ///
"`rowsupp' should have `nc' columns"
exit 503
}
local rowsupp rowsupp(`rowsupp')
}
if "`colsupp'" != "" {
confirm matrix `colsupp'
if rowsof(`colsupp') != `nr' {
dis as err "colsupp() invalid; " ///
"`colsupp' should have `nr' rows"
exit 503
}
local colsupp colsupp(`colsupp')
}
// invoke camat on P
camat `P', nodisplay `dimensions' `factors' `normalize' ///
`rowsupp' `colsupp' rowname(`rowname') colname(`colname')
// repost
ereturn repost, esample(`touse')
ereturn matrix Rcoding = `Rcoding'
ereturn matrix Ccoding = `Ccoding'
ereturn local wtype `"`weight'"'
ereturn local wexp `"`exp'"'
ereturn local varlist `varlist'
// display
camat, `display_opts'
end
// LabList v RV
//
// returns in r(lab) a list of the value-labels of the values in the row vector
// RV according to the value labels associated with variable v. The labels are
// edited to make them suitable for use in matrix stripes.
// -- missing values are coded as strings (sysmiss, dota, ..., dotz).
// -- additional period are removed,
// -- spaces are replaced by underscores. and
// -- labels are truncated at 32 chars if necessary.
//
program LabList, rclass
args v RV
forvalues i = 1 / `=colsof(`RV')' {
local ll : label (`v') `=`RV'[1,`i']'
if "`ll'" == "." {
local ll sysmiss
}
else if length(`"`ll'"')==2 & substr(`"`ll'"',1,1)=="." {
local ll = "dot"+ substr(`"`ll'"',2,1)
}
else {
local ll : subinstr local ll "'" "", all
local ll : subinstr local ll " " "_", all
local ll : subinstr local ll "." "" , all
local ll = substr(`"`ll'"',1,32)
}
local lab `lab' `ll'
}
return local lab `lab'
end
// verifies that a variable is integer-valued
program Integer
args v
capture assert `v' == floor(`v') if !missing(`v')
if _rc {
dis as err "variable `v' is not integer-valued"
exit 198
}
end
exit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -