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

📄 svy_est_7.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*! version 1.0.9  01may2003 updated 20dec2004
program define svy_est_7
/*
   Syntax:  svy_est svycmd `0'
*/
	version 6, missing
	gettoken svycmd 0 : 0

	if replay() {
		if `"`e(cmd)'"'!="`svycmd'" {
			error 301
		}
		svy_dreg `0'  /* display results */
		exit
	}
	nobreak {
		capture noisily break {

		/* Create some temps for `svycmd' programs.
		   Note: S_VYtmp* are NOT used in svy_est.ado.
		*/
			tempvar doit
			tempname tmp1 tmp2 tmp3 tmp4 tmp5 tmp6 tmp7 tmp8 tmp9
			macro drop S_VY*
			global S_VYtmp1 `tmp1'
			global S_VYtmp2 `tmp2'
			global S_VYtmp3 `tmp3'
			global S_VYtmp4 `tmp4'
			global S_VYtmp5 `tmp5'
			global S_VYtmp6 `tmp6'
			global S_VYtmp7 `tmp7'
			global S_VYtmp8 `tmp8'
			global S_VYtmp9 `tmp9'

			SvyParse `svycmd' `doit' `0'

			local dopts $S_VYdopt /* save display options */

			SvyEst `svycmd' `doit'
		}

		local rc = _rc
		macro drop S_VY*

		if `rc' {
			estimates clear
			exit `rc'
		}
	}
	svy_dreg, `dopts' /* display results */
end

program define SvyEst, eclass
	args svycmd doit

	tempvar postit
	tempname b V Vdeff npop

/* Create necessary tempvars for scores. */

	`svycmd' 0 how_many_scores

	if "`svycmd'"=="svymlogit" | /*
	   */ "`svycmd'"=="svyologit" | /*
	   */ "`svycmd'"=="svyoprobit" {
		if $S_VYncat > 50 {
			error 149
		}
	}

	local i 1
	while `i' <= r(k_scores) {
		tempvar s
		local sclist `sclist' `s'
		local i = `i' + 1
	}

	if `r(cmdcando)' {
		local scopt score(`sclist')
	}

/* Are any of the options -log-, -trace-, -gradient-, -hessian-,
   or -showstep- specified?
*/
	Option "LOg TRace GRADient HESSian SHOWSTEP", $S_VYeopt

	if !`r(option)' {
		if "`svycmd'"=="svylogit" | "`svycmd'"=="svyprobit" {
			local nocoef "nocoef nolog"
		}
		else local quicmd "quietly"

		local quidi   "*"        /* do not display comment */
		local quimeff "quietly"  /* do not display meff computation */
	}

/* Get D, where V = DMD. */

	if "$S_VYwgt"!="" {
		local wt [iw=$S_VYexp]
		local wgted "weighted "
	}
	if "`svycmd'"=="svyreg" | "`svycmd'"=="svyivreg" {
		local mse1 "mse1"
	}

	`quidi' di _n in gr "Computing point estimates using `wgted'" /*
	*/ in ye "$S_VYcmd" in gr ":"

	estimates clear

	`quicmd' $S_VYcmd $S_VYdepv $S_VYindv `wt' if $S_VYsub, /*
	*/ $S_VYeopt `mse1' `nocoef' `scopt'

	quietly count if e(sample) /* can't trust commands with iweights
	                              to get #obs right
				   */
	local nobs `r(N)'

	matrix `b' = e(b)
	matrix `V' = e(V)
	global S_VYb `b'
	global S_VYV `V'

/* Compute scores for commands that cannot, or do other work. */

	if "`svycmd'"=="svyivreg" { preserve }

	`svycmd' 0 scores `doit' `sclist'

/* Replace missing scores with zeros. */

	tokenize `sclist'
	local i 1
	while "``i''"!="" {
		capture replace ``i'' = 0 if ``i''>=.
		if _rc {
			local `i' " "
		}
		local i = `i' + 1
	}

/* Compute variance estimates. */

	_robust `*' `wt' if `doit', v(`V') vsrs(`Vdeff') /*
	*/ $S_VYopt zeroweight

/* Save results from _robust(). */

	global S_VYn    `r(N)'	      /* number of obs    */
	global S_VYnstr `r(N_strata)' /* number of strata */
	global S_VYnpsu `r(N_clust)'  /* number of PSUs   */
	scalar `npop'  = r(sum_w)     /* population size  */

	if r(N_sub)<. {
		tempname nsubpop
		global S_VYosub   `r(N_sub)'    /* # subpop. obs */
		scalar `nsubpop' = r(sum_wsub)  /* subpop. size  */
	}

	if "`svycmd'"=="svyivreg" { restore }

