I just realized I have always worked regression problem where the independent variables were always numerical. Can I use linear regression in the case where all independent variables are categorical?
Just some semantics and to be clear:
- dependent variable == outcome == "$y$" in regression formulas such as $y = β_0 + β_1x_1 + β_2x_2 + ... + β_kx_k$
- independent variable == predictor == one of "$x_k$" in regression formulas such as $y = β_0 + β_1x_1 + β_2x_2 + ... + β_kx_k$
So in most situations the type of regression is dependend on the type of dependent, outcome or "$y$" variable. For example, linear regression is used when the dependent variable is continuous, logistic regression when the dependent is categorical with 2 categories, and multinomi(n)al regression when the dependent is categorical with more than 2 categories. The predictors can be anything (nominal or ordinal categorical, or continuous, or a mix).
(The remark below might be redundant for you, but I add it anyway)
However, do note that most software requires you to recode categorical predictors to a binary numeric system. This just means coding sex to 0 for females and 1 for males or vice versa. For categorical variables with more than 2 levels you'll need to recode these into $L-1$ dummy variables where $L$ is the number of levels and these dummies contain a 0 or 1 when they are in the corresponding category. This way each individual (sample) should be represented by having a 1 for the dummy variable he/she is part of and a 0 for the others, or a 0 for all dummies when he/she is part of the reference group.