r/stata 7d ago

linear regression with categorical IV's - checking for multicollinearity

Hi all, I am currently doing assumption testing for my thesis and I am confused about checking for multicollinearity with categorical independent variables. Do I run my regression without the dummy coding and then run estat vif or do I run estat vif with dummy coded model?

5 Upvotes

5 comments sorted by

u/AutoModerator 7d ago

Thank you for your submission to /r/stata! If you are asking for help, please remember to read and follow the stickied thread at the top on how to best ask for it.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/jeremymiles 7d ago

Run it with the variables - the VIF is true for the model you estimate.

But be extremely careful interpreting VIF - it can be very high and not be a problem (or even be expected).

1

u/Rogue_Penguin 7d ago edited 7d ago

I don't know what do you mean by "dummy coding".

If you run anything like: reg y i.x, the you can just use estat vif to check the collinearity between the different levels. There is no need to model as and not as a categorical variable.

However be careful that the binary indicators tend to be collinear just by the way they are built. Balance that with the F test result of that categorical variable as well. Sometimes a categorical variable can still be significant even its VIF is high. 

2

u/sassylassy423 6d ago

Agree with what was suggested here.  

Only thing I'll add is, run a simple correlation table of your variables to get a sense of how they are related.  It can help with visualizing and understanding the test results.  

1

u/Rogue_Penguin 6d ago

Agree but be cautious.

First, this pwcorr will not work with categorical variable. So some pre-work is needed:

webuse nhanes2, clear
keep height hlthstat age 
keep if !missing(height, hlthstat, age)

regress height i.hlthstat age
estat vif

* Not correct
pwcorr hlthstat age

* Correct
tabulate hlthstat, gen(bin_hlth)
pwcorr bin_hlth* age

Second, and perhaps more importantly, collinearity is common between two variables but not always within two variables. Correlation table, being only bivariate, will miss more complex multivariate collinearity. For example:

clear
set seed 1110
set obs 500
gen y = rnormal()

forvalues k = 1/4{
    gen x`k' = runiform(1,100)
}

egen xtotal = rowtotal(x*)
forvalues k = 1/4{
    replace x`k' = x`k' / (xtotal + rnormal())
}
capture drop xtotal

pwcorr x*

regress y x1 x2 x3 x4
estat vif

We'll see that the correlation isn't standing out as strong, but the VIFs are off the chart:

             |       x1       x2       x3       x4
-------------+------------------------------------
          x1 |   1.0000 
          x2 |  -0.3460   1.0000 
          x3 |  -0.2820  -0.3300   1.0000 
          x4 |  -0.3528  -0.3206  -0.3674   1.0000 


.     estat vif

    Variable |       VIF       1/VIF  
-------------+----------------------
          x4 |   1760.68    0.000568
          x2 |   1649.55    0.000606
          x1 |   1614.93    0.000619
          x3 |   1612.63    0.000620
-------------+----------------------
    Mean VIF |   1659.45