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

📄 _stcurv.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*!version 6.3.3 23jul2004
program define _stcurv, rclass
	version 6
	if "`e(cmd2)'" != "streg" & "`e(cmd2)'"!= "stcox"{ 
		error 301
	}
	/* save() is not optional */
        syntax , save(string) [		/*
		*/ CUMHaz		/*
		*/ SURvival		/*
		*/ HAZard		/*
		*/ UNCONDitional	/*
		*/ ALPHA1		/*
		*/ Range(numlist	/*
		*/ 	ascending	/*
		*/ 	min=2		/*
		*/ 	max=2		/*
		*/ )			/*
		*/ AT(string)		/*
		*/ Kernel(passthru)	/*
		*/ width(real -1)	/*
	*/ ]

	local n = ("`cumhaz'"!="") + ("`surviva'"!="") + ("`hazard'"!="")

	if `n'==0 { 
		di in red /*
	   	*/ "must specify one of the options cumhaz, survival, or hazard"
		exit 198
	}
	if `n'>1 { 
		di in red /*
		*/ "must specify only one of cumhaz, survival, and hazard"
		exit 198
	}

	if "`e(cmd)'" != "weibull" &  "`e(cmd)'" != "ereg" /*
	*/ & "`e(cmd)'" != "lnormal" & "`e(cmd)'" != "llogistic" /*
	*/ & "`e(cmd)'" != "gompertz" & "`e(cmd)'" != "gamma" & /*
	*/ "`e(cmd)'" != "cox" & /*
	*/ "`e(cmd)'" != "weibullhet" &  "`e(cmd)'" != "ereghet" /*
	*/ & "`e(cmd)'" != "lnormalhet" & "`e(cmd)'" != "llogistichet" /*
	*/ & "`e(cmd)'" != "gompertzhet" & "`e(cmd)'" != "gammahet" /*
	*/ & "`e(cmd)'" != "stcox_fr" {
		di in red /*
		*/ "stcurve cannot yet graph using the `e(cmd)' distribution"
		exit 301
	}
	if "`e(stcurve)'"=="" & `"`e(frailty)'"'=="" /*
		*/ & "`e(cmd)'" != "cox" & "`e(cmd)'" != "stcox_fr" {
		di in red /*
		*/ "stcurve cannot graph the `e(cmd)' distribution" 
		di in red "when ancillary() or strata() options are specified"
		exit 301
	}
	else local model="`e(cmd)'"
	if "`model'"=="cox" & "`e(strata)'"!="" {
		di in red /*
		*/ "stcurve not allowed after stcox, strata()"
		exit 198
	}
	if "`model'"!="cox" & "`model'"!="stcox_fr" {
		if `"`kernel'"'!="" | `width'!=-1 {
			di in red "smoothing options kernel() and width() " _c
			di in red "only valid after stcox"
			exit 198
		}
	}

	if "`range'"!="" {
		local begin: word 1 of `range'
		local end  : word 2 of `range'
		local bopt="begin(`begin')"
		local eopt="end(`end')"
	}

	preserve
	qui keep if e(sample)
	if "`at'"!="" {
		mat B=e(b)
		tokenize "`at'" ,parse(" =,")
		while "`1'"!="" {
			confirm var `1'
			confirm number `3'
			CheckVar `1' `B'
			qui replace `1' `2' `3'
			if "`4'"=="," {
				mac shift 4
			}
			else { mac shift 3 }
		}
	}
	tempname nff nt
	if "`model'"== "weibull" | "`model'"== "weibullhet" { 
		WeiPlot `nff' `nt', /* 
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Weibull regression"
	}
	if "`model'"== "ereg"  | "`model'"== "ereghet" { 
		ExpPlot `nff' `nt', /* 
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Exponential regression"
	}
	if "`model'"== "lnormal" | "`model'"=="lnormalhet" { 
		LnoPlot `nff' `nt', /* 
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Log-normal regression"
	}
	if "`model'"== "llogistic" | "`model'"== "llogistichet" { 
		LloPlot `nff' `nt', /*
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Log-logistic regression"
	}
	if "`model'"== "gompertz"  | "`model'"== "gompertzhet" { 
		GomPlot `nff' `nt', /* 
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Gompertz regression"
	}
	if "`model'"== "gamma"  | "`model'"== "gammahet" { 
		GamPlot `nff' `nt', /* 
			*/ `cumhaz' `surviva' `hazard' `bopt' `eopt' /*
			*/ `uncondi' `alpha1'
        	local bb "Generalized gamma regression"
	}
	if "`model'"== "cox" || "`model'" == "stcox_fr"  { 
		if "`surviva'"!="" {
			if "`e(bases)'"==""{
				di in red /* 
				*/"must specify basesurv() option in stcox"
				exit 198
			}
		}
		if "`hazard'"!="" {
			if "`e(basehc)'"==""{
				di in red /* 
				*/"must specify basehc() option in stcox"
				exit 198
			}
		}
		if "`cumhaz'"!="" {             /* cumhaz */
			if "`e(basech)'"=="" {
				di in red /*
				*/"must specify basechazard() option in stcox"
				exit 198
			}
		}
		
		CoxPlot `nff' `nt', `cumhaz' `surviva' `hazard' ///
			`kernel' width(`width') `bopt' `eopt'
        	local bb "Cox proportional hazards regression"
	}
	label var `nt' "`e(depvar)'"
	qui save `"`save'"', replace
	ret local myvars = "`nff' `nt'"
 	ret local bb=`"`bb'"'
end

prog def CheckVar 
	args varn B
	unab myvarn: `varn'
	local bnames: colnames B 
	local bsize: word count `bnames'
	tokenize `bnames'
	local flag 0
	local i 1
	while `i'<=`bsize' {
		if "`myvarn'"=="`1'" {
			local flag=1
		}
		mac shift
		local i=`i'+1		
	}
	if `flag'==0 {
		noi di in red /*
		*/ "at() variable `myvarn' not in the estimated model"
		exit 198
	}
end

program define WeiPlot 
	syntax newvarlist(gen min=2 max=2) [, CUMHaz SURvival HAZard /*
		*/ UNCONDitional ALPHA1 /*
		*/ 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) == "weibullhet" {
		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'=-log(`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 ExpPlot 
	syntax newvarlist(gen min=2 max=2) [, CUMHaz SURvival HAZard /*
		*/ UNCONDitional ALPHA1 /*
		*/ 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) == "ereghet" {
		local k=colsof(`b')-1
	}
	else {
		local k=colsof(`b')
	}
	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'=-log(`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 LnoPlot
	syntax newvarlist(gen min=2 max=2) [, CUMHaz SURvival HAZard /*
		*/ UNCONDitional ALPHA1 /*
		*/ 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) == "lnormalhet" {
		local k=colsof(`b')-2
	}
	else {
		local k=colsof(`b')-1
	}

	local N=_N+1
	qui gen `flag'=1 if _n==_N
	qui set obs `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

⌨️ 快捷键说明

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