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

📄 svy_est_7.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
		local exp `s(varname)'
	}
	else if "`weight'"=="pweight" { /* try to varset pweight variable */
		capture confirm variable `exp'
		if _rc==0 {
			svy_get pweight `exp'
			local exp `s(varname)'
		}
	}
	if "`exp'"!="" {
		global S_VYexp `exp'
		if "`weight'"!="" { global S_VYwgt `weight' }
		else		    global S_VYwgt "pweight"

		local wt [$S_VYwgt=$S_VYexp]
	}

/* Get strata, psu, and fpc. */

	svy_get strata `strata', optional
	global S_VYstr `s(varname)'
	if "$S_VYstr"!="" { global S_VYopt $S_VYopt strata($S_VYstr) }

	svy_get psu `psu', optional
	global S_VYpsu `s(varname)'
	if "$S_VYpsu"!="" { global S_VYopt $S_VYopt psu($S_VYpsu) }

	svy_get fpc `fpc', optional
	global S_VYfpc `s(varname)'
	if "$S_VYfpc"!="" { global S_VYopt $S_VYopt fpc($S_VYfpc) }

/* Mark/markout. */

	mark `doit' `wt' `if' `in', zeroweight

	if "`svycmd'"=="svyintreg" {
		markout `doit' $S_VYindv $S_VYfpc `subpop' `markout'
		local y1 : word 1 of $S_VYdepv
		local y2 : word 2 of $S_VYdepv
		qui replace `doit' = 0 if `y1'>=. & `y2'>=.
	}
	else	markout `doit' $S_VYdepv $S_VYindv $S_VYfpc `subpop' `markout'

	markout `doit' $S_VYstr $S_VYpsu, strok

/* Compute total #obs. */

	qui count if `doit'
	local nobs = r(N)
	if `nobs' == 0 { error 2000 }
	if "$S_VYwgt"!="" {
		qui count if `doit' & ($S_VYexp)!=0
		if r(N) == 0 {
			di in blu "all observations have zero weights"
			exit 2000
		}
	}

