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

📄 ml_model.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
		}
		else	global ML_crtyp "log likelihood"
	}
	else {
		global ML_crtyp = trim(substr(`"`crittype'"',1,32))
	}
	if "$ML_vce" == "robust" {
		if "`vce'" != "" {
			di as err ///
			"options vce() and robust may not be combined"
			exit 198
		}
		local vce vce(oim)
	}
/* end set -robust- option */


/* set -bracket- option for computation of numeric derivative */
	global ML_brack `bracket'
/* end set -bracket- option */


/* ---- begin method description processing -- routine m<method>_.ado */
	local methi = "m" + substr("$ML_meth",1,30) + "_"
	if `"`technique'`vce'"'!="" {
		global ML_tech `", `technique' `vce'"'
		local methi `"`methi', `technique' `vce'"'
		local techniq
		local vce
	}
	capture `methi'
	if _rc | `"`r(method)'"' != "$ML_meth" {
		if _rc!=199 { 
			`methi'
		}
		di in red "unknown method $ML_meth"
		exit 199
	}
	global ML_opt `"`r(opt)'"'
	global ML_tnql `"`r(techlist)'"'	// list of techniques to use
	global ML_tnqk `"`r(numlist)'"'		// steps within each technique
	global ML_tnqi 1			// index for current technique
	global ML_tnqj 1			// step in current technique
	global ML_eval `"`r(eval)'"'
	global ML_evali `"`r(evali)'"'
	global ML_evalf `"`r(evalf)'"'
	global ML_noinv `"`r(noinv)'"'
	global ML_noinf `"`r(noinf)'"'
	global ML_score `"`r(score)'"'
	global ML_vscr `"`r(vscore)'"'
	if "$ML_vce" == "" {
		global ML_vce `"`r(vce)'"'
	}
	global ML_vce2 `"`r(vce2)'"'
	if "`r(scvars)'" != "" {
		global ML_mksc
	}
	local methi
	if `"$ML_opt"'=="" | `"$ML_eval"'=="" {
		if `"$ML_opt"'=="" {
			di in red "method $ML_meth does not specify optimizer"
		}
		if `"$ML_eval"'=="" {
			di in red "method $ML_meth does not specify evaluator"
		}
		di in red "method $ML_meth, program ${ML_eval}_, has an error"
		exit 198
	}
	if "`noscore'" != "" {
		local bhhh bhhh
		local tqlist $ML_tnql
		if "$ML_opt" == "ml_e1_bhhh" | `:list bhhh in tqlist' {
			di as err ///
"technique bhhh is not allowed with option noscore"
			exit 198
		}
	}
/* ---- end method description processing -- routine ml_<method>_.ado */


/* process -nopreserve- option */
	global ML_save
	if r(preserve)==1 {
		global ML_save "true"
	}
	else if r(preserve)>=. {
		if "`preserv'"=="" {	/* -nopreserve- not specified */
			global ML_save "maybe"
		}
	}
/* end process -nopreserve- option */


/* process whether robust, cluster(), and pweights allowed */
	if "$ML_vce"=="robust" {
		if `"$ML_score"' == "" {
			di in red /*
	*/ "method $ML_meth does not allow pweights, robust, or cluster()"
			exit 101
		}
		if "`scvars'" != "" {
			#delimit ;
			di in red
"method $ML_meth does not allow pweights, robust, or cluster() because" _n
"you specified option noscvars" ;
			#delimit cr
			exit 101
		}
	}
/* end process whether robust, cluster(), and pweights allowed */

/* process whether wald test */
	if `waldtes'!=0 {
		if ("$ML_vce"=="robust" | "`lf0'"=="") & `waldtes'<0 {
			local waldtes = abs(`waldtes')
		}
		if `waldtes'>0 {
			global ML_wald `waldtes'
		}
	}
/* end process whether wald test */


/* optionally remove collinearity */
	if "`colline'" == "" {
		RmColl
	}
/* end optionally remove collinearity */


/* save dependent variable names in $ML_y`i' */
	tokenize $ML_y
	local i 1
	if "$ML_yn" == "" {
		global ML_yn 0
	}
	while `i' <= $ML_yn {
		global ML_y`i' ``i''
		local i = `i' + 1
	}

	global ML_title `"`title'"'

/* build coefficient vector */
	Build_b

/* set -constraints- option */
	global ML_C 0		// default for no constraints
	if "`constraints'" != "" {
		if (`caller' <= 8.0) {
			if ( ("$ML_x1" != "") | ("`svarconst'" != "") ) {
				tempname b V T a C
				mat `b' = $ML_b
				mat `V' = `b''*`b'
				mat post `b' `V'
				capture mat makeCns `constraints'
				if _rc {
					di in red "Constraints invalid:"
					mat makeCns `constraints'
					exit _rc
				}
				global ML_cns `constraints'  
			}
		}
		else {
			tempname b V T a C
			mat `b' = $ML_b
			mat `V' = `b''*`b'
			mat post `b' `V'
			makecns `constraints', `cnsnotes'
			global ML_cns `r(clist)'
		}
		if "$ML_cns" != "" {
			matcproc `T' `a' `C'
			global ML_C 1
			global ML_CT ML_CT
			global ML_Ca ML_Ca
			global ML_CC ML_CC
			mat $ML_CT = `T'
			mat $ML_Ca = `a'
			mat $ML_CC = `C'
			// constraints imply a model Wald test
			if "$ML_wald" == "" {
				if "`waldtes'" != "" {
					global ML_wald = abs(`waldtes')
				}
				else {
					global ML_wald 1
				}
			}
			local lf0
		}
	}
/* end set -constraints- option */

/* process -lf0()- (or -continue-) option */
	if "`lf0'" != "" {
		local n : word count `lf0'
		if `n'!=2 {
			di in red "lf0(`lf0') invalid"
			exit 198
		}
		global ML_k0 : word 1 of `lf0'
		global ML_ll_0 : word 2 of `lf0'
		confirm number $ML_ll_0
		confirm integer number $ML_k0
		if $ML_k0 < 0 {				// was $ML_k0 < 1
			di in red "lf0(`lf0') invalid"
			exit 198
		}
	}

/* Probably fully defined; set status variable ML_stat to "model" */
	global ML_stat "model"


/* determine whether we run (or request our caller run) other routines */

	if `"`init'"'!="" {
		ml_init `init'
	}
	if "`maximiz'"!="" {
		sret local maxcmd `"ml_max, nooutput `options'"'
	}
	else if `"`options'"' != "" {
		di in red `""`options'" not allowed"'
		exit 198
	}
end

program define ParseIL /* [name:] [y1 y2 ... =] [x1 x2 ...] 
				[, nocons offset() linear ]
*/
	tokenize `"`0'"', parse(":[]=,")
	if "`2'" == ":" {
		IsNewEqN `1'
		global ML_eq$ML_n `1'
		mac shift 2
	}
	else 	global ML_eq$ML_n eq$ML_n

	local haseq 0
	while "`1'" != "," & "`1'"!="" {
		if "`1'" == "=" {
			if `haseq' {
				di in red `"(`0')"'
				error 198
			}
			local haseq 1
			global ML_y $ML_y `list'
			local list
		}
		else 	local list `list' `1'
		mac shift
	}

	if "$ML_y" != "" {
		tsunab myy: $ML_y
		global ML_y `myy'
		if "`s(tsops)'" != "" {
			global ML_tsops "true"
		}
		local myy
	}
	global ML_yn : word count $ML_y

	if "`list'" != "" {
		tsunab list: `list'
		global ML_x$ML_n `list'
		if "`s(tsops)'" != "" {
			global ML_tsops "true"
		}
	}

	local 0 "`*'"
	syntax [, noCONStant OFFset(varname) EXPosure(varname) Linear ]

	if "`constan'" != "" {
		global ML_xc$ML_n "nocons"
		if "${ML_x$ML_n}" == "" {
			di in red `"(`0')"'
			error 198
		}
	}
	if "`offset'"!="" | "`exposur'"!="" {
		if "`offset'" != "" & "`exposur'" != "" {
			di in red "cannot specify both offset() and exposure()"
			error 198
		}
		global ML_xo$ML_n "`offset'"
		global ML_xe$ML_n "`exposure'"
	}
	global ML_xl$ML_n "`linear'"
end

program define ParsePrm /* name */
	IsNewEqN `0'
	global ML_eq$ML_n `0'
end


program define IsName
	local n : word count `0'
	if `n' == 1 {
		capture confirm var `0'
		if _rc == 0 {
			exit
		}
		capture confirm new var `0'
		if _rc ==0 {
			exit
		}
	}
	di in red `"`0' invalid name"'
	exit 198
end

program define IsNewEqN /* name */
	IsName `0'
	local i 1
	while `i' < $ML_n { 		/* <, sic, filling in $ML_n */
		if "`0'" == "${ML_eq`i'}" {
			di in red "Equation/parameter /`0'/ multiply defined"
			exit 110
		}
		local i = `i' + 1
	}
end

                       /*    1     2    3        4      */
program define SetTmpV /* macname <- namestub [varname] */
	args macn junk stub name
	if `"`name'"' != "" {
		local n : word count `name'
		if `n'!=1 {
			error 198
		}
		confirm new var `name'
		global `macn' `"`name'"'
		exit
	}
	local i 1
	capture confirm new var `stub'`i'
	while _rc {
		local i = `i' + 1
		capture confirm new var `stub'`i'
	}
	global `macn' `stub'`i'
