clogit_p.ado
来自「是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到」· ADO 代码 · 共 143 行
ADO
143 行
*! version 1.1.1 19jan2005
program define clogit_p
version 6, missing
syntax [anything] [if] [in] [, SCores * ]
if `"`scores'"' != "" {
GenScores `0'
exit
}
/* Step 1:
place command-unique options in local myopts
Note that standard options are
LR:
Index XB Cooksd Hat
REsiduals RSTAndard RSTUdent
STDF STDP STDR noOFFset
SE:
Index XB STDP noOFFset
*/
local myopts "Pc1 PU0"
/* Step 2:
call _propts, exit if done,
else collect what was returned.
*/
_pred_se "`myopts'" `0'
if `s(done)' { exit }
local vtyp `s(typ)'
local varn `s(varn)'
local 0 `"`s(rest)'"'
/* Step 3:
Parse your syntax.
*/
syntax [if] [in] [, `myopts' noOFFset]
/* Step 4:
Concatenate switch options together
*/
local type "`pc1'`pu0'"
/* Step 5:
quickly process default case if you can
Do not forget -nooffset- option.
*/
/* Step 6:
mark sample (this is not e(sample)).
*/
marksample touse
/* Step 7:
handle options that take argument one at a time.
Comment if restricted to e(sample).
Be careful in coding that number of missing values
created is shown.
Do all intermediate calculations in double.
*/
/* Step 8:
handle switch options that can be used in-sample or
out-of-sample one at a time.
Be careful in coding that number of missing values
created is shown.
Do all intermediate calculations in double.
*/
if "`type'"=="" | "`type'"=="pc1" {
if "`type'"=="" {
#delimit ;
di in gr
"(option pc1 assumed; conditional probability for single outcome within group)";
#delimit cr
}
tempvar xb denom p
quietly {
_predict double `xb' if `touse', xb `offset'
sort `e(group)'
by `e(group)': gen double `denom' = sum(exp(`xb'))
by `e(group)': gen double `p' = exp(`xb')/`denom'[_N]
drop `denom'
}
gen `vtyp' `varn' = `p' if `touse'
label var `varn' "Pr(`e(depvar)'|single outcome w/i `e(group)')"
exit
}
if "`type'" == "pu0" {
tempvar xb
quietly {
_predict double `xb' if `touse', xb `offset'
}
gen `vtyp' `varn' = 1/(1+exp(-`xb')) if `touse'
label var `varn' "Pr(`e(depvar)'|fixed effect is 0)"
exit
}
/* Step 9:
handle switch options that can be used in-sample only.
Same comments as for step 8.
*/
* qui replace `touse'=0 if !e(sample)
/* Step 10.
Issue r(198), syntax error.
The user specified more than one option
*/
error 198
end
program GenScores, rclass
version 9, missing
syntax [anything] [if] [in] [, * ]
marksample touse
_score_spec `anything', `options'
local varn `s(varlist)'
local vtyp `s(typlist)'
tempname eb
matrix `eb' = e(b)
local xvars : colna `eb'
local CONS _cons
local xvars : list xvars - CONS
_get_offopt `e(offset)'
local offopt `"`s(offopt)'"'
quietly _clogit_lf `e(depvar)' `xvars' if `touse', ///
group(`e(group)') score(`varn') beta(`eb') `offopt'
label var `varn' "equation-level score from clogit"
return local scorevars `varn'
end
exit
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?