Can I run a linear regression with a categorial independent variable (treatment) and adjust for gender at the same time? I'm doing a retrospective study where I want to analyze whether a certain treatment (surgery A vs. surgery B) has an effect on the health status after the surgery measured with different parameters (blood measures for example which are continuous variables but also measures like certain complications which are categorial). Since it is a retrospective study I couldn't control for the gender distributions within the two conditions (A vs. B). When looking at the data I see that there are many more males in one condition than in the other. So now I think the best will be to predict health status depending on the kind of surgery adjusted for gender (and possibly age too). Since treatment and gender are both categorial variables I wondered how I can both include them in a linear model, do I need to dummy code both? And how would this look like in R for example?
Another related question is that there are also data on the blood measures from before the surgery so it would be reasonable to also adjust for those differences within the different conditions, correct? Could I do this in the same model? And another questions which comes to mind in this context is whether it would be reasonable to have some multilevel analysis (within and between) effects?
Help is highly appreciated!
 A: Yes, you can do all of those things.
The first model would be:
$$
\operatorname{blood\_measure}_i=\beta_0+\beta_1\operatorname{treatment_i}+\beta_2\operatorname{gender_i}
$$
In R:
lm(blood_measure ~ treatment + gender, data)

The second model would simply be:
$$
\operatorname{blood\_measure}_i=\beta_0+\beta_1\operatorname{treatment_i}+\beta_2\operatorname{gender_i} + \beta_3\operatorname{pre\_test\_result}
$$
In R:
lm(blood_measure ~ treatment + gender + pre_test_result, data)

Note that in R you don't need to dummify categorical variables. As you see in the formulas above, you can simply pass your variables as factors and R will take care of it.
Finally, if you had reasons to believe that there might be an interaction between, say, treatment and gender (e.g. the response to treatment A is different for males and females), then you could add an interaction in the following way:
lm(blood_measure ~ treatment + gender + treatment:gender, data)

Or equivalently:
lm(blood_measure ~ treatment * gender, data)

