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

📄 estat_summ.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*! version 1.0.1  24mar2005
program estat_summ, rclass sortpreserve
	version 9

	if "`e(cmd)'" == "" {
		error 301
	}

	capture assert e(sample) == 0
	if !_rc {
		dis as err "e(sample) information not available"
		exit 498
	}

	syntax [anything(name=eqlist id="equation list")] , [	///
		EQuation					///
		noHEAder					///
		noWEIghts					///
		LABels						///
		]

	local eq `equation'

// turn (e(b),eq) or eqlist into the following macros
//
//         neq           #equations
//         eqname<i>     equation name <i>
//         eqvlist<i>    eqlist in equation <i>

	if `"`eqlist'"' == "" {
		capture confirm matrix e(b)
		if !has_eprop(b) | _rc {
			dis as err "matrix e(b) not found in estimation results"
			exit 321
		}

		tempname b bi
		matrix `b' = e(b)
		if rowsof(`b') != 1 {
			dis as err "matrix e(b) is not a row vector"
			exit 322
		}

		local neq = 0
		local vnames : colnames `b'
		if "`eq'" == "" {
			local vnames `e(depvar)' `vnames'
			local vnames : list uniq vnames
			// take care of ts ops
			local neq = 1
			SplitTSOp `vnames'
			local eqts`neq' `eqts`neq'' `r(tsops)'
			local eqvlist`neq' `eqvlist`neq'' `r(vars)'
		}
		else {
			if "`e(depvar)'" != "" {
				local eqname`++neq'  depvar
				SplitTSOp `e(depvar)'
				local eqts`neq' `eqts`neq'' `r(tsops)'
				local eqvlist`neq' `eqvlist`neq'' `r(vars)'
			}
			local eqnames : coleq `b'
			local eqnames : list uniq eqnames
			foreach eqn of local eqnames {
				matrix `bi' = `b'[1,"`eqn':"]
				local cnames : colnames `bi'
				if "`cnames'"!="_cons" & "`cnames'"!="_se" {
					local eqname`++neq' `eqn'
					SplitTSOp `: list uniq cnames'
					local eqts`neq' `eqts`neq'' `r(tsops)'
					local eqvlist`neq' ///
						`eqvlist`neq'' `r(vars)'
				}
			}
			matrix drop `bi'
		}
	}
	else {
		*if "`eq'" != "" {
		*	dis as err "option equation not allowed with varlist()"
		*	exit 198
		*}

		local spec   `"`eqlist'"'
		*di "spec = |`eqlist'|"
		local spc : subinstr local spec ":" ":" , all count(local eqcnt)
		if `eqcnt' {
			local neq = 0
			gettoken tok spec : spec, match(parens)
			while `"`tok'"' != "" {
				gettoken eqname tok : tok, parse(":=")
				gettoken equal  tok : tok, parse(":=")
				if "`equal'" != ":" {
					dis as err `"equation list invalid; ":" expected"'
					exit 198
				}
				local eqname`++neq' `eqname'
				tsunab vnames : `tok'
				SplitTSOp `: list uniq vnames'
				local eqts`neq' `r(tsops)'
				local eqvlist`neq' `r(vars)'

				if trim(`"`spec'"') == "" {
					continue, break
				}
				gettoken tok spec : spec, match(parens)
				*if !inlist(`"`tok'"',"/","\") {
				*	dis as err "varlist() invalid; \ or / expected"
				*	exit 198
				*}
				*gettoken tok spec : spec, parse("\/")
			}
		}
		else {
			local neq = 1
			tsunab vnames : `eqlist'
			SplitTSOp `: list uniq vnames'
			local eqts`neq' `r(tsops)'
			local eqvlist`neq' `r(vars)'
			confirm var `eqvlist`neq''
		}
	}

	qui count if e(sample)
	local sampsz = r(N)

// fix eqts lists
//     0) "0" indicates no ts ops
//     1) Put the ts operator "__." for those without ts ops (currently marked
//        as "0") that are next to the same named var that does have ts ops.
//     2) Prepend a "@" on the ts operator to indicate that this is the first
//        one for this variable (so we need to output the varname etc.)

	forvalues ieq = 1/`neq' {
		local tsl `eqts`ieq''
		local eqts`ieq'
		local vll `eqvlist`ieq''
		local prev
		local pret 0
		foreach v of local vll {
			// capture here in case variable doesn't exist
			capture count if e(sample) & !missing(`v')
			if _rc==0 & `r(N)' != `sampsz' {
				local junk `e(depvar)'
				local junk : subinstr local junk "`v'" "", ///
					count(local matches)
				if `matches' == 0 {
di as text "`v' " as err "has fewer observations than estimation sample (" _c
di as text `r(N)' as err " versus " as text `sampsz' as err ")"
exit 498
				}
				else {
					local depnote "y"
				}
			}
			gettoken tsop tsl : tsl
			local vtmp `ferest()'
			if "`vtmp'" != "" {
				gettoken nextv : vtmp
				gettoken nextt : tsl
			}
			else {
				local nextv
				local nextt 0
			}
			if "`v'" != "`prev'" {
				local prev `v'
				if "`tsop'" != "0" {
					local eqts`ieq' `eqts`ieq'' @`tsop'
					local pret "`tsop'"
					continue
				}
				// know "`tsop'" == 0 now
				if "`v'" == "`nextv'" & "`nextt'" != "0" {
					local eqts`ieq' `eqts`ieq'' @__.
					local pret "`tsop'"
					continue
				}
				local eqts`ieq' `eqts`ieq'' `tsop'
				local pret "`tsop'"
				continue
			}
			// know "`v'" == "`prev'" now
			if ("`tsop'" == "0") & ("`pret'" != "0" | ///
					("`nextv'"=="`v'" & "`nextt'"!="0")) {
				local eqts`ieq' `eqts`ieq'' __.
				local pret "`tsop'"
				continue
			}
			local eqts`ieq' `eqts`ieq'' `tsop'
			local pret "`tsop'"
		}
	}

