Up to what number of distinct values should I transform a categorical variable in a dummy variable? When working with categorical variables, it's common to do some sort of transformation. Usually people apply a one-hot encoding. Putting it simply, we transform a categorical into a dummy variable. However, there may be some problems when doing this. E.g. let's say you are working with a variable "city". Sometimes it won't be a smart move to transform this variable into several dummies because there will be dozens of dummy variables after the transformation. However, if you are working with a variable like "marital status", it seems ok to do the one-hot encoding.
I know we have other sort of transformations for categorical variables, like the ones mentioned by Andre Ye in the post https://towardsdatascience.com/stop-one-hot-encoding-your-categorical-variables-bbb0fba89809.
All that said, is there a number of distinct values a categorical variable should have if I want to transform it in a dummy? If the variable has 5 distinct values, I believe it's fine to do the transformation. If there's 6 distinct values, it seems OK too. But what about 7? 8? 9? Up to what number of distinct values we might transform a categorical in a dummy?
 A: A categorical variable with $k$ distinct categories is often mapped to $k - 1$ indicator or dummy variables with values 1 and 0 (or sometimes missing, NA or whatever). This is an extension of a single binary or dichotomous variable being a property you can code as 1 and 0, for present or absent, employed or unemployed, survived or not, and so forth.
I don't think there are any rigid rules on a upper value of $k$. If it suits your analysis and you have a big enough dataset, fire away.
If you have a categorical variable you want to use, and it has 20 or 200 categories, it is not usually true that there is an alternative measured variable on an integer or real scale.
For example, economists and other social scientists with panel or longitudinal data often fit a term for each year of a series to catch time effects. Or they may use an indicator for each month to capture seasonality: with socio-economic data in many countries, December is often quite different from November or January, and August may be quite different from July or September, given holidays, special days and so forth. Substitute  your own examples for places with different holidays or special seasons depending on religion or culture.
Years of (completed formal) education is another variable that in one sense is a count, but completing high school, or completing a first degree, often has implications for say employment prospects or many other variables that mean the effects of length of education are better handled through  a set of indicator variables.
The downside of having many indicator variables as predictors in a model includes

*

*Estimating lots of parameters chews up degrees of freedom and you may or may not care about that.


*Fitting lots of indicators may be a way just to correct for a predictor you regard as secondary to your main interest, or it is a source of complication you may regret.


*Rare categories can be difficult to fit because the individuals may be a quirky sample.
Notes on terminology:

*

*The term unique is often used, as in your original post, but the traditional meaning of unique as meaning occurring once only implies to me that distinct is a much better term.


*In some fields, the term dummy variable is used (much) more frequently than indicator variable. If it is the prevailing technical jargon in your field, so be it. I have heard, however, horror stories in which expressions like "gender dummy" or "race dummy" have been very much misunderstood by non- or less statistical people as being disparaging or even offensive, so watch out. I have never heard that indicator variable has been misunderstood.
Note: I haven't tried to discuss the ideas on the page  you mention.
