Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Estout and VIF - Correction


From   "Jann, Ben" <ben.jann@soz.gess.ethz.ch>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Estout and VIF - Correction
Date   Tue, 12 Apr 2005 09:24:20 +0200

As Hervé pointed out, the example code in my last message had 
the problem, that the constant was not treated correctly. 
Below is a more elaborated version of the code. Note that 
with this program it is also possible to store the tolerance, 
i.e. 1/VIF, and sqrt(VIF).

program define _estadd_vif, eclass
 syntax [ , prefix(name) TOLerance SQRvif * ]
//copy coefficients matrix and set to .z
 tempname results results2 results3
 matrix `results' = e(b)
 forv j = 1/`=colsof(`results')' {
  mat `results'[1,`j'] = .z
 }
 if "`tolerance'"!="" mat `results2' = `results'
 if "`sqrvif'"!="" mat `results3' = `results'
//compute VIF and add to results vector
 capture vif
 if !_rc {
  local i 0
  local name "`r(name_`++i')'"
  while "`name'"!="" {
   local j = colnumb(`results',"`name'")
   if `j'<. {
    matrix `results'[1,`j'] = r(vif_`i')
    if "`tolerance'"!="" matrix `results2'[1,`j'] = 1 / r(vif_`i')
    if "`sqrvif'"!="" matrix `results3'[1,`j'] = sqrt( r(vif_`i') )
   }
   local name "`r(name_`++i')'"
  }
 }
//return the results
 if "`sqrvif'"!="" ereturn matrix `prefix'sqrvif = `results3'
 if "`tolerance'"!="" ereturn matrix `prefix'tolerance = `results2'
 ereturn matrix `prefix'vif = `results'
end

Save the code as "_estadd_vif.ado" somewhere in the adopath.
To add VIF to the e-returns, type

 . estadd , stats(vif)

To additionally save the tolerance and sqrt(VIF), type

 . estadd , stats(vif(tolerance sqrvif))

To tabulate the results using -estout-, type

 . estout , cells(vif tolerance sqrvif)

ben

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu 
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of 
> Herve STOLOWY
> Sent: Monday, April 11, 2005 11:22 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: RE: Estout and VIF
> 
> 
> Dear Ben:
> 
> Once again, I sincerely appreciate your help. I followed your 
> suggestions and it works perfectly. (I saved your program as 
> an ado file).
> 
> I can simply mention one little detail (but so minor): on the 
> constant line, in the vif column, a figure is disclosed. It 
> is not a VIF but the repetition of the amount of the b coefficient.
> 
> Best regards
> 
> Hervé
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index