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

📄 stci.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
		else {
			sort `touse' `id'
			by `touse' `id': /*
			*/ gen double `z'=`wv' if _n==1 & `touse'
			summ `z' if `touse'
			local nsubj = r(sum)
		}
	}

	Settitle `touse' `"`by'"'
	local ttl `"$S_1"'

	capture GetS `touse' `s'
	if _rc==0 { 
		tempvar prior gap area sarea ns
		tempname a1 a2 mt msurv lamb area2
		gsort -`s' _t
		gen double `prior'=_t0 in 1
		gen double `ns'=1 in 1
		replace `prior'=_t[_n-1] if `prior'>=. & `touse'
		replace `ns'=`s'[_n-1] if `ns'>=. & `touse'
		gen double `gap'=_t-`prior' if `touse'
		gen double `area'=`gap'*`ns' if `touse'
		gen double `sarea'=sum(`area')
		sum `sarea' if `touse'
		scalar `a1'=r(max)
		if `median'== 4 {
			sum _t if `touse'
			scalar `mt'=r(max)
			tempvar ms
			gen double `ms'=`s' if _t==`mt' & `touse'
			sum `ms' if `touse'
			scalar `msurv'=r(max)
			scalar `lamb'=-log(`msurv')/`mt'
			scalar `area2'=(1/`lamb')*exp(-`lamb'*`mt')
			if `flag2'~=0 {
				if `flag2'==-1 {
					local tmax= /*
					*/ -log(`msurv'/100)/`lamb'
				}
				else {
					local tmax=`flag2'
				}
			
				preserve
				tempname ns
				count 
				local nn=r(N)
				local xn=`nn'+21
				set obs `xn'	
				replace _t= /*
				*/ _t[_n-1]+ (`tmax'-`mt')/20 if _n>`nn'
				replace _t=`tmax' if _n==_N
				drop if _t>`tmax'
				replace `s'=. if _t>`mt'
				replace `ms'=. if _t>`mt'
				gen `ns'=exp(-`lamb'*_t) if _t>=`mt'
				label var `ns' "Eponential extension"
				local xn=_N+1
				set obs `xn'
				replace `s'=1 if _n==_N
				replace _t=0 if _n==_N
				label var _t "analysis time"
				if `"`plot'`addplot'"' == "" {
					local legend legend(nodraw)
				}
				else	local draw nodraw
				version 8: graph twoway			///
				(line `s' _t, 				///
					sort 				///
					connect(stairstep)		///
					lstyle(p1)			///
					`options'			///
				)					///
				(line `ns' _t,				///
					connect(direct)			///
					lstyle(p1)			///
					ylabel(0(.2)1)			///
					ytitle("Survival probability")	///
					title(				///
			"Exponentially extended survivor function"	///
					)				///
					`legend'			///
					`draw'				///
					`options'			///
				)					///
				// blank
				restore
				if `"`plot'`addplot'"' != "" {
					version 8: graph addplot `plot'	///
						|| `addplot' || , norescaling
				}
			}
			if `lamb'>=. {
				local area2 0
			}
			scalar `a2'=`area2'
		}
		tempname ps nse psl psu
		if `median'== 4 {
			scalar `ps'=  `a1' + `a2'
		}
		else {
			scalar `ps'=`a1'
		
			tempvar narea  
			preserve
			keep if `touse'
			gsort -_t 
			qui gen double `narea'=sum(`area') 
			gsort `mtouse' _t -`narea'
			replace `narea'=`narea'[_n+1] if `touse'==1
			qui replace `narea'= /*
			*/ cond(_d==0,.,(`narea'^2)/(`N'*(`N'-`d')))
			qui sum `N', meanonly
			local tN=r(max)
			qui sum `narea', meanonly
			if "`ccorr'"=="" {
				scalar `nse'=sqrt(r(sum))
			}
			else {
				scalar /*
				*/ `nse'=sqrt( (`tN'/(`tN'-1))*r(sum))
			}

			local alpha=invnorm(.5+`level'/200)
			scalar `psu' = `ps' + `alpha'*`nse'
			scalar `psl' = `ps' - `alpha'*`nse'
		}
	}
	else {
		local ps .
		local nse .
		local psl .
		local psu .
	}

} // quietly

	local flag
	qui sum `s' if `touse'
	if r(min)>0 & `median'==3 {
		local flag=1 
		local flag1=1 
	} 
	else if r(min)<=0 & `median'==4 {
		local flag=2
		local flag1=2
	}

	if `flag2'==0 {
		Displine `"`ttl'"' `nsubj' `ps' /*
		*/ `nse' `psl' `psu' `median' "`flag'" `dec'
	}
	if `median'== 3 {
		ret scalar ub = `psu'
		ret scalar lb = `psl'
		ret scalar se = `nse'
		ret scalar rmean = `ps'
		ret local f1 = `flag1'
	}
	else { 
		ret scalar emean = `ps' 
		ret local f1 = `flag1'
	}
	ret scalar N_sub = `nsubj'
end


program define Findptl /* percentile s `j0' */
	args p s j0 
	if `j0'>=. {
		global S_1 . 
		exit
	}
	tempvar j
	quietly {
		gen long  `j' = _n if float(`s')<=float(`p') in `j0'/l
		summ `j' in `j0'/l
		local j=r(min)
	}
	local t : char _dta[st_t]
	global S_1 = _t[`j']
	global S_2 = `s'[`j']
end

