*! version 1.2.0 05may1995 (STB-25: sg32.1) program define vif version 4.0 if "$S_E_cmd" != "fit" { error 301 } local varlist "$S_E_vl" local if "$S_E_if" local in "$S_E_in" local wgt "$S_E_wgt" local exp "$S_E_exp" local wtexp = "" if "`wgt'" != "" & "`exp'" != "" { local wtexp = "[`wgt'`exp']" } parse "`varlist'", parse(" ") mac shift local ovars "" local i 1 while "``i''" != "" { local idx = index("`ovars'","``i''") if `idx' == 0 { local ovars "`ovars' ``i''" } local i = `i'+1 } local nvif : word count `ovars' tempname ehold vif mvif scalar `mvif' = 0.0 quietly { noi di noi di in gr "Variable | VIF 1/VIF " noi di in gr "---------+----------------------" local i 1 local nv 0 estimate hold `ehold' tempname nms vvv gen str8 `nms' = "" gen `vvv' = . capture { while `i' <= `nvif' { parse "`ovars'", parse(" ") local ind local vc 1 while `vc' < `i' { local ind "`ind' ``vc''" local vc = `vc'+1 } local vc = `i'+1 while `vc' <= `nvif' { local ind "`ind' ``vc''" local vc = `vc'+1 } local dep "``i''" fit `dep' `ind' `if' `in' `wtexp' replace `vvv' = 1/(1-_result(7)) in `i' replace `nms' = "`dep'" in `i' scalar `mvif' = `mvif'+`vvv'[`i'] local nv = `nv'+1 local i = `i'+1 if _rc { estimate unhold `ehold' error _rc } } preserve gsort -`vvv' `nms' local i 1 while `i' <= `nv' { local skip = 9-length(`nms'[`i']) noi di in gr _col(`skip') `nms'[`i'] /* */ _col(10) "| " in ye %9.2f `vvv'[`i'] /* */ " " in ye %8.6f 1/`vvv'[`i'] local i = `i'+1 } noi di in gr "---------+----------------------" noi di in gr "Mean VIF | " /* */ in ye %9.2f `mvif'/`nv' restore } estimate unhold `ehold' error _rc } end