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

📄 _stcurv.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
	}
	qui replace _st=1
	qui replace _t0=0
	if "`cumhaz'"!="" {
	        tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		qui replace `ff'=-ln(`ff')
	        label var `ff' "Cumulative Hazard"
	        qui drop if `flag'==1
	}

	 if "`hazard'"!="" {
	        tempvar ff
		qui predict double `ff', haz `alpha1' `uncondi'
	        label var `ff' "Hazard function"
	        qui drop if `flag'==1
	}
	if "`surviva'"!="" {
	        tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
	        label var `ff' "Survival"
	        qui drop if `flag'==1
	}
	qui replace `nff'= `ff'
	qui replace `nt'= `t'
	local ffl: variable label `ff'
	local ntl: variable label `t'
	label var `nff' "`ffl'"
	label var `nt' "`ntl'"
end

program define LloPlot
	syntax newvarlist(gen min=2 max=2) [, /*
		*/ UNCONDitional ALPHA1 /*
        	*/ CUMHaz SURvival HAZard Begin(string) End(string) ]
	tokenize `varlist'
	local nff "`1'"
	local nt "`2'"

	local t:   char _dta[st_t]
	local wtopt:  char _dta[st_w]

	tempname b A M
	tempvar  flag
	mat `b'= get(_b)
	if  e(cmd) == "llogistichet" {
		local k=colsof(`b')-2
	}
	else {
		local k=colsof(`b')-1
	}

	local N=_N+1
	qui set obs `N'
	qui gen `flag'=1 if _n==_N
	local rhs: colnames(`b')
	tokenize "`rhs'"
	local i 1
	while `i'<=`k'-1 {
		qui mat acc `A' = `1' `wtopt', means(`M')
		qui replace `1'=`M'[1,1]
		mac shift
		local i=`i'+1
	}
	if "`end'"!="" {
		qui keep if `flag'==1
		qui expand 102
		qui replace `t'=`begin' in 1
		local int=(`end'-`begin')/100
		qui replace `t'=`t'[_n-1]+`int' if _n>1
		qui replace `flag'=0 if _n!=_N
	}
	qui replace _st=1
	qui replace _t0=0

	if "`cumhaz'"!="" {
		tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		qui replace `ff'=-ln(`ff')
		label var `ff' "Cumulative Hazard"
		qui drop if `flag'==1
	}
	if "`hazard'"!="" {
		tempvar ff
		qui predict double `ff', haz `alpha1' `uncondi'
		label var `ff' "Hazard function"
		qui drop if `flag'==1
	}
	if "`surviva'"!="" {
		tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		label var `ff' "Survival"
		qui drop if `flag'==1
	}
	qui replace `nff'= `ff'
	qui replace `nt'= `t'
	local ffl: variable label `ff'
	local ntl: variable label `t'
	label var `nff' "`ffl'"
	label var `nt' "`ntl'"

end


program define GomPlot
	syntax newvarlist(gen min=2 max=2) [, /*
		*/ UNCONDitional ALPHA1 /*
		*/ CUMHaz SURvival HAZard Begin(string) End(string) ]
	tokenize `varlist'
	local nff "`1'"
	local nt "`2'"

	local t:   char _dta[st_t]
	local wtopt:  char _dta[st_w]

	tempname b A M
	tempvar  flag
	mat `b'= get(_b)
	if  e(cmd) == "gompertzhet" {
		local k=colsof(`b')-2
	}
	else {
		local k=colsof(`b')-1
	}
	local N=_N+1
	qui set obs `N'
	qui gen `flag'=1 if _n==_N
	local rhs: colnames(`b')
	tokenize "`rhs'"
	local i 1
	while `i'<=`k'-1 {
		qui mat acc `A' = `1' `wtopt', means(`M')
	        qui replace `1'=`M'[1,1]
	        mac shift
	        local i=`i'+1
	}
	if "`end'"!="" {
		qui keep if `flag'==1
		qui expand 102
		qui replace `t'=`begin' in 1
		local int=(`end'-`begin')/100
		qui replace `t'=`t'[_n-1]+`int' if _n>1
		qui replace `flag'=0 if _n!=_N
	}
	qui replace _st=1
	qui replace _t0=0

	if "`cumhaz'"!="" {
	        tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		qui replace `ff'=-ln(`ff')
	        label var `ff' "Cumulative Hazard"
	        qui drop if `flag'==1
	}
	if "`hazard'"!="" {
       		tempvar ff
		qui predict double `ff', haz `alpha1' `uncondi'
        	label var `ff' "Hazard function"
		qui drop if `flag'==1
	}
	if "`surviva'"!="" {
        	tempvar ff
		qui predict double `ff', surv `alpha1' `uncondi'
	        label var `ff' "Survival"
	        qui drop if `flag'==1
	}

	qui replace `nff'= `ff'
	qui replace `nt'= `t'
	local ffl: variable label `ff'
	local ntl: variable label `t'
	label var `nff' "`ffl'"
	label var `nt' "`ntl'"

end

program define GamPlot
	syntax newvarlist(gen min=2 max=2) [, /*
		*/ UNCONDitional ALPHA1 /*
		*/ CUMHaz SURvival HAZard Begin(string) End(string) ]
	tokenize `varlist'
	local nff "`1'"
	local nt "`2'"

	local t:   char _dta[st_t]
	local wtopt:  char _dta[st_w]


	tempname b A M
	tempvar flag
	mat `b'= get(_b)
	if  e(cmd) == "gammahet" {
		local b0=colsof(`b')-3
	}
	else {
		local b0=colsof(`b')-2
	}

	local bb "Gamma regression"
	local N=_N+1
	qui set obs `N'
	qui gen `flag'=1 if _n==_N
	local rhs: colnames(`b')
	tokenize "`rhs'"
	local i 1
	while `i'<=`b0'-1 {
		qui mat acc `A' = `1' `wtopt', means(`M')
		qui replace `1'=`M'[1,1]
		mac shift
		local i=`i'+1
	}
	if "`end'"!="" {
		qui keep if `flag'==1
		qui expand 102
		qui replace `t'=`begin' in 1
		local int=(`end'-`begin')/100
		qui replace `t'=`t'[_n-1]+`int' if _n>1
		qui replace `flag'=0 if _n!=_N
	}
	qui replace _st=1
	qui replace _t0=0

	if "`cumhaz'"!="" {
	        tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		qui replace `ff'=-ln(`ff')
		label var `ff' "Cumulative Hazard"
		qui drop if `flag'==1
	}
	if "`hazard'"!="" {
		tempvar ff
		qui predict double `ff', haz `alpha1' `uncondi'
		label var `ff' "Hazard function"
		qui drop if `flag'==1
	}
	if "`surviva'"!="" {
		tempvar  ff
		qui predict double `ff', surv `alpha1' `uncondi'
		label var `ff' "Survival"
		qui drop if `flag'==1
	}
	qui replace `nff'= `ff'
	qui replace `nt'= `t'
	local ffl: variable label `ff'
	local ntl: variable label `t'
	label var `nff' "`ffl'"
	label var `nt' "`ntl'"

end
program define CoxPlot
	syntax newvarlist(gen min=2 max=2) [, /*
		*/ HAZard CUMHaz SURvival Kernel(string) width(real -1) /*
		*/ begin(real -1) end(real -1) ]
	tokenize `varlist'
	local nff "`1'"
	local nt "`2'"

	local t:   char _dta[st_t]
	local wtopt:  char _dta[st_w]
	
	tempname b A M
	tempvar flag t2
	mat `b'= get(_b)
	local b0=colsof(`b')
	local rhs: colnames(`b')
	tokenize "`rhs'"
	local i 1
	while `i'<=`b0' {
		qui mat acc `A' = `1' `wtopt', means(`M')
		tempname mean`i'
		scalar `mean`i''=`M'[1,1]
		mac shift
		local i=`i'+1
	}

	local bb "Cox regression"
	if "`hazard'"=="" {
		if "`kernel'" != "" {
			di in red "kernel() only allowed with hazard"
			exit 198
		}
		if `width'!=-1 {
			di in red "width() only allowed with hazard"
			exit 198
		}
		local N=_N+1
		qui set obs `N'
		qui gen `flag'=1 if _n==_N
		if `begin'!=-1 {
			qui drop if `t'<`begin'
		}
		if `end'!=-1 {
			qui drop if `t'>`end'
		}
	}
	else {
		qui drop if `e(basehc)'==. 
		sort `t'
		qui by `t': keep if _n==1
		summ `t', meanonly
		local tmin = r(min)
		local tmax = r(max)
		if `begin'!=-1 {
			local tmin `begin'
		}
		if `end'!=-1 {
			local tmax `end'
		}
		local N = _N
		local N1 = `N' + 1
		local obs = `N'+101
		qui set obs `obs'
		qui replace `t' = `tmin' + (`tmax'-`tmin')*(_n-`N1')/100 ///
			in `N1'/l
		qui gen `flag'=1 in `N1'/l
		qui gen `t2' = `t' in `N1'/l
	}
	tokenize "`rhs'"
	local i 1
	while `i'<=`b0' {
	 	qui replace `1' = scalar(`mean`i'') 
		mac shift
		local i=`i'+1
	}
	qui replace _st=1
	qui replace _t0=0

	if "`cumhaz'"!="" {
	        tempvar  ff
		qui predict double `ff', xb
                qui replace `ff'=`e(basech)'*exp(`ff')
		label var `ff' "Cumulative Hazard"
		qui drop if `flag'==1
	}
	if "`hazard'"!="" {
		tempvar ff smooth newh
		qui predict double `ff', xb
		if `width'!=-1 {
			local wopt width(`width')
		}
		qui gen double `newh' = (1-(1-`e(basehc)')^exp(`ff'))
		version 8: kdensity `t' [iw=`newh'], ///
			nograph at(`t2') gen(`smooth') `kernel' `wopt'
		qui replace `ff'=`smooth'
		label var `ff' "Smoothed hazard function"
		qui keep if `flag'==1
	}
	if "`surviva'"!="" {
		tempvar  ff
		qui predict double `ff', xb
		qui replace `ff'=`e(bases)'^exp(`ff')
		label var `ff' "Survival"
		qui drop if `flag'==1
	}
	qui replace `nff'= `ff'
	qui replace `nt'= `t'
	local ffl: variable label `ff'
	local ntl: variable label `t'
	label var `nff' "`ffl'"
	label var `nt' "`ntl'"
end

⌨️ 快捷键说明

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