Question on constrained OLS regression in Python

Dear all,

This is my question: is there a method/what’s the best method to implement an OLS regression with constrained parameters?

Let’s say for example that I would like to estimate: Y_t=c+β_1 X_t+β_2 Z_t+β_3 R_t
Such that β_1=1-β_2.

How can I program it in Python?

You might have some luck using statsmodels’ fit_constrained method described here: https://www.statsmodels.org/dev/generated/statsmodels.genmod.generalized_linear_model.GLM.fit_constrained.html#statsmodels.genmod.generalized_linear_model.GLM.fit_constrained

1 Like

A pretty simple way to do it (since it is simply an equality constraint) is by rewriting the regression and estimate that through sm.OLS.

Y_t=c+β_1 X_t+β_2 Z_t+β_3 R_t \\ = c+(1 - β_2) X_t+β_2 Z_t+β_3 R_t \\ = c + β_2(Z_t - X_t) + X_t + β_3 R_t \\ Y_t - X_t = c + β_2(Z_t - X_t) + β_3 R_t

So create the variables Y_t - X_t and Z_t - X_t then regress Y_t - X_t on Z_t - X_t and R_t

If you want to test whether the restriction holds, a simple F test between the standard model you wrote in the question and the model above should work. If the F test is shows significant difference, the restriction doesn’t hold in the data

1 Like