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

📄 _choice_table.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
字号:
*! version 1.0.2  01apr2005
program _choice_table
	version 8.2
	if "`e(cmd)'" == "" {
		error 301
	}
	syntax [namelist] [,			///
		BEGIN				///
		END				///
		Level(cilevel)			///
		EQuation			///
		comment(passthru)		///
		value(passthru)			///
		NOSEP				///
		AUXlook				///
	]

	if `"`equation'"' != "" & `"`comment'"' != "" {
		opts_exclusive "equation comment()"
	}
	if `"`equation'"' != "" & `"`value'"' != "" {
		opts_exclusive "equation value()"
	}

	// parse `options' for -eform()- and friends
	_get_eformopts , eformopts(`options') allowed(__all__) soptions
	local eform	`"`s(str)'"'

	// get equation names for auxiliary parameters or extra equations
	local coleq : coleq e(b), quote
	local coleq : list clean coleq
	local coleq : list uniq coleq
	if "`equation'" != "" {
		if !`:list namelist in coleq' {
			local bad : list namelist - coleq
			di as err "invalid quation: `word 1 of `bad''"
			exit 198
		}
	}

	// display any constraints
	if "`begin'" != "" {
		tempname cns error
		capture mat `cns' = get(Cns)
		if !c(rc) {
			matrix dispCns
		}
	}

	local df_r .
	Chk4Int df_r

	tempname z
	if missing(`df_r') {
		scalar `z' = invnorm((100+`level')/200)
	}
	else	scalar `z' = invttail(`df_r',(100-`level')/200)

	tempname Tab
	.`Tab' = ._tab.new, col(7) lmargin(0) ignore(.b)
	// column        1      2     3     4     5     6     7
	.`Tab'.width	13    |11    11     9     9    12    12
	.`Tab'.titlefmt  .   %11s  %12s   %7s     .  %24s     .
	.`Tab'.strfmt    .   %11s     .     .     .     .     .
	.`Tab'.pad       .      2     2     1     3     3     3
	.`Tab'.numfmt    .  %9.0g %9.0g %8.2f %5.3f %9.0g %9.0g
	.`Tab'.strcolor  . result    .     .     .     .     .
	// NOTE: Changing any of the above values should be reflected in
	// the ColumnTitles subroutine.  This may also affect
	// _coef_table_header.ado.

	if "`begin'" != "" {
		if "`e(clustvar)'" != "" & !missing(e(N_clust)) {
			di as txt ///
"{ralign 78:(Std. Err. adjusted for {res:`e(N_clust)'} clusters in `e(clustvar)')}"
		}
		else if "`e(clustvar)'" != "" {
			di as txt ///
"{ralign 78:(Std. Err. adjusted for clustering on `e(clustvar)')}"
		}
		ColumnTitles `Tab' `level' `df_r' `"`eform'"' `neq'
	}

	if `"`equation'"' != "" {
		DisplayEqns `namelist' :	///
			`Tab',	l(`level')	///
				df(`df_r')	///
				z(`z')		///
				ef(`eform')	///
				// blank
	}
	else if `"`value'"' != "" {
		DisplayValue `namelist', `value' `comment' `auxlook' : `Tab'
	}
	else if `"`comment'"' != "" {
		DisplayComment `namelist', `comment' : `Tab'
	}

	if "`end'" != "" {
		.`Tab'.sep, bottom
	}
	else if "`nosep'" == "" {
		.`Tab'.sep
	}

	if e(rc) == 504 & "`e(opt)'" == "ml" {
		di as err ///
"{p 0 0 2}variance matrix missing because `e(user)' failed" ///
"to compute scores or computed scores with missing values{p_end}"
		exit 504
	}
	if (!missing(e(rc)) & e(rc) != 0) error e(rc)
end

program ColumnTitles
	args Tab level df eform

	local tsdvn 0		// number of depvar lines for time-series
				// operators to display

	local coleq : coleq e(b)
	local dv `"`e(depvar)'"'
	local dv1 : word 1 of `dv'
	if `:word count `dv'' == 1 ///
	 & (!`:list dv in coleq') {
		gettoken op vn : dv, parse(".")
		if "`vn'" != "" & `:length local dv' > 12 {
			local vn = substr("`vn'",2,.)
			MLineTSop op_ depvar tsdvn : `op' `vn'
		}
		else	local depvar = abbrev("`dv'",12)
	}
	if "`eform'" != "" {
		local coef "`eform'"
	}
	else	local coef "Coef."
	if missing(`df') {
		local stat z
	}
	else	local stat t
	.`Tab'.sep, top
	if `"`e(vcetype)'"' != "" {
		local vcetype `"`e(vcetype)'"'
		if "`e(vcetype)'" == "Bootstrap" {
			local obs "Observed"
			local citype "Normal-based"
		}
		local ciwd : length local citype
		local vcewd : length local vcetype
		if `"`e(mse)'"' != "" {
			capture which `e(vce)'_`e(mse)'.hlp
			if !c(rc) {
				local vcetype ///
				"{help `e(vce)'_`e(mse)'##|_new:`vcetype'}"
				local plus = `: length local vcetype' - `vcewd'
				local plus "+`plus'"
			}
		}
		if `vcewd' <= 12 {
			// NOTE: see the width and pad definitions of .`Tab'
			local vcewd = `vcewd'`plus' + ceil((12-`vcewd')/2+1)
		}
		if `ciwd' <= 27 {
			// NOTE: see the width and pad definitions of .`Tab'
			local ciwd = `ciwd' + ceil((27-`ciwd')/2)
		}
		// column        1       2             3   4  5          6  7
		.`Tab'.titlefmt  .       .     %`vcewd's   .  .   %`ciwd's  .
		.`Tab'.titles   "" "`obs'" `" `vcetype'"' "" "" "`citype'" ""
		.`Tab'.titlefmt  .       .          %12s   .  .       %24s  .
	}
	if `tsdvn' > 0 {
		.`Tab'.titlefmt  %-12s . . . . . .
		forval i = 1/`tsdvn' {
			.`Tab'.titles "`op_`i''" "" "" "" "" "" ""
		}
		.`Tab'.titlefmt  %12s . . . . . .
	}
	.`Tab'.titles	"`depvar'"	/// 1
			"`coef'"	/// 2
			"Std. Err."	/// 3
			"`stat'"	/// 4
			"P>|`stat'|"			/// 5
			`"[`=strsubdp("`level'")'% Conf. Interval]"' ""	//  6 7
