# Dummy Variable Trap

In my course about machine learning I'm studying multiple linear regression and we talked about dummy variable trap. I have a data set which contains country, height, weight, gender of every person where country is encoded with letters such as us, uk, fr, ge for united states, united kingdom, france and germany respectively and genders are encoded with M F. When I convert these categorical variables into numeric ones (with one hot encoder) I get confused about the following.

When we encode M and F with two different columns if we don't drop one, we fall into dummy variable trap since a "1" on male column would obviously mean a "0" on female column therefore we only have one degree of freedom so the other is redundant, no problem here.

However with country column we can for example say a person is french if all other columns have "0" for them therefore I think that 3 columns are enough for specifying 4 countries and if we have 4 columns we would fall into dummy variable trap but all worked examples state otherwise.

Why is it so? Why 2 variables can be represented with 1 columns if two of them can't be true at the same time but 4 columns cannot be represented by 3 columns if any two columns cannot be true at the same time? Thanks in advance

• "...but all worked examples state otherwise." These are examples in your course? Does every person have one of the four countries listed? Commented Apr 20, 2020 at 2:27
• As far as i know to avoid dummy variable trap, if you have m level you should keep m-1 dummy variables only as you said. Otherwise you will face an issue of multicollinearity due to high correlation between columns. Commented Apr 20, 2020 at 12:12
• @BenReiniger yes, speaking for the examples in my course only. And yes, every person has one of the four countries listed. Commented Apr 20, 2020 at 18:23
• @AyushRanjan exactly, that is what I understood from other sources as well. Alas I don't know how to tell that if I fell to the trap. Are there any exact way to say it just by looking at results or if it is the case I will see only gibberish so it is the only way to know? Commented Apr 20, 2020 at 18:28
• i am not sure but go through this theanalysisfactor.com/eight-ways-to-detect-multicollinearity and see if it helps Commented Apr 20, 2020 at 23:44