cs.ado
来自「是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到」· ADO 代码 · 共 599 行 · 第 1/2 页
ADO
599 行
* Call dispcs
dispcs "`Sf'" "`irr'" "`virr'" /*
*/ "`CRUDE'" "`C0'" "`C1'" /*
*/ "`pnum'" "`pden'" "`iz'" "`df'" /*
*/ "`or'" "`or0'" "`or1'" "`stdflg'" "`x2'" /*
begin options
*/ `hom' `pool' `jopt' type(`type') /*
*/ hdr2("`hdr2'") paren("`paren'") `crude'
ret add /* add return values from dispcs */
exit
}
quietly {
safesum `one' `w' /*
*/ if `cas' & `ex' & `use' & `by'==`by'[`i']
local a=r(sum)
safesum `one' `w' /*
*/ if `cas' & `ex'==0 & `use' & `by'==`by'[`i']
local b=r(sum)
safesum `one' `w' /*
*/ if `cas'==0 & `ex' & `use' & `by'==`by'[`i']
local c=r(sum)
safesum `one' `w' /*
*/ if `cas'==0 & `ex'==0 & `use' & `by'==`by'[`i']
local d=r(sum)
}
* csi `a' `b' `c' `d', level(`level') `col' `woolf'
local m1=`a'+`b'
local m0=`c'+`d'
local n1=`a'+`c'
local n0=`b'+`d'
local t=`n1'+`n0'
if `stdflg'==0 {
if "`type'"=="OR" {
local wgt=(`b'*`c')/`t'
local or=(`a'*`d')/(`b'*`c')
local P=(`a'+`d')/`t'
local Q=(`b'+`c')/`t'
local R=(`a'*`d')/`t'
local S=(`b'*`c')/`t'
local SPR=`SPR'+`P'*`R'
local SR=`SR'+`R'
local SPSQR=`SPSQR'+`P'*`S'+`Q'*`R' /*sic*/
local SS=`SS'+`S'
local SQS=`SQS'+`Q'*`S'
local SXnum=`SXnum'+`a'-(`n1'*`m1')/`t'
local SXden=`SXden'+/*
*/ (`n1'*`n0'*`m1'*`m0')/((`t')^2*(`t'-1))
global S_4
ret local lb_rd /* -ret drop- */
if "`fast'"=="" {
_crcor `a' `b' `c' `d' `level' /*
*/ `woolf' `tb'
local or0 = r(lb)
local or1 = r(ub)
}
if `t' != 0 {
local Sor=`Sor'+(`a'*`d')/`t'
}
}
else {
local wgt=(`b'*`n1')/`t'
_crcrr `a' `b' `c' `d' `level' `tb'
local or = r(rr)
local or0 = r(lb)
local or1 = r(ub)
local S1=`S1'+ /*
*/ (`m1'*`n1'*`n0'-`a'*`b'*`t')/((`t')^2)
local S2=`S2'+(`a'*`n0')/`t'
local Sor = `Sor' + (`a'*`n0')/`t'
}
local Swgt=`Swgt'+`wgt'
}
else { /* standardize */
if "`estanda'"!="" { local wgt `n0' }
else if "`istanda'"!="" { local wgt `n1' }
else local wgt=`standar'[`i']
local Swgt = `Swgt'+`wgt'
local R1=`a'/`n1'
local R0=`b'/`n0'
local vR1=(`a'*`c')/(`n1')^3
local vR0=(`b'*`d')/(`n0')^3
if "`type'"=="RR" {
_crcrr `a' `b' `c' `d' `level' `tb'
local or = r(rr)
local or0 = r(lb)
local or1 = r(ub)
local SXnum=`SXnum'+`wgt'*`R1'
local SXden=`SXden'+`wgt'*`R0'
local SPR=`SPR'+(`wgt')^2*`vR1'
local SR=`SR'+(`wgt')^2*`vR0'
}
else { /* RD */
_crcrd `a' `b' `c' `d' `level' `tb'
local or = r(rd)
local or0 = r(lb)
local or1 = r(ub)
local Sor=`Sor'+`wgt'*`or'
local SXnum=`SXnum'+(`wgt')^2*(`vR0'+`vR1')
}
}
local Sa = `Sa'+`a'
local Sb = `Sb'+`b'
local Sc = `Sc'+`c'
local Sd = `Sd'+`d'
local Sn0 = `Sn0'+`n0'
local Sn1 = `Sn1'+`n1'
qui replace `irr'=`or' in `i'
if "`type'"=="OR" {
qui replace `irr' = (`a'*`d')/(`b'*`c') in `i'
qui replace `virr'= 1/`a'+1/`b'+1/`c'+1/`d' in `i'
}
if "`type'"=="RR" {
qui replace `irr' = (`a'/`n1')/(`b'/`n0') in `i'
qui replace `virr'=`c'/(`a'*`n1')+`d'/(`b'*`n0') in `i'
}
if "`type'"=="RD" {
qui replace `irr' = (`a'/`n1')-(`b'/`n0') in `i'
qui replace `virr'= (`a'*`c')/((`n1')^3) + /*
*/ (`b'*`d')/((`n0')^3) in `i'
}
if `irr'[`i']/`virr'[`i'] < . {
if "`type'"=="RD" {
local pnum = `pnum' + `irr'[`i']/`virr'[`i']
}
else local pnum = `pnum'+log(`irr'[`i'])/`virr'[`i']
local pden = `pden' + 1/`virr'[`i']
}
local lbl=`lby'[`i']
local lbl=substr("`lbl'",1,16)
local skip=16-length("`lbl'")
di in smcl in gr _skip(`skip') "`lbl' {c |} " in ye /*
*/ %9.0g `or' " " %9.0g `or0' " " %9.0g `or1' /*
*/ " " %9.0g `wgt' in gr " `r(label)'"
local i=`i'+1
local df=`df'+1
}
/*NOTREACHED*/
end
prog define dispcs, rclass
local Sf "`1'" /* variable names */
local irr "`2'"
local virr "`3'"
mac shift 3
local CRUDE `1'
local C0 `2'
local C1 `3'
local pnum `4'
local pden `5'
local iz `6'
local df `7'
local or `8'
local or0 `9'
local or1 `10'
local stdflg `11'
local x2 `12'
mac shift 12
#delimit ;
local options "TYPE(string) MOTE(string) HDR2(string) ARGS(string) noHOM POOL PAREN(string) noCRUDE" ;
#delimit cr
parse ", `*'"
local hdr2 = trim("`hdr2'")
if "`hdr2'" == "M-H combined" | "`hdr2'"=="Standardized" {
local hdr2 " `hdr2'"
}
di in smcl in gr "{hline 17}{c +}{hline 49}"
if "`crude'" == "" {
di in smcl in gr " Crude {c |} " in ye /*
*/ %9.0g `CRUDE' " " %9.0g `C0' " " /*
*/ %9.0g `C1' in gr _col(69) "`CTYPE'"
}
if "`pool'" != "" {
if "`type'"=="RD" {
local POOL = `pnum'/`pden'
local sd = sqrt(1/`pden')
local P0 = `POOL'-`iz'*`sd'
local P1 = `POOL'+`iz'*`sd'
local dfm1=`df'-1
quietly replace `Sf'= sum( /*
*/ (`irr'-`POOL')^2/`virr') in 1/`df'
local pchi=`Sf'[`dfm1'+1]
local pval=chiprob(`dfm1',`pchi')
}
else {
local POOL = exp(`pnum'/`pden')
local sd = sqrt(1/`pden')
local P0 = exp(log(`POOL')-`iz'*`sd')
local P1 = exp(log(`POOL')+`iz'*`sd')
local dfm1=`df'-1
quietly replace `Sf'= sum( /*
*/ (log(`irr')-log(`POOL'))^2/`virr') in 1/`df'
local pchi=`Sf'[`dfm1'+1]
local pval=chiprob(`dfm1',`pchi')
}
di in smcl in gr " Pooled (direct) {c |} " in ye /*
*/ %9.0g `POOL' " " %9.0g `P0' " " /*
*/ %9.0g `P1'
}
if "`mote'"=="" {
di in smcl in gr " `hdr2' {c |} " in ye /*
*/ %9.0g `or' " " %9.0g `or0' " " %9.0g `or1'
}
else {
di in smcl in gr " `hdr2' {c |} " in ye /*
*/ %9.0g `or' " " %9.0g `or0' " " %9.0g `or1' /*
*/ in gr _col(69) "(`mote')"
}
if "`hom'" == "" {
if "`pool'" != "" | "`paren'"=="M-H" {
di in smcl in gr "{hline 17}{c BT}{hline 49}"
}
if "`pool'" != "" {
di in gr /*
*/ "Test of homogeneity " /*
*/ "(direct)" _col(32) "chi2(" in ye "`dfm1'" in gr /*
*/ ") =" in ye %9.3f `pchi' in gr /*
*/ " Pr>chi2 = " in ye %6.4f `pval'
global S_26 = `dfm1' /* double save S_ and r() */
global S_27 = `pchi'
ret scalar df = `dfm1'
ret scalar chi2_p = `pchi'
}
if "`paren'"=="M-H" {
if "`type'"=="RD" {
local dfm1=`df'-1
quietly replace `Sf'= sum( /*
*/ (`irr'-`or')^2/`virr') /*
*/ in 1/`df'
quietly summ `irr' in 1/`df', mean
local cdf = r(N) - 1
local mchi=`Sf'[`dfm1'+1]
*local mval=chiprob(`dfm1',`mchi')
local mval=chiprob(`cdf',`mchi')
}
else {
local dfm1=`df'-1
quietly replace `Sf'= sum( /*
*/ (log(`irr')-log(`or'))^2/`virr') /*
*/ in 1/`df'
quietly summ `irr' in 1/`df', mean
local cdf = r(N) - 1
local mchi=`Sf'[`dfm1'+1]
*local mval=chiprob(`dfm1',`mchi')
local mval=chiprob(`cdf',`mchi')
}
if `cdf' > 0 {
di in gr /*
*/ "Test of homogeneity " /*
*/ "(`paren')" _col(32) "chi2(" in ye "`cdf'" in gr /*
*/ ") =" in ye %9.3f `mchi' in gr /*
*/ " Pr>chi2 = " in ye %6.4f `mval'
global S_26 = `cdf' /* double save S_ and r() */
global S_25 = `mchi'
ret scalar df = `cdf'
ret scalar chi2_mh = `mchi'
}
}
}
if "`type'"=="OR" & `stdflg'==0 {
di in gr _n _col(20) /*
*/ "Test that combined OR = 1:" _n _col(33) /*
*/ "Mantel-Haenszel chi2(1) =" /*
*/ in ye %10.2f `x2' _n in gr /*
*/ _col(49) "Pr>chi2 =" in ye /*
*/ %10.4f chiprob(1,`x2')
}
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?