Setting Multiple linear restrictions equal to some coefficient in R? I have a model of the form: $y_i = \beta_0 + \beta_1 x_1 +\beta_2 x_2 +\epsilon_i$ . I want to test the null hypothesis that $\beta_1 + \beta_2 =2$, by creating a restricted model imposing these restrictions. My idea was to create a new variable, call it $restrictions$ and make it the equation $\beta_1 + \beta_2 =2$ and then input this equation into a restricted regression, call it R,
R <- lm(y_i ~ restrictions, data = mydata)

This was just what occurred to me, I have never dealt with multiple linear restrictions equal to something non-trivial such as zero, which would make this a much more straightforward affair as I would be able to just exclude them, e.g. $\beta_1=0$
I also want to be able to fit my restrictions into the general form of $R \beta = r$ where R is a qx(k+1) with rank(R)=q<k+1 and r is qx1, and q is the number of restrictions.
 A: There are two ways of doing this. One is to incorporate each kind of restriction using algebra, and the other is to derive a general formula into which specific cases can be fitted.
Let's start with the first. Your constrained model is
$$y_i = \beta_0 + \beta_1 x_1 +\beta_2 x_2 +\epsilon_i \mbox{ where } \beta_1 + \beta_2 =2.$$
This can be rewritten as
$$y_i = \beta_0 + \beta_1 x_1 +(2-\beta_1) x_2 +\epsilon_i,$$
which is equivalent to
$$y_i - 2 x_2  = \beta_0 + \beta_1 (x_1 - x_2) +\epsilon_i.$$
This is the model you can fit after defining 2 new variables. To recover $\hat \beta_2$, you just need to calculate the linear function of $2 - \hat \beta_1$.
Now for the general solution for a linear equality constraint of the form $R\beta=r$, where $R$ is a $q \times k$ matrix of known constants, with $q<k$; r is a $q-$vector of known constants; $k$ is the number of variables in the model (including intercept) and $q$ is the number of restrictions. R and r constants come from the restrictions you want to impose. For example, in your simple model
$$R = \begin{bmatrix} 0 & 1 & 1 \end{bmatrix},\mbox{ } r=2,  \mbox{ and } q=1.$$
To impose the restriction, we define a constrained sum of squares
$$RSS=(y-Xb^*)'(y-Xb^*) - 2 \lambda'(Rb^*-r),$$
where $\lambda$ is a $q-$vector of Lagrange multipliers. From setting the FOCs with respect to $b^*$ and $\lambda$ to zero, you can derive that
$$b^*= b + (X'X)^{-1}R'[R(X'X)^{-1}R']^{-1}(r-Rb)$$
where $b$ is the usual OLS estimator $(X'X)^{-1}X'y$ and $b^*$ is the constrained coefficient vector.
In R, this can be done with glmc which will allow you to specify the constraint(s) and handles the rest.
