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

📄 varirf_ctable.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*! version 2.4.7  17jan2005
program varirf_ctable, rclass
	version 8.0
	syntax anything(name=tabspeclist id="table specifications")	/*
	*/ [,							/*
	*/ INdividual						/*
	*/ STep(numlist max=1 integer >0 <=500)			/* 
	*/ Level(passthru)					/*
	*/ noCI							/*
	*/ STDerror						/*
	*/ set(string)						/*
	*/ TItle(string)					/*
	*/ ]

	if "`ci'" != "" & "`level'" != "" {
		di as err "{cmd:noci} and {cmd:level()} cannot "	/*
			*/ "both be specified"
		exit 198
	}
	
	local zero `0'
	local 0 ", `level'"
	local backopt `options'
	syntax [, level(cilevel)]
	local 0 `zero'
	local options `backopt'

/* remap ci to g_ci and stderror -> g_stderror */
	if "`ci'" != "" {
		local g_ci noci
		local ci 
	}

	if "`stderror'" != "" {
		local g_stderror stderror
		local stderror 
	}

	/* check options */

	/* global options that conflict with options in `tabspeclist' are
	 * given the "g_" prefix
	 */

	local g_title `title'
	
	if "`level'" == "" {
		local g_level $S_level
	}
	else {
		local g_level `level'
	}

	/* set a new varirf data file */
	if `"`set'"' != "" {
		varirf set `set'
	}

	preserve
	_virf_use
	if "`step'" != "" {
		qui keep if step <= `step' + 1
	}	

	/* See NOTES at bottom of this file. */

	local k 0
	local k_u 0
	tempvar jvar
	qui gen int `jvar' = .
	local tspecid table specification

	/* BEGIN parse through the table specifications */
	while `"`tabspeclist'"' != "" {
		local ++k
		gettoken 0 tabspeclist : tabspeclist , match(parns)
		syntax anything(id="`tspecid'" name=tspec)	/*
		*/ [,						/*
		*/ noCI						/*
		*/ STDerror					/*
		*/ Level(passthru)				/*
		*/ ITItle(string)				/*
		*/ ]

		/* reset print ci flag to off */

		if "`g_stderror'" != "" | "`stderror'" != "" {
			local stderror stderror
		}
		else {
			local stderror 
		}


		if "`g_ci'" != "" | "`ci'" != "" {
			local ci noci
		}
		else {
			local ci 
		}

		if `"`ititle'"' != "" & "`individual'" == "" {
			di as err  "{cmd:individual} cannot be "	/*
				*/ "empty when {cmd:ititle()} is "	/*
				*/ "specified in a `tspecid'"
			exit 198
		}

		if `"`level'"' != "" & "`individual'" == "" {
			di as err "{cmd:individual} cannot be empty "	/*
				*/ "when {cmd:level()} is "	/*
				*/ "specified in `tspecid'"
			exit 198
		}

		if "`level'" != "" & "`g_ci'" != "" {
			di as err "{cmd:noci} and {cmd:level()} "	/*
				*/ "cannot both be specified"
			exit 198
		}	

		if "`level'" != "" & "`ci'" != "" {
			di as err "{cmd:noci} and {cmd:level()} "	/*
				*/ "cannot both be specified"
			exit 198
		}	

		if "`level'" != "`c(level)'" {
			local level `g_level'
		}

		local title`k' `"`ititle'"'

		/* check for error */
		gettoken tmp1 tmp2 : tspec , parse("()")
		local base `tspec'
		if `"`tmp2'"' != `""' {
			di as err `"tables not properly specified in `0'"'
			exit 198
		}

		gettoken irfname  base  : base
		if "`irfname'" == "" {
			di as err "{cmd:irfname} cannot be empty"
			exit 198
		}	
		local validirfs : char _dta[irfnames]
		local tmp_ck : subinstr local validirfs "`irfname'" 	/*
			*/ "`irfname'", count( local ck_found) word
		if `ck_found' < 1 {
			di as err "`irfname' is not a valid irfname"
			exit 498
		}	

		local ckvec : char _dta[`irfname'_model]
		if "`ckvec'" == "vec" {
			local ci noci
		}	
 

		gettoken impulse  base  : base
		if "`impulse'" == "" {
			di as err "{cmd:impulse} cannot be empty"
			exit 198
		}	
		local validimps : char _dta[`irfname'_order]
		local tmp_ck : subinstr local validimps "`impulse'" 	/*
			*/ "`impulse'", count( local ck_found) word
		if `ck_found' < 1 {
			di as err "`impulse' is not a valid impulse"
			exit 498
		}	
		
		gettoken response stats : base
		if "`response'" == "" {
			di as err "{cmd:response} cannot be empty"
			exit 198
		}	
		local tmp_ck : subinstr local validimps "`response'" 	/*
			*/ "`response'", count( local ck_found) word
		if `ck_found' < 1 {
			di as err "`response' is not a valid response"
			exit 498
		}	

		if "`stats'" == "" {
			di as err "{cmd:statlist} cannot be empty"
			exit 198
		}	
		capture confirm variable `stats'
		if _rc > 0 {
			di as err "`stats' not valid"
			exit 198
		}

		local adj_level = `level'/100 + (100-`level')/200
		tempname zz
		scalar `zz' = invnorm(`adj_level')

		local uniqs : list uniq stats
		local uniq : list uniqs == stats
		if `uniq' != 1 {
			di as err "duplicate elements found in `stats'"
			exit 198
		}	

		local ns : word count `stats'
		if "`ci'" == "" {
			local ns = 3*`ns'
		}

		if "`ci'" == "" {
			local levlist `levlist' `level'	 
		}
		else {
			local levlist " `levlist' . " 
		}

		CheckTriple `irfname' `impulse' `response'
		local cond `r(condition)'
		sum `jvar' if `cond', meanonly
		if r(N) != 0 {
			/* current triple already seen */
			if r(min) == r(max) {
				local k_u = r(min)
				local irflist `irflist' `irfname'
				local impl `impl' `impulse'
				local resl `resl' `response'
			}
			else {	/* should never happen */
				di as err /*
*/ "internal varirf_ctable error, unique assumption invalid"
				exit 459
			}
		}
		else {
			/* current triple is new */
			qui count if `cond' & missing(`jvar')
			if r(N) > 0 {
				local ++k_u
				qui replace `jvar' = `k_u' if `cond'
				local irflist `irflist' `irfname'
				local impl `impl' `impulse'
				local resl `resl' `response'
			}
			else {	/* should never happen */
				di as err /*
*/ "internal varirf_ctable error, failed to catch invalid triple"
				exit 459
			}
		}
		/* build the column lists */
		foreach stat of local stats {

			local slist `slist' `stat'
			local nlist `nlist' `stat'
			local nsind `nsind' `ns'
			local k_ulist `k_ulist' `k_u'

			/* # of columns in the current block */
			local bcols  1

			if "`ci'" == "" {
				if "``stat'_ci'" == "" {
					capture confirm variable std`stat'
					tempvar `stat'_ll `stat'_ul
					qui gen double ``stat'_ll' = `stat' - /*
						*/ std`stat'*`zz'
					qui gen double ``stat'_ul' = `stat' + /*
						*/ std`stat'*`zz'
					local `stat'_ci created
				}
				local slist `slist' ``stat'_ll' ``stat'_ul'
				local nlist `nlist' Lower Upper
				local nsind `nsind' `ns' `ns'
				local k_ulist `k_ulist'  `k_u' `k_u'

				local bcols = `bcols' + 2
			}

			if "`stderror'" != "" {
				local slist `slist' std`stat'
				local nlist `nlist' S.E.
				local nsind `nsind' `ns'
				local k_ulist `k_ulist'  `k_u'

				local bcols = `bcols' + 1
			}

			forvalues cnt = 1/`bcols' {
				local k_list `k_list' `k'
				local blen `blen' `bcols'
			}
		}
	}
	local K `k'	/* number of tspecs */
	/* END parse through the table specifications */

	/* check that lists contain the same number of elements (columns) */
	local nnames : word count `nlist'
	local nstats : word count `slist'
	if `nnames' != `nstats' {
		di as error /*
*/ "internal varirf_ctable error, name and stat lists do not match "
		exit 498
	}
	local ncols : word count `k_ulist'
	if `ncols' != `nstats' {
		di as error /*
*/ "internal varirf_ctable error, name and k_u lists do not match "
		exit 498
	}

	local unique : list uniq slist

	qui drop if missing(`jvar')

	sum `jvar', meanonly
	local k_umax = r(max)
	keep `unique' step `jvar'
	qui reshape wide `unique', i(step) j(`jvar')

	/* set initial values for calculating column positions.  */
	local lstepc 10
	local lstepcm2 = `lstepc' -2
	local lstfmt 6
	local lcol 12
	local lcolm2 = `lcol' -2
	local lcolm1 = `lcol' -1
	local lcfmt 8

	local stind0 = int((`lstepc'-`lstfmt')/2)
	local linesize : set linesize
	local cpline = int((`linesize'-`lstepc')/`lcol')

	local linelen = `lstepc' + `cpline'*`lcol'
	local linelenm2 = `lstepc' + `cpline'*`lcol'-2

	sum step, meanonly
	local smax =r(max) + 1

	local cpos 0

	/* subtract 4 for step
	 *

⌨️ 快捷键说明

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