/* Handle subpop.  If no subpop, S_VYsub is mark variable `doit'. */

	if "`subpop'"=="" {
		global S_VYsub `doit'
	}
	else {
		global S_VYopt $S_VYopt subpop(`subpop')
		global S_VYsub (`doit'&`subpop'!=0)
		global S_VYsubv `subpop'

		svy_sub_7 `doit' `subpop' "$S_VYexp" "$S_VYstr"
	}

/* Remove collinearity. */

/* 	if "`svycmd'"!="svyreg" & "`svycmd'"!="svyivreg" { */
		_rmcoll $S_VYindv `wt' if $S_VYsub, `constan'
		global S_VYindv `r(varlist)'
/*	} */

/* Save variables for model test; it may be reset by some commands. */

	global S_VYmodl $S_VYindv
end

program define NextOpt, rclass
	gettoken option 0 : 0, parse(" (")
	ret local option = lower("`option'")
			/* this is the option name */
	ret local macro = substr("`return(option)'",1,7)
			/* this is the macro name */
	ret scalar varlist = 0

/* Check if it is an "xxx(...)" option. */

	gettoken next 0 : 0, match(parens)
	if "`parens'"=="(" {
		local next = substr(ltrim("`next'"),1,7)
		if "`next'"=="varname" | "`next'"=="varlist" {
			ret scalar varlist = 1
		}

		ret local rest `0'
	}
	else	ret local rest `next' `0'
end

program define Option, rclass
	gettoken opts 0 : 0, parse(" ,")
	syntax [, `opts' *]

	while "`opts'"!="" {
		NextOpt `opts'
		if "``r(macro)''"!="" {
			return scalar option = 1
			return local contents ``r(macro)''
			exit
		}
		local opts `r(rest)'
	}

	return scalar option = 0
end

/*--------------------------- Save results program ---------------------------*/

program define SvySave, eclass
	args npop nsubpop Vdeff Vmeff

	est scalar N_pop = `npop'	  /* population size   	     */

	if "`nsubpop'"!="" {
		est scalar N_sub = $S_VYosub    /* # subpop. obs     */
		est scalar N_subpop = `nsubpop' /* subpop. size      */
	}

/* Save results from S_VY* macros. */

	est scalar N        = $S_VYn	 /* number of obs	     */
	est scalar N_strata = $S_VYnstr  /* number of strata	     */
	est scalar N_psu    = $S_VYnpsu  /* number of PSUs	     */
	est scalar df_r     = e(N_psu) - e(N_strata) /* df           */

	est local depvar  $S_VYdepv    /* dependent variable(s)      */
	est local wtype	  $S_VYwgt     /* weight type                */
	if "$S_VYexp"!="" {
		est local wexp "= $S_VYexp" /* weight expression     */
	}
	est local strata  $S_VYstr     /* strata variable            */
	est local psu     $S_VYpsu     /* psu variable               */
	est local fpc     $S_VYfpc     /* fpc variable               */
	est local subpop  $S_VYsubv    /* subpop variable            */
	est local adjust  $S_VYadj     /* "noadjust" if specified    */
	est local svy_est svy_est      /* used by svy_dreg           */

	Option "OFFset(varname numeric)", $S_VYeopt
	if `r(option)' {
		est local offset `r(contents)' /* offset variable    */
	}

	Option "EXPosure(varname numeric)", $S_VYeopt
	if `r(option)' {
		est local offset ln(`r(contents)') /* offset variable */
	}

/* Double saves. */

	global S_E_nobs = e(N)            /* number of obs	     */
	global S_E_nstr = e(N_strata)     /* number of strata	     */
	global S_E_npsu = e(N_psu)        /* number of PSUs	     */
	global S_E_npop = e(N_pop)        /* pop. size   	     */

	if e(N_sub)<. {
		global S_E_osub = e(N_sub)         /* # subpop. obs  */
		global S_E_nsub = e(N_subpop)      /* subpop. size   */
	}

	global S_E_wgt  `e(wtype)'   /* weight type                  */
	global S_E_exp  `e(wexp)'    /* weight expression            */
	global S_E_str  `e(strata)'  /* strata variable              */
	global S_E_psu  `e(psu)'     /* psu variable                 */
	global S_E_fpc  `e(fpc)'     /* fpc variable                 */
	global S_E_depv `e(depvar)'  /* dependent variable(s)        */
	global S_E_adj  `e(adjust)'  /* "noadjust" if specified      */

/* Compute model F test: create e(F) and e(df_m). */

	Ftest

/* Make matrices e(deff), e(deft), and e(V_srs).
   If fpc, make matrix e(V_srswr).
   If meff or meft, make matrices e(V_msp) and e(meft).
*/
	MakeDeff `Vdeff'
	if "`Vmeff'"!="" { MakeMeff `Vmeff' }
end

program define Ftest, eclass
	if "$S_VYmodl"!="" {
		capture test $S_VYmodl, min

		if _rc==0 {
			est scalar df_m = r(df)

			if reldif(r(drop) ,0)<1e-10  | "$S_VYcnt" =="yes" {
				if "`e(adjust)'"=="" { /* adjusted (default) */
					if e(df_r)-e(df_m)+1 > 0 {
						est scalar F = /*
					*/ r(F)*(e(df_r)-e(df_m)+1)/e(df_r)
					}
				}
				else { /* unadjusted */
					est scalar F = r(F)
				}
			}
			else {
				est scalar F = .
			}	
		}
	}
	else est scalar df_m = 0
		
/* Double saves. */

	global S_E_f = e(F)
	global S_E_mdf = e(df_m)
end

program define MakeDeff, eclass
	args Vsrs

/* Compute Vsrswr if fpc() specified. */

	tempname f V deff deft

	if "`e(fpc)'"!="" { /* create V_srswr matrix */
		if "$S_VYsrss"=="" {
			scalar `f' = 1/(1-e(N)/e(N_pop))
		}
		else	scalar `f' = 1/(1-e(N_sub)/e(N_subpop))

		if `f'>=. { scalar `f' = 0 }

		tempname Vsrswr
		matrix `Vsrswr' = `f'*`Vsrs' /* unwind fpc on Vsrs */
	}
	else	local Vsrswr `Vsrs'

/* Create row vectors containing deff and deft. */

	matrix `V' = e(V)
	matrix `V' = vecdiag(`V')
	matrix `deff' = `V'
	matrix `deft' = `V'

	local dim = colsof(`V')
	local i 1
	while `i' <= `dim' {
		scalar `f' = `V'[1,`i']/`Vsrs'[`i',`i']
		matrix `deff'[1,`i'] = cond(`f'<., `f', 0)

		scalar `f' = sqrt(`V'[1,`i']/`Vsrswr'[`i',`i'])
		matrix `deft'[1,`i'] = cond(`f'<., `f', 0)

		local i = `i' + 1
	}

/* Save matrices. */

	est matrix V_srs `Vsrs'
	est matrix deff  `deff'
	est matrix deft  `deft'

	if "`e(fpc)'"!="" {
		est matrix V_srswr `Vsrswr'
	}

/* Double saves. */

	matrix S_E_Vsrs = e(V_srs)
	matrix S_E_deff = e(deff)
	matrix S_E_deft = e(deft)

	if "`e(fpc)'"!="" {
		matrix S_E_Vswr = e(V_srswr)
	}
end

program define MakeMeff, eclass
	args Vmeff

/* Create row vector containing meft. */

	tempname V f meft
	matrix `V' = e(V)
	matrix `V' = vecdiag(`V')
	matrix `meft' = `V'

	local dim = colsof(`V')
	local i 1
	while `i' <= `dim' {
		scalar `f' = sqrt(`V'[1,`i']/`Vmeff'[`i',`i'])
		matrix `meft'[1,`i'] = cond(`f'<., `f', 0)

		local i = `i' + 1
	}

/* Save matrices. */

	est matrix V_msp `Vmeff'
	est matrix meft `meft'

/* Double saves. */

	matrix S_E_Vmsp = e(V_msp)
	matrix S_E_meft = e(meft)
end


program define CkConst
		syntax [, CONSTRAINTS(string) * ]
		if "`constraints'" != "" {
			global 	S_VYcnt "yes"
		}	
end		

/******************************** end of file ********************************/

⌨️ 快捷键说明

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