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

📄 boxcox.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 3 页
字号:
	if "$T_nocns" == "" {
		local eqnames `eqnames' Notrans
		local names `names' _cons
		if `first'==1 {
			matrix `newb'=`b1'[1,`size']
			local first  0 
		}
		else 	matrix `newb'=`newb',`b1'[1,`size']
	}

	tokenize $T_parm
	while "`1'" != "" {
		local eqnames `eqnames' Trans
		local names `names' `1'
		if `first'==1 {
			matrix `newb'=`b1'[1,`cnt']
			local first 0
		}
		else 	matrix `newb'=`newb',`b1'[1,`cnt']
		macro shift 
		local cnt =`cnt' +1 
	}

	matrix colnames `newb' = `names'
	matrix coleq `newb' = `eqnames' 

	if "`model'"=="lhsonly" {
		local bparms "theta:_cons"	
	}

	if "`model'"=="rhsonly" | "`model'"=="lambda"  {
		local bparms "lambda:_cons"	
	}

	if "`model'"=="theta" {
		local bparms "lambda:_cons theta:_cons"	
	}

/* 	matrix `b1'=`bpar',sqrt($T_sig) */
 	matrix `b1'=`bpar',sqrt(`lsig')
	matrix colnames `b1'=  `bparms'  sigma:_cons
	matrix `b'=`newb',`b1'

	local nmes : colnames `b'
	local eqnames : coleq `b'

	local size = colsof(`b')

	matrix `V'=J(`size',`size',0)
	matrix `V1'=`Vf'

	if "`model'" != "theta" {
		matrix `V'[`size'-1,`size'-1]=`V1'[1,1]
	}
	else {
		local low = `size'-2
		local high=`size'-1
		matrix `V'[`low',`low']=`V1'[1,1]
		matrix `V'[`low',`high']=`V1'[1,2]
		matrix `V'[`high',`low']=`V1'[2,1]
		matrix `V'[`high',`high']=`V1'[2,2]
	}
	matrix colnames `V'=`nmes'
	matrix coleq `V' = `eqnames'

	matrix rownames `V' = `nmes'
	matrix roweq `V' = `eqnames'

	local df=colsof(`b')
	estimates post `b' `V', dep(`e(depvar)') obs(`e(N)') /*
		*/  esample(`touse') 

	est scalar df_m=`df'
end

program define lincompR
	args ll touse
	/* this program computes the value of the log likelikehood for 
		the RHSONLY	model when lambda=1  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse 
		*/
	
	tokenize $T_parm
	local i 1
	local trans "" 

	while "`1'" != "" {
		tempvar t`i'
		gen double `t`i''=`1'-1
		local trans `trans' `t`i''
		macro shift
		local i=`i' +1
	}

	quietly {
		regress $T_dep $T_notr `trans' if `touse' $T_wtexp, $T_nocns
		tempvar err llfv
		tempname sigmat
	
		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llfv' = -.5*(1+ln(2*_pi)+ ln(`sigmat')) if `touse'
		*summ `llfv' $T_wtexp, meanonly
		*scalar `ll'  =r(sum)
		reg `llfv' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end

program define invcompR
	args ll touse
	/* this program computes the value of the log likelikehood
			for the RHSONLY model when lambda=-1  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tokenize $T_parm
	local i 1
	local trans "" 

	while "`1'" != "" {
		tempvar t`i'
		gen double `t`i''=1-(1/`1')
		local trans `trans' `t`i''
		macro shift
		local i=`i' +1
	}


	quietly	 {
		regress $T_dep $T_notr `trans' if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat
	
		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf'=-.5*(1 + ln(2*_pi)+ ln(`sigmat') ) if `touse'
		*summ `llf' $T_wtexp, meanonly
		*scalar `ll' = r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end

program define logcompR
	args ll touse
	/* this program computes the value of the log likelikehood 
			for the RHSONOLY model when lambda=0  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	
	tokenize $T_parm
	local i 1
	local trans "" 

	while "`1'" != "" {
		tempvar t`i'
		gen double `t`i''=ln(`1')
		local trans `trans' `t`i''
		macro shift
		local i=`i'+1
	}

	quietly	 {
		regress $T_dep $T_notr `trans' if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat
	
		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf'= -.5*(1 + ln(2*_pi)+ ln(`sigmat') ) if `touse'
		*summ `llf' $T_wtexp, meanonly
		*scalar `ll'=r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end




program define lincompL
	args ll touse
	/* this program computes the value of the log likelikehood for 
			the LHSONLY	model when theta=1  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	quietly	{
		regress $T_dep $T_notr  if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat 
	
		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf'=-.5*(1 + ln(2*_pi)+ ln(`sigmat') ) if `touse'
		*summ `llf' $T_wtexp, meanonly
		*scalar `ll'  =r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end

program define invcompL
	args ll touse
	/* this program computes the value of the log likelikehood
			for the LHSONLY model when theta=-1  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tempvar yt

	quietly {
		gen double `yt'=1-(1/$T_dep) if `touse'
		regress `yt' $T_notr  if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat 
	
		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf' = -.5*(1 + ln(2*_pi)+ ln(`sigmat') ) /*
			*/ -2*ln($T_dep) if `touse'
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
		*summ `llf' $T_wtexp , meanonly 
		*scalar `ll' = r(sum)
	}
end

program define logcompL
	args ll touse
	/* this program computes the value of the log likelikehood 
			for the LHSONOLY model when theta=0  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tempvar yt llf err
	tempname sigmat 

	quietly	 {
		gen double `yt'=ln($T_dep) if `touse'
		regress `yt' $T_notr if `touse' $T_wtexp, $T_nocns

		predict double `err', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
  		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double  `llf'  = -.5*(1 + ln(2*_pi)+ ln(`sigmat') ) /*
			*/  -ln($T_dep) if `touse'
		*summ `llf' $T_wtexp, meanonly 
		*scalar `ll'=r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end



program define lincompT
	args ll touse
	/* this program computes the value of the log likelikehood for 
			the THETA model when theta=1 & lambda=1 
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tempvar yt
	
	tokenize $T_parm
	local i 1
	local trans "" 

	quietly { 
		gen double `yt'=$T_dep-1 if `touse'
		while "`1'" != "" {
			tempvar t`i'
			gen double `t`i''=`1'-1 if `touse'
			local trans "`trans' `t`i''"
			macro shift
			local i=`i' +1
		}
		regress $T_dep $T_notr  `trans' if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat 
	
		predict double `err' if `touse', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf'=-.5*(1 + ln(2*_pi)+ ln(`sigmat') ) if `touse'
		*summ `llf' $T_wtexp, meanonly
		*scalar `ll'  =r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end

program define invcompT
	args ll touse
	/* this program computes the value of the log likelikehood
			for the THETA model when theta=-1 and lambda= -1  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tempvar yt 
	

	tokenize $T_parm
	local i 1
	local trans "" 

	quietly {
		gen double `yt'=1-(1/$T_dep) if `touse'
		while "`1'" != "" {
			tempvar t`i'
			gen double `t`i''=1-(1/`1') if `touse'
			local trans " `trans' `t`i'' "
			macro shift
			local i=`i' +1
		}

		regress `yt' $T_notr `trans'  if `touse' $T_wtexp, $T_nocns
		tempvar err llf
		tempname sigmat
	
		predict double `err' if `touse', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
   		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double `llf' = -.5*(1 + ln(2*_pi)+ /*
			*/ ln(`sigmat') )-2*ln($T_dep) if `touse'
		*summ `llf' $T_wtexp , meanonly 
		*scalar `ll' = r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end

program define logcompT
	args ll touse
	/* this program computes the value of the log likelikehood 
			for the THETA model when theta=0 and lambda=0  
		arguments
			1 is name of scalar to hold restricted  LL
			2 is name of touse */

	tempvar yt llf err
	tempname sigmat 


	tokenize $T_parm
	local i 1
	local trans "" 

	quietly {
		gen double `yt'=ln($T_dep) if `touse'
		while "`1'" != "" {
			tempvar t`i'
			gen double `t`i''=ln(`1') if `touse'
			local trans " `trans' `t`i'' "
			macro shift
			local i=`i' +1
		}

		regress `yt' $T_notr `trans' if `touse' $T_wtexp, $T_nocns

		predict double `err' if `touse', residuals
		replace `err'=`err'^2
		*summ `err' if `touse' $T_wtexp, meanonly  
  		*scalar `sigmat'=r(mean)
		reg `err' if `touse' $T_wtexp
		scalar `sigmat' = _b[_cons]

		gen double  `llf'  = -.5*(1 + ln(2*_pi)+ ln(`sigmat') )/*
			*/  -ln($T_dep) if `touse'
		*summ `llf' $T_wtexp, meanonly 
		*scalar `ll'=r(sum)
		reg `llf' if `touse' $T_wtexp
		scalar `ll' = _b[_cons]*e(N)
	}
end


program define lrdispR
	di
	di as txt "{hline 57}"
	di as txt _col(4) "Test" _col(17) "Restricted" _col(32) /* 
		*/ "LR statistic"  _col(50) "P-Value"
	di  as txt _col(5) "H0:"  _col(15) "log likelihood" _col(36) "chi2" /*
		*/ _col(47) "Prob > chi2"
	di as txt "{hline 57}"
	di as txt "lambda = -1" _col(17)  %10.0g as res e(ll_tm1) /* 
		*/ _col(32)  as res %8.2f e(chi2_tm1) /*
		*/  _col(51) %5.3f as res e(p_tm1)

	di as txt "lambda =  0" _col(17) %10.0g as res e(ll_t0) /* 
		*/ _col(32) as res %8.2f e(chi2_t0) /*
		*/ _col(51)  %5.3f as res e(p_t0)

	di as txt "lambda =  1" _col(17)  %10.0g as res e(ll_t1) /* 
		*/ _col(32) as res %8.2f e(chi2_t1) /*
		*/ _col(51)  %5.3f as res e(p_t1)
	di as txt "{hline 57}"
end

program define lrdispL
	di
	di as txt "{hline 57}"
	di as txt _col(4) "Test" _col(17) "Restricted" _col(32) /* 
		*/ "LR statistic"  _col(50) "P-Value"
	di  as txt _col(5) "H0:"  _col(15) "log likelihood" _col(36) "chi2" /*
		*/ _col(47) "Prob > chi2"
	di as txt "{hline 57}"
	di as txt "theta = -1" _col(17)  %10.0g as res e(ll_tm1) /* 
		*/ _col(32)  as res %8.2f e(chi2_tm1) /*
		*/  _col(51) %5.3f as res e(p_tm1)

	di as txt "theta =  0" _col(17) %10.0g as res e(ll_t0) /* 
		*/ _col(32) as res %8.2f e(chi2_t0) /*
		*/ _col(51)  %5.3f  as res e(p_t0)

	di as txt "theta =  1" _col(17)  %10.0g as res e(ll_t1) /* 
		*/ _col(32) as res %8.2f e(chi2_t1) /*
		*/ _col(51)  %5.3f as res e(p_t1)
	di as txt "{hline 57}"
end

program define lrdispT
	di " "
	if "`e(model)'" == "lambda" {
		di as txt "{hline 57}"
		di as txt _col(4) "Test" _col(17) "Restricted" _col(32) /*
			*/ "LR statistic" /*
			*/  _col(50) "P-Value"
		di as txt _col(5) "H0:"  _col(15) "log likelihood" /*
			*/  _col(36) "chi2" _col(47) "Prob > chi2"
		di as txt "{hline 57}"

		di as txt "lambda = -1" _col(17)  %10.0g as res e(ll_tm1) /* 
			*/ _col(32)  as res %8.2f e(chi2_tm1) /*
			*/  _col(51) %5.3f as res e(p_tm1)

		di as txt "lambda =  0" _col(17) %10.0g as res e(ll_t0) /* 
			*/ _col(32) as res %8.2f e(chi2_t0) /*
			*/ _col(51)  %5.3f as res e(p_t0)

		di as txt "lambda =  1" _col(17)  %10.0g as res e(ll_t1) /* 
			*/ _col(32) as res %8.2f e(chi2_t1) /*
			*/ _col(51)  %5.3f as res e(p_t1)
		di as txt "{hline 57}"
	}
	else {
		di as txt "{hline 63}"
		di as txt _col(4) "Test" _col(23) "Restricted" _col(38) 
			*/ "LR statistic"  _col(56) "P-Value"
		di  as txt _col(5) "H0:"  _col(21) "log likelihood" /* 
			*/ _col(42) "chi2" _col(53) "Prob > chi2"
		di as txt "{hline 63}"

		di as txt "theta=lambda = -1" _col(23)  %10.0g as res /* 
			*/ e(ll_tm1) _col(38) as res %8.2f e(chi2_tm1) /*
			*/  _col(57) %5.3f as res e(p_tm1)

		di as txt "theta=lambda =  0" _col(23) %10.0g as res e(ll_t0) /* 
			*/ _col(38) as res %8.2f e(chi2_t0) /*
			*/ _col(57)  %5.3f as res e(p_t0)

		di as txt "theta=lambda =  1" _col(23)  %10.0g as res e(ll_t1)/* 
			*/ _col(38) as res %8.2f e(chi2_t1) /*
			*/ _col(57)  %5.3f as res e(p_t1)

		di as txt "{hline 63}"
	}

end


program define ChkVar
	args var touse
	qui count if `var'<=0 & `touse'
	if r(N) { 
		di as err /*
		*/ "`1' contains observations that are not strictly positive"
		exit 411
	}
end


program define Display
	syntax [, Level(cilevel)]

	bhead
	btitle `level'
	local level "level(`level')"
	if "`e(model)'"=="lambda" |"`e(model)'"=="rhsonly"   {
		_diparm lambda, `level'
	}
	if  "`e(model)'"=="theta" {
		_diparm lambda, `level'
		_diparm theta, `level'
	}
	if  "`e(model)'"=="lhsonly" {
		_diparm theta, `level'
	}

	if "`e(lrtest)'" != "" {
		cdisplr
	}
	else {
		cdisp
	}

	if "`e(model)'"=="rhsonly"   {
		lrdispR
	}
	if  "`e(model)'"=="lhsonly" {
		lrdispL
	}
	if "`e(model)'"=="lambda" |  "`e(model)'"=="theta" {
		lrdispT
	}
end
 
exit

Use of globals
--------------

	$T_bvec		name of matrix containing coefficient vector
	$T_wtexp 	"[fweight=`wvar']"
	$T_nocns	"" or "noconstant"
	$T_dep		name of dependent variable
	$T_parm		list of var names:  transformed variables
	$T_notr		list of var names:  nontransformed variables
	$T_sig		name of scalar containing value of sigma

Updates
-------

06/20/02	fixed iweights to take non-integer values (whg)

⌨️ 快捷键说明

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