I am working my way for the first time through predicting a continuous dependent variable in a problem where all independent variables are categorical using python statsmodels. I would like to add to this model 'y ~ + C(x1) + C(x2) + C(x3)' all possible quadratic terms. What is the right notation for that?

EDIT: one of my categorical variables is age, which I binned in four different bins. All other are transformed into dummy. So the idea was to square age.

  • $\begingroup$ Please clarify. Suppose one of your categorical models is region {East, West, North, or South}. Would you try to square "East"? $\endgroup$ – rolando2 Mar 19 '17 at 22:17
  • $\begingroup$ I imagined that if one of the categories is age, and I build a few age bins, I could still square age and have a meaning associated to it $\endgroup$ – famargar Mar 20 '17 at 6:51

Quadratic terms for categorical variables are undefined because you cannot square a categorical variable. On the other hand, given that you have a continuous variable with nonlinear relationship to your outcome/dependent variable, categorization may help and be such that it is synonymous to introducing quadratic terms but with the added benefit of simpler model to build and explain.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.