end


program define IsLast /* token */, sclass
	if `"`0'"'=="[" | `"`0'"'=="if" | `"`0'"'=="in" | `"`0'"'=="," | /*
	*/ | `"`0'"'=="" {
		sret local cont 0
	}
	else	sret local cont 1
end


program define RmColl
	local i 1
	while `i' <= $ML_n {
		if "${ML_x`i'}" != "" {
			_rmcoll ${ML_x`i'} if $ML_samp, ${ML_xc`i'}
			global ML_x`i' "`r(varlist)'"
			global S_1 /* cleanup after out-of-date rmcoll */
		}
		local i = `i' + 1
	}
end

program define MarkOut
	markout $ML_samp $ML_y
	local i 1
	while `i' <= $ML_n {
		markout $ML_samp ${ML_x`i'} ${ML_xo`i'} ${ML_xe`i'}
		if "${ML_xe`i'}" != "" {
			qui replace $ML_samp = 0 if ${ML_xe`i'}<=0
		}
		local i = `i' + 1
	}
end

program define Build_b
	global ML_k 0
	local i 1
	capture mat drop $ML_b
	tempname bi
	while `i' <= $ML_n {
		if "${ML_xc`i'}"=="" {
			local names ${ML_x`i'} _cons
		}
		else	local names ${ML_x`i'}
		global ML_k`i' : word count `names'
		if ${ML_k`i'}==1 & "${ML_xc`i'}"=="" {
			global ML_ip`i' 1
		}
		else	global ML_ip`i' 0
		global ML_fp`i' = $ML_k + 1
		global ML_lp`i' = $ML_k + ${ML_k`i'}

		mat `bi' = J(1,${ML_k`i'},0)
		mat coleq `bi' = ${ML_eq`i'}
		mat colnames `bi' = `names'
		mat $ML_b = nullmat($ML_b), `bi'
		global ML_k = $ML_k + ${ML_k`i'}
		local i = `i' + 1
	}
end

program define Init_b /* {skip|error} {check|doit} b0 */
	args skip doit b0
	capture di matrix(`b0'[1,1])
	if _rc {
		di in red "matrix `b0' not found"
		exit 111
	}
	if matrix(rowsof(`b0')!=1 & colsof(`b0')!=1) {
		di in red "`b0': " matrix(rowsof(`b0')) " x " /*
		*/ matrix(colsof(`b0')) " is not a vector"
		exit 503
	}
	if matrix(rowsof(`b0')) != 1 {
		tempname c
		mat `c' = `b0' '
		local b0 `c'
	}
	local eqs : coleq(`b0')
	local nms : colnames(`b0')
	local i 1
	while `i' <= matrix(colsof(`b0')) {
		local eq : word `i' of `eqs'
		local nm : word `i' of `nms'
		local j = matrix(colnumb($ML_b, "`eq':`nm'"))
		if `j'>=. & "`eq'"=="_" {
			local eq ${ML_eq1}
			local j = matrix(colnumb($ML_b, "`eq':`nm'"))
		}
		if `j' < . & "`doit'"=="doit" {
			mat $ML_b[1,`j'] = `b0'[1,`i']
		}
		else if `j'>=. & "`skip'"=="error" {
			di in red "parameter `eq':`nm' not found"
			exit 111
		}
		local i = `i' + 1
	}
end

// Parse the -diparm()- options, putting the contents into globals of the form
// ML_diparm#.  The global ML_diparms contains the number of -diparm()-
// options.
program ParseDiparmOpts
	version 9, missing
	_get_diparmopts, diparmopts(`0') soptions syntaxonly
	forval k = 1/`s(k)' {
		global ML_diparm`k' `"`s(diparm`k')'"'
	}
	global ML_diparms `s(k)'
end
exit

⌨️ 快捷键说明

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