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..