⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stcox_p.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
字号:
*! version 6.0.3  24sep2004
program define stcox_p, sort
	version 6, missing

		/* 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 "XB Index STDP HR CSNell DEViance CCSnell CMGale"


		/* 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 "`xb'`index'`stdp'`hr'`csnell'`deviance'`ccsnell'`cmgale'"


		/* 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
	if "`e(cmd2)'"=="stcox" {
		st_is 2 full
		qui replace `touse' = 0 if _st==0
	}

/*
	if "`type'"=="" | "`type'"=="hr" {
		if "`type'"=="" {
			di in gr "(option hr assumed; relative hazard)"
		}
		tempvar xb
		_predict `vtyp' `varn' if `touse', /* default */ `offset'
		label var `varn' "relative hazard"
		exit
	}
*/

	if "`type'"=="xb" | "`type'"=="index" | "`type'"=="stdp" {
		_predict `vtyp' `varn' if `touse', `type' `offset'
		exit
	}


	st_is 2 full

        if "`type'"=="csnell" { 
		if "`e(mgale)'"=="" { Error csnell }
		gen `vtyp' `varn' = (_d!=0) - `e(mgale)' if `touse'
		if "`_dta[st_id]'" != "" { local part "partial " }
		label var `varn' "`part'Cox-Snell residual"
		exit
	}

	if "`type'"=="" | "`type'"=="hr" {
		if "`type'"=="" {
			di in gr "(option hr assumed; relative hazard)"
		}
		tempvar xb
		qui _predict `vtyp' `xb' if `touse', xb  `offset'
		qui gen `vtyp' `varn'=exp(`xb')
		label var `varn' "relative hazard"
		exit
	}

		/* 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'"=="deviance" { 
		if "`e(mgale)'"=="" { Error deviance }
		tempvar cmg
		qui predict double `cmg' if `touse', cmgale `offset'
		gen `vtyp' `varn' = sign(`cmg')*sqrt( /* 
		*/ -2*(`cmg' + (_d!=0)*(ln((_d!=0)-`cmg')))) if `touse'
		label var `varn' "deviance residual"
		exit
	}


	if "`type'"=="ccsnell" {
		if "`e(mgale)'"=="" { Error ccsnell }
		if "`_dta[st_id]'" == "" {
			predict `vtyp' `varn' if `touse', csnell `offset'
			exit
		}
		tempvar cs
		qui predict double `cs' if `touse', csnell `offset'
		sort `touse' `_dta[st_id]' _t
		qui by `touse' `_dta[st_id]': /*
			*/ replace `cs'=cond(_n==_N,sum(`cs'),.) if `touse'
		gen `vtyp' `varn' = `cs' if `touse'
		label var `varn' "cum. Cox-Snell residual"
		exit
	}


	if "`type'"=="cmgale" {
		if "`e(mgale)'"=="" { Error cmgale }
		if "`_dta[st_id]'" == "" {
			gen `vtyp' `varn' = `e(mgale)' if `touse'
			label var `varn' "Martingale resid."
			exit
		}
		tempvar mg
		sort `touse' `_dta[st_id]' _t
		qui by `touse' `_dta[st_id]': /*
		*/ gen double `mg'=cond(_n==_N, sum(`e(mgale)'), .) if `touse'
		gen `vtyp' `varn' = `mg' if `touse'
		label var `varn' "cum. Martingale resid."
		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 define Error
	#delimit ;
	di in red 
"`1' may not be calculated unless you specified option mgale(newvar)" _n
"on the stcox command." ;
	#delimit cr
	exit 198
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -