xtht_p.ado

来自「是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到」· ADO 代码 · 共 150 行

ADO
150
字号
*! version 1.0.1  06nov2002
program define xtht_p
	version 8 

		/* Step 1:
			place command-unique options in local myopts
			Note that standard options are
			LR:
				Index XB Cooksd Hat 
				REsiduals RSTAndard RSTUdent
				STDF STDP STDR noOFFset
			SE:
				Index XB STDP noOFFset
		*/

	local myopts "UE E U XBU"
	/* note that UE is full sample, rest are estimation subsample only */
	/* default is XB */



		/* Step 2:
			call _propts, exit if done, 
			else collect what was returned.
		*/
	_pred_se "`myopts'" `0'
	if `s(done)' {
		exit
	}
	local vtyp  `s(typ)'
	local varn `s(varn)'
	local 0 `"`s(rest)'"'


		/* Step 3:
			Parse your syntax.
		*/
	syntax [if] [in] [, `myopts']


		/* Step 4:
			Concatenate switch options together
		*/
	local type  "`e'`u'`ue'`xbu'"


		/* Step 5:
			quickly process default case if you can 
			Do not forget -nooffset- option.
		*/
	if "`type'"=="" {
		di in gr "(option xb assumed; fitted values)"
		_predict `vtyp' `varn' `if' `in', xb `offset'
		label var `varn' "Xb"
		exit
	}


		/* Step 6:
			mark sample (this is not e(sample)).
		*/
	marksample touse


		/* Step 7:
			handle options that take argument one at a time.
			Comment if restricted to e(sample).
			Be careful in coding that number of missing values
			created is shown.
			Do all intermediate calculations in double.
		*/


		/* Step 8:
			handle switch options that can be used in-sample or 
			out-of-sample one at a time.
			Be careful in coding that number of missing values
			created is shown.
			Do all intermediate calculations in double.
		*/

	if "`type'" =="ue" {
		tempvar xb
		quietly _predict double `xb' if `touse', xb `offset'
		gen `vtyp' `varn' = `e(depvar)' - `xb' if `touse'
		label var `varn' "u[`e(ivar)'] + e[`e(ivar)',t]"
		exit
	}
			

		/* Step 9:
			handle switch options that can be used in-sample only.
			Same comments as for step 8.
		*/
	qui replace `touse'=0 if !e(sample)

	if "`type'"=="e" {
		tempvar xb u
		quietly {
			_predict double `xb' if `touse', xb `offset'
			predict double `u' if `touse', u `offset'
		}
		gen `vtyp' `varn' = `e(depvar)' - `xb' - `u' if `touse'
		label var `varn' "e[`e(ivar)',t]"
		exit
	}

	/* for the remaining, we also need to know the full estimation 
	   subsample
	*/
	tempvar smpl
	qui gen byte `smpl' = e(sample)

	if "`type'"=="u" | "`type'"=="xbu" {
		tempvar xb u 
		quietly {
			_predict double `xb' if `smpl', xb `offset'
			sort `e(ivar)' `smpl'
			if e(Tcon)==0 {
				tempvar ratio
				qui by `e(ivar)' `smpl': /*
				*/ gen double `ratio' = /*
				*/ scalar(e(sigma_u)^2/(_N*e(sigma_u)^2 /*
				*/ + e(sigma_e)^2)) if `smpl'
			}
			else {
				tempname ratio
				scalar `ratio' = /*
				*/ scalar(e(sigma_u)^2/(e(Tbar)*e(sigma_u)^2 /*
				*/ + e(sigma_e)^2))
			}
			by `e(ivar)': gen double `u' = /*
			*/ `ratio'*sum(`e(depvar)'-`xb') if `smpl'
			by `e(ivar)': replace `u' = `u'[_N] if `touse' 
								/* sic */
		}
		if "`type'"=="u" {
			gen `vtyp' `varn' = `u' if `touse'
			label var `varn' "u[`e(ivar)']"
		}
		else {
			gen `vtyp' `varn' = `xb' + `u' if `touse'
			label var `varn' "Xb + u[`e(ivar)']"
		}
		exit
	}
	error 198
			
end

⌨️ 快捷键说明

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