end

program MLineTSop
	args c_op c_dv c_n COLON op vn

	local n 1

	// operator fits on a line by itself
	if `:length local op' < 12 {
		c_local `c_op'1	`"`op'."'
		local vn = abbrev(`"`vn'"',12)
		c_local `c_dv'	`"`vn'"'
		c_local `c_n'	`n'
		exit
	}

	c_local `c_op'`n' = substr(`"`op'"',1,12)
	local op = substr(`"`op'"',13,.)
	while `:length local op' >= 12 {
		local ++n
		c_local `c_op'`n' = substr(`"`op'"',1,12)
		local op = substr(`"`op'"',13,.)
	}
	if `"`op'"' == "" {
		local vn = abbrev(`"`vn'"', 12)
		c_local `c_dv' `"`vn'"'
	}
	else {
		local rest `"`op'.`vn'"'
		if `:length local rest' <= 12 {
			c_local `c_dv' `"`rest'"'
		}
		else {
			local ++n
			c_local `c_op'`n' `"`op'."'
			local vn = abbrev(`"`vn'"', 12)
			c_local `c_dv' `"`vn'"'
		}
	}
	c_local `c_n' `n'
end

program DisplayValue
	_on_colon_parse `0'
	local 0 `"`s(before)'"'
	syntax namelist(name=idlist) [,	///
		value(real 0.0)		///
		comment(string)		///
		auxlook			///
	]
	local 0 `s(after)'
	syntax name(name=Tab)
	foreach id of local idlist {
		if ("`auxlook'"!="")	///
			Value `Tab' "/`id'" `value' `"`comment'"'
		else  Value `Tab' "`id'" `value' `"`comment'"'
	}