/* Get misspecified estimates if meff or meft specified. */

	Option "MEFF MEFT", $S_VYdopt /* was meff or meft specified? */

	if `r(option)' {
		`quimeff' di _n in gr "Computing misspecified " /*
		*/ in ye "$S_VYcmd" in gr " model for meff/meft compution:"

		estimates clear

		`quimeff' $S_VYcmd $S_VYdepv $S_VYindv if $S_VYsub, /*
		*/ $S_VYeopt

		tempname Vmeff
		capture matrix `Vmeff' = e(V)
		if _rc {
			matrix `Vmeff' = 0*`V'
		}
		else if e(N)!=`nobs' | colsof(`Vmeff')!=colsof(`V') {
			matrix `Vmeff' = 0*`V'
		}
	}

/* Post results. */

	local df = $S_VYnpsu - $S_VYnstr

	gen byte `postit' = `doit' /* may need `doit' later */
	estimates post `b' `V', dof(`df') esample(`postit')

/* Save other results. */

	SvySave `npop' "`nsubpop'" `Vdeff' "`Vmeff'" /* save common results */

	`svycmd' 0 save         /* save special results */

	est local cmd `svycmd'
	global S_E_cmd `e(cmd)' /* double save */
end

/*----------------------------- Parse programs -------------------------------*/

program define SvyParse
	gettoken svycmd 0 : 0
	gettoken doit   0 : 0

/* S_VY macros:

	S_VYdopt  display options
	S_VYeopt  estimation options
	S_VYopt   options for _robust

	S_VYadj   "noadjust" if specified
	S_VYsrss  "srssubpop" if specified

	S_VYdepv  dependent variable(s)
	S_VYindv  independent variables
	S_VYmodl  variable for model test

	S_VYwgt   weight type
	S_VYexp   weight expression
	S_VYstr   strata variable
	S_VYpsu   psu variable
	S_VYfpc   fpc variable

	S_VYsub	  subpop. expression = "`doit'" or "`doit' & `subpop'!=0"
*/

/* Call `svycmd' with "syntax" query to get # of dependent variables
   `s(k_depvar)', allowed command options `s(okopts)', special display
   options `s(dopts)', and whether there are ml options `s(mlopts)'.
*/
	`svycmd' 0 syntax `0'
	local cmd `s(cmd)'
	local k_dv `s(k_depvar)'
	local okopts `s(okopts)'
	local dopts `s(dopts)'

	if "`s(mlopts)'"=="yes" {
		local mlopts "LOg *"
	}
	if "`s(new0)'"!="" {
		local 0 `s(new0)'
	}

/* Parse and check for some errors. */

	syntax varlist(min=`k_dv' numeric) [pw iw/] [if] [in] [, /*
	*/ noCONstant STRata(varname) PSU(varname) FPC(varname numeric) /*
	*/ SUBpop(varname numeric) SRSsubpop noADJust /*
	*/ Level(cilevel) Prob CI DEFF DEFT MEFF MEFT EForm /*
	*/ `okopts' `dopts' `mlopts' `offset' ]


	if "`mlopts'"!="" {
		mlopts mlopts, `options'
		CkConst ,`mlopts'
		
	}
	if "`srssubp'"!="" & "`subpop'"=="" {
		di in red "srssubpop can only be specified when subpop() " /*
		*/ "is specified"
		exit 198
	}

/* Set global macros. */

	global S_VYcmd  `cmd'   /* name of underlying command */
	global S_VYsrss `srssubp'  /* srssubpop option flag */
	global S_VYadj  `adjust'   /* do unadjusted F test if !="" */
	global S_VYopt  `srssubp'  /* options for _robust; more added later */

/* Display options. */

	global S_VYdopt level(`level') `prob' `ci' `deff' `deft' /*
	*/ `meff' `meft' `eform'

	local opts `dopts'
	while "`opts'"!="" { /* add special display options to S_VYdopt */
		NextOpt `opts'
		global S_VYdopt $S_VYdopt ``r(macro)''
		local opts `r(rest)'
	}

/* Options for estimation. */

	global S_VYeopt `constan' `log' `mlopts'

	local opts `okopts'
	while "`opts'"!="" { /* add other allowed options to S_VYeopt */
		NextOpt `opts'
		if "``r(macro)''"!="" {
			if `r(varlist)' {
				local markout `markout' ``r(macro)''
				global S_VYeopt $S_VYeopt /*
				*/ `r(option)'(``r(macro)'')
			}
			else global S_VYeopt $S_VYeopt ``r(macro)''
		}
		local opts `r(rest)'
	}

	CkConst , $S_VYeopt 

/* Split off dependent and independent variables. */

	local i 1
	while `i' <= `k_dv' {
		gettoken var varlist : varlist
		global S_VYdepv $S_VYdepv `var'
		local i = `i' + 1
	}
	global S_VYindv `varlist' /* RHS for command */

	if "`constan'"!="" & "$S_VYindv"=="" {
		di in red /*
		*/ "independent variables required with noconstant option"
		exit 100
	}

/* Get weights. */

	if `"`exp'"'=="" {
		svy_get pweight, optional

⌨️ 快捷键说明

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