program define Findptl2 /* percentile s `j0' */
	args p s j0 
	if `j0'>=. {
		global S_1 . 
		exit
	}
	tempvar j
	quietly {
		gen long  `j' = _n if float(`s')>=float(`p') in `j0'/l
		summ `j' in `j0'/l
		local j=r(max)
	}
	local t : char _dta[st_t]
	global S_1 = _t[`j']
	global S_2 = `s'[`j']
end

program define Settitle /* touse byvars */
	args touse byvars

	if `"`byvars'"'==`""' {
		global S_1 `"total"'
		exit
	}
	quietly {
		tempvar j
		gen long `j' = _n if `touse'
		summ `j'
		local j = r(min)
	}
	tokenize `"`byvars'"'
	while `"`1'"'!=`""' {
		local ty : type `1'
		if substr(`"`ty'"',1,3)==`"str"' {
			local v = trim(substr(trim(`1'[`j']),1,8))
		}
		else {
			local v = `1'[`j']
			local v : label (`1') `v' 8
		}
		local list `"`list' "`v'""'
		mac shift 
	}
	global S_1 `"`list'"'
end

program define DispHdr /* level mytype mytype1 by */
	gettoken level 0:0
	gettoken mytype  0:0
	gettoken mytype1  0:0
	local n : word count `0'
	tokenize `0'
	local i 1 
	while `i' <= `n'-2 {
		di as txt abbrev(`"`1'"',12) _col(14) `"{c |}"'
		mac shift 
		local i = `i' + 1
	}
	local cil `=string(`level')'
	local cil `=length("`cil'")'
	if `cil' == 2 {
		local spaces "    "
	}
	else if `cil' == 4 {
		local spaces "  "
	}
	else {
		local spaces " "
	}
	if `"`2'"'==`""' {
		local ttl2 = abbrev(`"`1'"',12)
	}
	else {
		local ttl1 = abbrev(`"`1'"',12)
		local ttl2 = abbrev(`"`2'"',12)
	}
	if "`mytype1'"'=="extended" {
        	di as txt `"`ttl1'"' _col(14) /*
		*/ `"{c |}    no. of    `mytype1'"'
        	di as txt `"`ttl2'"' _col(14) /*
		*/ `"{c |}  subjects        `mytype'"'
		di as txt "{hline 13}{c +}{hline 22}"
	}
	else if "`mytype1'"'=="restricted"{
        	di as txt `"`ttl1'"' _col(14) /*
		*/ `"{c |}    no. of  `mytype1'"'
        	di as txt `"`ttl2'"' _col(14) /*
		*/ `"{c |}  subjects        mean      Std. Err."' /*
		*/ `"`spaces'[`=strsubdp("`level'")'% Conf. Interval]"'
		di as txt "{hline 13}{c +}{hline 61}"
	}
	else {
        	di as txt `"`ttl1'"' _col(14) /*
		*/ `"{c |}    no. of "'
        	di as txt `"`ttl2'"' _col(14) /*
		*/ `"{c |}  subjects         `mytype'     Std. Err."' /*
		*/ `" `spaces'[`=strsubdp("`level'")'% Conf. Interval]"'
		di as txt "{hline 13}{c +}{hline 61}"
	}
end

program define Displine 
	args ttl nsubj ps nse lb ub median flag dec

	local ttl = trim(`"`ttl'"')

	if length(`"`ttl'"') > 12 + 2 {	/* +2 to account for quotes */
		local n : word count `ttl'
		local i 1
		while `i' < `n' {
			local this : word `i' of `ttl'
			di as txt %12s `"`this'"' " {c |}"
			local i = `i' + 1
		}
		local ttl : word `n' of `ttl'
	}
	else	{
		tokenize `"`ttl'"'	/* to strip the quotes */
		local ttl `*'

	}
		
	if "`median'"=="4" {
		if "`flag'"=="2" {
			di as txt %12s `"`ttl'"' " {c |} " as res /*
			*/ %9.0g `nsubj' `"   "' %9.`dec' `ps' "(*)"
		}
		else {
			di as txt %12s `"`ttl'"' " {c |} " as res /*
			*/ %9.0g `nsubj' `"   "' %9.`dec' `ps'
		}
	}
	else if "`median'"=="3" {   
		di as txt %12s `"`ttl'"' " {c |} " as res /*
		*/ %9.0g `nsubj' `"   "' %9.`dec' `ps' _c
		if "`flag'"=="1" {
			di as res "(*)"  _skip(2) %9.`dec' `nse' /* 
			*/_skip(5) %8.`dec' `lb' _skip(3) %8.`dec' `ub'
		}
		else {
			di as res   _skip(5)  %9.`dec' `nse' /* 
			*/ _skip(5) %8.`dec' `lb' _skip(3) %8.`dec' `ub'
		}
	}
	else {   
		di as txt %12s `"`ttl'"' " {c |} " as res /*
		*/ %9.0g `nsubj' `"   "' %9.`dec' `ps' _c
		if "`flag'"~="" {
			di as res "(*)"  _skip(2) %9.`dec' `nse' /* 
			*/_skip(5) %8.0g `lb' _skip(3) %8.0g `ub'
		}
		else {
			di as res   _skip(5)  %9.`dec' `nse' /* 
			*/ _skip(5) %8.0g `lb' _skip(3) %8.0g  `ub'
		}
	}
end

program define GetS /* touse s */
	args touse s 

	tempname prior
	capture {
		capture estimate hold `prior'
		stcox if `touse', estimate bases(`s')
	}
	local rc=_rc
	capture estimate unhold `prior'
	exit `rc'
end
exit

⌨️ 快捷键说明

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