end

program Value
	args Tab id value comment
	local id = abbrev("`id'", 12)
	.`Tab'.strcolor           .       .          text   .  .  .  .
	.`Tab'.strfmt             .       .             .   .  .  .  .
	.`Tab'.row	   `"`id'"' `value' `"`comment'"' "" "" "" ""
	.`Tab'.strcolor           .       .        result   .  .  .  .
	.`Tab'.strfmt             .       .             .   .  .  .  .
end

program DisplayComment
	_on_colon_parse `0'
	local 0 `"`s(before)'"'
	syntax namelist(name=idlist) [,	///
		comment(string)		///
	]
	local 0 `s(after)'
	syntax name(name=Tab)
	foreach id of local idlist {
		Comment `Tab' `id' `"`comment'"'
	}
end

program DisplayEqns
	_on_colon_parse `0'
	local eqlist `"`s(before)'"'
	if (`: word count `eqlist'' == 0) exit

	local 0 `s(after)'
	syntax name(name=Tab) [,	///
		First			///
		EForm(passthru)		///
		ERRormat(name)		///
		*			///
	]

	local coleq : coleq e(b), quote
	local coleq : list clean coleq
	local colna : colna e(b)
	local neq   : word count `coleq'

	// index of first element
	local ucoleq : list uniq coleq
	local start : list posof "`:word 1 of `eqlist''" in coleq

	// loop through the coefficients, displaying those that belong to the
	// specified equations

	local i `start'
	local oldeq // start fresh
	while `i' <= `neq' {
		local eq : word `i' of `coleq'
		local qeq `""`eq'""'
		// exit if the current equation is not in the list
		local break = (!`:list eq in eqlist' & !`:list qeq in eqlist')
		if (`break') continue, break

		local na : word `i' of `colna'
		local nna : word `=`i'+1' of `colna'
		if `"`eq'"' != `"`oldeq'"' {

			if "`offset'" != "" {
				// display offset of previous equation
				Offset `Tab' `"`offset'"' `"`offtyp'"'
				local offset
				local offtyp
			}
			if `"`eq'"' != "_" {
				local abeq = abbrev(`"`eq'"',12)
				// columns           1   2  3  4  5  6  7
				.`Tab'.strcolor result   .  .  .  .  .  .
				.`Tab'.strfmt    %-12s   .  .  .  .  .  .
				.`Tab'.row   `"`abeq'"' "" "" "" "" "" ""
				.`Tab'.strcolor   text   .  .  .  .  .  .
				.`Tab'.strfmt     %12s   .  .  .  .  .  .
			}
			local oldeq `"`eq'"'

			// get offset of current equation
			local ieq : list posof `"`eq'"' in ucoleq
			_get_offopt `e(offset)'`e(offset`ieq')'
			local offset `s(offvar)'
			if "`s(offopt)'" == "offset(`offset')" {
				local offtyp "(offset)"
			}
			else if "`s(offopt)'" != "" {
				local offtyp "(exposure)"
			}
		}
		if `"`eform'"' == "" | "`na'" != "_cons" {
			gettoken op vn : na, parse(".")
			gettoken nop nvn : nna, parse(".")
			if "`nvn'" == ".`na'" | ".`oldvn'" == ".`na'" {
				local nulltsop nulltsop
				local vn ".`na'"
			}
			else	local nulltsop
			if "`vn'" != "" & ".`oldvn'" != "`vn'" {
				local vn = abbrev(substr("`vn'",2,.),12)
				// columns           1  2  3  4  5  6  7
				.`Tab'.row    `"`vn'"' "" "" "" "" "" ""
				local oldvn `vn'
			}
			else if "`vn'" == "" {
				local oldvn
			}
			Row `Tab' `"`qeq'"' "`na'", ///
				`options' `eform' `nulltsop'
		}
		local ++i
	}
	if "`offset'" != "" {
		// display offset of last displayed equation
		Offset `Tab' `"`offset'"' `"`offtyp'"'
		local offset
		local offtyp
	}
end

program Comment
	args Tab id comment
	local id = abbrev("`id'", 12)
	.`Tab'.strcolor      result          text   .  .  .  .  .
	.`Tab'.strfmt         %-12s             .   .  .  .  .  .
	.`Tab'.row	   `"`id'"' `"`comment'"' "" "" "" "" ""
	.`Tab'.strcolor        text        result   .  .  .  .  .
	.`Tab'.strfmt          %12s             .   .  .  .  .  .
end

program Offset
	args Tab offset offtyp
	local offset = abbrev("`offset'", 12)
	.`Tab'.strcolor           .         text   .  .  .  .  .
	.`Tab'.row	`"`offset'"' `"`offtyp'"' "" "" "" "" ""
	.`Tab'.strcolor           .       result   .  .  .  .  .
end

program Row
	syntax anything [,			///
		Level(cilevel)			///
		EForm(passthru)			///
		ERRor(integer 0)		///
		df(real 0)			///
		z(name)				///
		NULLTSOP			///
	]
	local 0 `anything'
	args Tab eq na
	local eq : list clean eq
	tempname b se t p ll ul
	if `"`eq'"' != "_" {
		scalar `b'  = [`eq']_b[`na']
		scalar `se' = [`eq']_se[`na']
	}
	else {
		scalar `b'  = _b[`na']
		scalar `se' = _se[`na']
	}
	if `se' == 0 & `"`e(census)'"' == "1" {
		scalar `t' = .
		scalar `p' = .
		scalar `ll' = .
		scalar `ul' = .
	}
	else {
		if `se' == 0 {
			scalar `se' = .
		}
		scalar `t' = `b'/`se'
		if missing(`df') {
			scalar `p' = 2*norm(-abs(`t'))
		}
		else	scalar `p' = 2*ttail(`df',abs(`t'))
		scalar `ll' = `b' - `se'*`z'
		scalar `ul' = `b' + `se'*`z'
		if "`eform'" != "" {
			scalar `b'  = exp(`b')
			scalar `se' = `b'*`se'
			scalar `ll' = exp(`ll')
			scalar `ul' = exp(`ul')
		}
	}

	if "`nulltsop'" != "" {
		local na "--.`na'"
	}
	gettoken op vn : na, parse(".")
	if "`vn'" != "" {
		if `:length local op' == 1 {
			local op `op'1
		}
		local na `"`op'."'
		while `:length local na' > 12 {
			.`Tab'.strfmt %11s . . . . . .
			local n1 = substr("`na'",1,10)
			.`Tab'.row "`n1'" "" "" "" "" "" ""
			local na = substr("`na'",11,.)
		}
		.`Tab'.strfmt %12s . . . . . .
	}
	else	local na = abbrev("`na'",12)

	local error1 "  (no observations)"
	local error2 "  (stratum with 1 PSU detected)"
	local error3 "  (sum of weights equals zero)"
	local error4 "  (denominator estimate equals zero)"
	local error5 "  (dropped)"

	if `error' {
		.`Tab'.row "`na'" "`error`error''" "" "" "" "" ""
	}
	else if `b'== 0 & `se' >= . {
		.`Tab'.row "`na'" "`error5'" "" "" "" "" ""
	}
	else {
		.`Tab'.row "`na'" `b' `se' `t' `p' `ll' `ul'
	}
end

program Chk4Int
	args ename
	if `"`e(`ename')'"' != "" {
		capture confirm integer number `e(`ename')'
		if !c(rc) {
			c_local `ename' `e(`ename')'
		}
	}
end

exit

⌨️ 快捷键说明

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