// check that weights can be evaluated and e(cluster) can be found

	if "`e(wtype)'" != "" & "`weights'" != "noweights" {
		tempvar wvar
		capture quietly gen `wvar' `e(wexp)' if e(sample)
		if _rc {
			dis as err "weighting expression cannot be evaluated"
			capture gen `wvar' `e(wexp)'
			exit 111
		}
		label var `wvar' `"`e(wexp)'"'
		char `wvar'[varname] _weight

		// summary will be weighted same as estimation cmd
		if "`e(wtype)'" == "pweight" {
			// treat pweight as aweight for -summarize-
			// produces okay mean and std. dev.
			local wt "[aweight=`wvar']"
		}
		else {
			local wt "[`e(wtype)'=`wvar']"
		}

		if "`e(wtype)'" == "fweight" {
			// will pass along f weight to report weighted N
			// a, i, and p weights do not change N
			local fwvar `wvar'
		}
	}

	if "`e(clustvar)'" != "" {
		capture confirm variable `e(clustvar)'
		if _rc {
			dis as err "cluster() variable `e(clustvar)' not found"
			exit 111
		}
	}

// width of table including variable labels

	local len = 21
	if "`labels'" != "" {
		forvalues ieq = 1 / `neq' {
			foreach v of local eqvlist`ieq' {
				if ("`v'" == "_cons") continue
				if ("`v'" == "_se") continue
				if (substr("`v'",1,4) == "_cut") continue

				capture confirm var `v'
				if !_rc {
				    local len = ///
					max(`len', length(`"`:var label `v''"'))
				}
			}
		}

		if "`e(wtype)'" != "" & "`weights'" != "noweights" {
			// wvar was generated and labeled previously
			local len = max(`len', length(`"`:var label `wvar''"'))
		}

		local vlwidth = min(`:set linesize' - 57, `len')
		local llength = 53 + `vlwidth'
	}
	else {
		local vlwidth = min(`:set linesize' - 57, `len')
		local llength = 53
	}

// display table

	tempname stats

	if "`header'" == "" {
		Header "`labels'" `llength' `fwvar'
	}
	HeaderTab `llength' "`labels'"

	forvalues ieq = 1/`neq' {
		if "`eqname`ieq''" != "" {
			DispEqn "`eqname`ieq''" "`labels'"
		}
		local eqts `eqts`ieq''
		foreach v of local eqvlist`ieq' {
			gettoken tsop eqts : eqts
			if ("`v'" == "_cons") continue
			if ("`v'" == "_se")  continue
			if (substr("`v'",1,4) == "_cut")  continue

			Stats "`eqname`ieq''" `v' "`labels'" `vlwidth' ///
				`tsop' "`wt'"
			matrix `stats' = nullmat(`stats') \ r(stats)
		}
		if `ieq' < `neq' {
			Line "+" `llength' "`labels'"
		}
	}

	if "`e(wtype)'" != "" & "`weights'" != "noweights" {
		Line "+" `llength' "`labels'"
		if "`eq'" != "" {
			local weq weight
		}
		// summary statistics of weights are themselves unweighted
		Stats "`weq'" `wvar' "`labels'" `vlwidth' ///
			0  "" /* i.e., no `wt' here! */
		matrix `stats' = nullmat(`stats') \ r(stats)
	}
	Line "BT" `llength' "`labels'"

	// warn if cluster()
	if `"`e(cluster)'"' != "" | `"`e(clustvar)'"' != "" {
		if "`labels'" != "" {
			di as smcl "Std. Dev. not adjusted for clustering"
		}
		else {
			di as smcl "  Std. Dev. not adjusted for clustering"
		}
	}
	
	// warn if depvars based on missing values
	if "`depnote'" != "" {
		local dvars `e(depvar)'
		foreach dv of local dvars {
			qui count if e(sample) & !missing(`dv')
			if `r(N)' != `sampsz' {
di as smcl "  `dv' statistics based on `r(N)' nonmissing observations"	
			}
		}
	}
			
	return matrix stats = `stats'
end

// ---------------------------------------------------------------------------
// subroutines
// ---------------------------------------------------------------------------

// Stats eqname vname vlwidth tsop wgtexp
// displays a statistics line for vname, with vlwidth chars for var label
//
// if char vname[varname] is defined, it is used as varname instead of vname.
//

⌨️ 快捷键说明

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