Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VIF error

    Hello everyone,

    I'm new to Stata so I'm still figuring out the ropes. I have the following problem.

    I am on Stata 14, and I am trying to get the VIF for some X variables. First, I get an error r(199) - "command VIF not defined by VIF.ado". So, I try again and I get another error, this time r(301) - "not appropriate after regress, nocons; use option uncentered to get uncentered VIFs".

    I am doing a fixed effects regression ("areg"). Can someone help?

    Thanks.

    Ashvinder

  • #2
    Ashvinder:
    welocme to the list.
    -estat vif- is not allowed after -areg-.
    However, you can go -estat vce, corr- as an alternative.
    The following toy-example covers that issue comparing -are- with -regress-:
    Code:
    . use http://www.stata-press.com/data/r14/auto2
    (1978 Automobile Data)
    
    . areg mpg weight gear_ratio, absorb(rep78)
    
    Linear regression, absorbing indicators         Number of obs     =         69
                                                    F(   2,     62)   =      41.64
                                                    Prob > F          =     0.0000
                                                    R-squared         =     0.6734
                                                    Adj R-squared     =     0.6418
                                                    Root MSE          =     3.5109
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          weight |  -.0051031   .0009206    -5.54   0.000    -.0069433    -.003263
      gear_ratio |    .901478   1.565552     0.58   0.567    -2.228015    4.030971
           _cons |   34.05889   7.056383     4.83   0.000     19.95338     48.1644
    -------------+----------------------------------------------------------------
           rep78 |          F(4, 62) =      1.117   0.356           (5 categories)
    
    . estat vif
    estat vif not valid
    r(321);
    
    . estat vce, corr
    
    Correlation matrix of coefficients of areg model
    
            e(V) |   weight  gear_r~o     _cons
    -------------+------------------------------
          weight |   1.0000                    
      gear_ratio |   0.7544    1.0000          
           _cons |  -0.8976   -0.9639    1.0000
    
    . reg mpg weight gear_ratio
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     66.38
           Model |  1592.05392         2  796.026958   Prob > F        =    0.0000
        Residual |  851.405544        71  11.9916274   R-squared       =    0.6516
    -------------+----------------------------------   Adj R-squared   =    0.6417
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4629
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          weight |  -.0059643   .0008013    -7.44   0.000    -.0075621   -.0043665
      gear_ratio |   .0994882   1.364894     0.07   0.942    -2.622033     2.82101
           _cons |   39.00643   6.169955     6.32   0.000     26.70389    51.30898
    ------------------------------------------------------------------------------
    
    . estat vce, corr
    
    Correlation matrix of coefficients of regress model
    
            e(V) |   weight  gear_r~o     _cons
    -------------+------------------------------
          weight |   1.0000                    
      gear_ratio |   0.7593    1.0000          
           _cons |  -0.8985   -0.9647    1.0000
    
    . estat vif
    
        Variable |       VIF       1/VIF 
    -------------+----------------------
      gear_ratio |      2.36    0.423527
          weight |      2.36    0.423527
    -------------+----------------------
        Mean VIF |      2.36
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo,

      Many thanks for your wishes and for the illustration. This solves it - however, just to check, when I run -estat vce, corr- or -estat vif- , somehow my y variable is also included whereas in your illustration above, it does not appear:

      1. Is there another line in the code?
      2. Does the inclusion of the y variable affects the correlation between the x variables?
      3. If I change the y variable, will the correlation between the x variables change as well?

      Thank you.

      Ashvinder

      Comment


      • #4
        VIF and tolerance concern the explanatory variables only. So one solution to your problem would be to use Phil Ender's collin program. Type findit collin to find and install it. Then, using a slight modification of Carlo's example:

        Code:
        . clear
        
        . use http://www.stata-press.com/data/r14/auto2
        (1978 Automobile Data)
        
        . areg mpg weight length gear_ratio, absorb(rep78)
        
        Linear regression, absorbing indicators         Number of obs     =         69
                                                        F(   3,     61)   =      30.71
                                                        Prob > F          =     0.0000
                                                        R-squared         =     0.6952
                                                        Adj R-squared     =     0.6602
                                                        Root MSE          =     3.4197
        
        ------------------------------------------------------------------------------
                 mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              weight |  -.0014644   .0019614    -0.75   0.458    -.0053865    .0024576
              length |  -.1234458   .0591825    -2.09   0.041    -.2417885   -.0051032
          gear_ratio |   1.383746   1.542316     0.90   0.373    -1.700307    4.467798
               _cons |   44.82346   8.594935     5.22   0.000     27.63683    62.01009
        -------------+----------------------------------------------------------------
               rep78 |          F(4, 61) =      1.400   0.245           (5 categories)
        
        . collin weight length gear_ratio if e(sample)
        (obs=69)
        
          Collinearity Diagnostics
        
                                SQRT                   R-
          Variable      VIF     VIF    Tolerance    Squared
        ----------------------------------------------------
            weight     12.75    3.57    0.0784      0.9216
            length     10.02    3.17    0.0998      0.9002
        gear_ratio      2.72    1.65    0.3682      0.6318
        ----------------------------------------------------
          Mean VIF      8.50
        
                                   Cond
                Eigenval          Index
        ---------------------------------
            1     3.9172          1.0000
            2     0.0793          7.0290
            3     0.0026         38.8199
            4     0.0010         64.1869
        ---------------------------------
         Condition Number        64.1869
         Eigenvalues & Cond Index computed from scaled raw sscp (w/ intercept)
         Det(correlation matrix)    0.0374
        The if e(sample) you see there ensures that collin uses the same cases (or the same estimation sample) as the preceding areg command.

        HTH.

        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Dear Bruce - thank you so much for the clarification. It's helped me a lot!

          Ashvinder

          Comment


          • #6
            Dear Carlo,

            I am confused about the command "-estat vce, corr-" you mentioned here. I noticed that the correlation matrix are different when this command and "corr" are used. What is the defference between them? Thanks for your help!

            Originally posted by Carlo Lazzaro View Post
            Ashvinder:
            welocme to the list.
            -estat vif- is not allowed after -areg-.
            However, you can go -estat vce, corr- as an alternative.

            [/CODE]
            Best regards,
            Sybil

            Comment


            • #7
              Sybil:
              welcome to the list.
              Whereas -corr- gives you back the correlation between variables, -estat vce, corr- gives you back the correlation between regression coefficients. That's why they are different.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Hi Carlo Lazzaro I am new to stata
                How to store results of vif and corr, vce in excel

                Comment


                • #9
                  Mallikarjuna:
                  provided that I never challenged myself with such a task, you may want to take a look at: https://www.statalist.org/forums/for...-vifs-to-excel
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment

                  Working...
                  X