1

Is there a way in python where I can add a constrain to my OLS with dummy regression variables? I had a look at this link with a possible solution in R.

I am using pandas get_dummies() on my dataframe , without setting the drop_first to TRUE.

Ideally I would like to then use either statsmodel or scipy to run a regression with the constraint which says the sum of weighted coefficients of each of my set of categorical variable = 0

======== Below is the model and the constraint I am trying to implement ======

y_{i}(t) = \alpha(t)+\sum_{r=1}^{14}\beta_{r}(t)*Rating^{r}_{i}(t)+\sum_{s=1}^{20}\gamma_{s}(t)*Sector^{s}_{i}(t)+\sum_{c=1}^{5}\sigma_{c}(t)*Country^{c}_{i}(t) ............ (1) where

\sum_{r=1}^{14}\beta_{r}(t)*weight(t) + \sum_{s=1}^{20}\gamma_{s}(t)*weight(t)+ \sum_{c=1}^{5}\sigma_{c}(t)*weight(t) = 0 ........... (2)

The above is the constraint I want to force on my model in equation (1)

Apologies, but I am not sure how to put latex equations here..

Community
  • 1
  • 1
sumit_uk1
  • 43
  • 1
  • 7
  • What are the weight functions? – Bill Bell Mar 09 '17 at 18:41
  • It's not available for statsmodels OLS but it is for GLM which defaults to Gaussian. see http://stackoverflow.com/questions/29261018/how-to-add-sum-to-zero-constraint-to-glm-in-python and the answer here http://stackoverflow.com/questions/29261018/how-to-add-sum-to-zero-constraint-to-glm-in-python – Josef Mar 10 '17 at 18:11

0 Answers0