<p>While the previous answer was very instructive, the correct answer for Stata is that <code>xtreg y x, nocons</code> will result in error <code>r(198) option noconstant not allowed</code>. I don't know why Stata programmers did not allow noconstant option for random effects model, but that's a different question.</p>

CC BY-SA 4.0
2021-06-17T08:22:36.660Z
2021-06-17T08:28:01.947Z
2021-06-17T08:28:01.947Z
Papayapap
<p>Running an (OLS) regression with or without intercept will not change the other coefficients of the other covariates if the means of (all) these covariates are zero.</p>
<p>For simplicity, consider the case of one covariate. We have two regressions, the first with and the second without an intercept.
<span class="math-container">$$
\begin{align*}
&amp;y_i = \alpha + \beta x_{i} + \varepsilon_i, \tag{1}\\
&amp;y_i = \gamma x_i + \delta_i \tag{2}
\end{align*}
$$</span>
For the first regression, you will estimate the coefficients by setting the following sample moment conditions:
<span class="math-container">$$
\begin{align*}
&amp;\frac{1}{n} \sum_i \varepsilon_i = 0,\\
&amp;\frac{1}{n} \sum_i \varepsilon_i x_i = 0
\end{align*}
$$</span>
So:
<span class="math-container">$$
\begin{align*}
&amp;\frac{1}{n} \sum_i y_i = \hat \alpha + \hat \beta \left(\frac{1}{n} \sum_i x_i\right),\\
&amp;\frac{1}{n} \sum_i y_ix_i = \hat \alpha \left(\frac{1}{n} \sum_i x_i\right) + \hat \beta \left(\frac{1}{n} \sum_i (x_i)^2\right)
\end{align*}
$$</span>
Then:
<span class="math-container">$$
\begin{align*}
&amp;\hat \alpha = \left(\frac{1}{n} \sum_i y_i\right) - \hat \beta \left(\frac{1}{n} \sum_i x_i\right),\\
&amp;\frac{1}{n} \sum_i y_i x_i = \left(\frac{1}{n} \sum_i y_i\right) \left( \frac{1}{n} \sum_i x_i\right) - \hat \beta \left(\frac{1}{n} \sum_i x_i\right)^2 + \hat \beta \left(\frac{1}{n} \sum_i (x_i)^2\right),
\end{align*}
$$</span>
So using <span class="math-container">$\widehat{cov}(y_i, x_i) = \left(\frac{1}{n} \sum_i y_i x_i\right) - \left(\frac{1}{n} \sum_i y_i\right) \left( \frac{1}{n} \sum_i x_i\right)$</span> and <span class="math-container">$\widehat{var}(x_i) = \left(\frac{1}{n} \sum_i (x_i)^2\right) - \left(\frac{1}{n} \sum_i x_i\right)^2$</span>:
<span class="math-container">$$
\hat \beta = \frac{\widehat{cov}(y_i, x_i)}{\widehat{var}(x_i)}. \tag{3}
$$</span>
For the regression <span class="math-container">$(2)$</span> without intercept, we only have the second moment condition:
<span class="math-container">$$
\begin{align*}
&amp;\frac{1}{n} \sum_i \delta_i x_i = 0,\\
\to &amp;\frac{1}{n} \sum_i y_i x_i = \hat \gamma \left(\frac{1}{n} \sum_i (x_i)^2\right)
\end{align*}
$$</span>
So:
<span class="math-container">$$
\hat \gamma = \frac{\frac{1}{n} \sum_i y_i x_i}{\frac{1}{n} \sum_i (x_i)^2} \tag{4}
$$</span>
Comparing <span class="math-container">$(3)$</span> and <span class="math-container">$(4)$</span>, we see that they are the same if the mean of <span class="math-container">$x$</span> is zero:  <span class="math-container">$\frac{1}{n} \sum_i x_i = 0$</span>.</p>
<p>The figure below demonstrates.  We have 5 data points with <span class="math-container">$\frac{1}{n} \sum_i x_i =  0$</span>. We see that the two regression lines, the black with intercept and the red without intercept have the same slope.
<a href="https://i.sstatic.net/0jEoY.png" rel="noreferrer"><img src="https://i.sstatic.net/0jEoY.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-06-17T08:03:20.023Z
That is a rather special case.  If the mean of any of the covariates is not zero you would typically see all the coefficients change by removing the intercept.  As your chart shows, if the means of all of the covariates is zero but the mean of the variate is not zero then the no-intercept regression can be so seriously biased as to be largely meaningless
Henry
CC BY-SA 4.0
2021-06-17T08:49:58.373Z
@Henry Indeed, the intercept will be biased (as you fix it to zero). However, the slope will still be unbiased.  The whole derivation is in fact a special case of the Firsh-Waugh-Lovell theorem. First de-mean the covariates by regressing on the constant term and taking the residuals. Then regress $y$ on these de-meaned variables.
tdm
CC BY-SA 4.0
2021-06-17T23:20:43.417Z
Hi @tdm, a novice question, I can explain and rpvoe that (3) equalling to (4) based on this condition. However, can I ask why for the (1) regression ,For the first regression, I can estimate the coefficients by setting the following sample moment conditions:
$$
\begin{align*}
&\frac{1}{n} \sum_i \varepsilon_i = 0,\\
&\frac{1}{n} \sum_i \varepsilon_i x_i = 0
\end{align*}
$$
Phil Nguyen
CC BY-SA 4.0
2021-06-18T05:31:23.247Z
@BeautifulMindset One way to see this is to notice that OLS minimizes $\frac{1}{n} \sum_i (y_i - \alpha - \beta x)^2$ with respect to $\alpha$ and $\beta$. This gives the conditions $\frac{1}{n} \sum_i (y_i - \alpha - \beta x) = 0$ and $\frac{1}{n} \sum_i (y_i - \alpha - \beta x) x = 0$. Subsituting back $\varepsilon = (y - \alpha - \beta x)$ gives you the two moment conditions. Alternatively, you can also see the conditions as the method of moments estimator (see for example [here](https://www.math.canterbury.ac.nz/~m.reale/econ324/Topic1.pdf)).
tdm
CC BY-SA 4.0
2021-06-17T06:36:27.810Z
2021-06-17T06:36:27.810Z
tdm
<p>Is there any explanation if running without intercept caused the change in coefficients of other variables ?</p>
<p>I am talking about a panel data regression.</p>
<p><code>xtreg y x</code></p>
<p>and</p>
<p><code>xtreg y x, nocons</code></p>

<stata>
Will excluding the intercept affect other variables' coefficients?
Phil Nguyen
# Will excluding the intercept affect other variables' coefficients?

(Asked by: username_0 on 2021-06-17)

Is there any explanation if running without intercept caused the change in coefficients of other variables ?

I am talking about a panel data regression.

`xtreg y x`

and

`xtreg y x, nocons`

**Tags:** stata

---

## 2 answers

### Answer by username_2 on 2021-06-17. Score: 6 | Accepted answer

Running an (OLS) regression with or without intercept will not change the other coefficients of the other covariates if the means of (all) these covariates are zero.

For simplicity, consider the case of one covariate. We have two regressions, the first with and the second without an intercept.
$$
\begin{align\*}
&y\_i = \alpha + \beta x\_{i} + \varepsilon\_i, \tag{1}\\
&y\_i = \gamma x\_i + \delta\_i \tag{2}
\end{align\*}
$$
For the first regression, you will estimate the coefficients by setting the following sample moment conditions:
$$
\begin{align\*}
&\frac{1}{n} \sum\_i \varepsilon\_i = 0,\\
&\frac{1}{n} \sum\_i \varepsilon\_i x\_i = 0
\end{align\*}
$$
So:
$$
\begin{align\*}
&\frac{1}{n} \sum\_i y\_i = \hat \alpha + \hat \beta \left(\frac{1}{n} \sum\_i x\_i\right),\\
&\frac{1}{n} \sum\_i y\_ix\_i = \hat \alpha \left(\frac{1}{n} \sum\_i x\_i\right) + \hat \beta \left(\frac{1}{n} \sum\_i (x\_i)^2\right)
\end{align\*}
$$
Then:
$$
\begin{align\*}
&\hat \alpha = \left(\frac{1}{n} \sum\_i y\_i\right) - \hat \beta \left(\frac{1}{n} \sum\_i x\_i\right),\\
&\frac{1}{n} \sum\_i y\_i x\_i = \left(\frac{1}{n} \sum\_i y\_i\right) \left( \frac{1}{n} \sum\_i x\_i\right) - \hat \beta \left(\frac{1}{n} \sum\_i x\_i\right)^2 + \hat \beta \left(\frac{1}{n} \sum\_i (x\_i)^2\right),
\end{align\*}
$$
So using $\widehat{cov}(y\_i, x\_i) = \left(\frac{1}{n} \sum\_i y\_i x\_i\right) - \left(\frac{1}{n} \sum\_i y\_i\right) \left( \frac{1}{n} \sum\_i x\_i\right)$ and $\widehat{var}(x\_i) = \left(\frac{1}{n} \sum\_i (x\_i)^2\right) - \left(\frac{1}{n} \sum\_i x\_i\right)^2$:
$$
\hat \beta = \frac{\widehat{cov}(y\_i, x\_i)}{\widehat{var}(x\_i)}. \tag{3}
$$
For the regression $(2)$ without intercept, we only have the second moment condition:
$$
\begin{align\*}
&\frac{1}{n} \sum\_i \delta\_i x\_i = 0,\\
\to &\frac{1}{n} \sum\_i y\_i x\_i = \hat \gamma \left(\frac{1}{n} \sum\_i (x\_i)^2\right)
\end{align\*}
$$
So:
$$
\hat \gamma = \frac{\frac{1}{n} \sum\_i y\_i x\_i}{\frac{1}{n} \sum\_i (x\_i)^2} \tag{4}
$$
Comparing $(3)$ and $(4)$, we see that they are the same if the mean of $x$ is zero: $\frac{1}{n} \sum\_i x\_i = 0$.

The figure below demonstrates. We have 5 data points with $\frac{1}{n} \sum\_i x\_i = 0$. We see that the two regression lines, the black with intercept and the red without intercept have the same slope.
[![enter image description here](https://i.sstatic.net/0jEoY.png)](https://i.sstatic.net/0jEoY.png)

> **Comments:**
> **username_3**: That is a rather special case.  If the mean of any of the covariates is not zero you would typically see all the coefficients change by removing the intercept.  As your chart shows, if the means of all of the covariates is zero but the mean of the variate is not zero then the no-intercept regression can be so seriously biased as to be largely meaningless  
> **username_2**: @Henry Indeed, the intercept will be biased (as you fix it to zero). However, the slope will still be unbiased.  The whole derivation is in fact a special case of the Firsh-Waugh-Lovell theorem. First de-mean the covariates by regressing on the constant term and taking the residuals. Then regress $y$ on these de-meaned variables.  
> **username_0**: Hi @tdm, a novice question, I can explain and rpvoe that (3) equalling to (4) based on this condition. However, can I ask why for the (1) regression ,For the first regression, I can estimate the coefficients by setting the following sample moment conditions: $$ \begin{align*} &\frac{1}{n} \sum_i \varepsilon_i = 0,\\ &\frac{1}{n} \sum_i \varepsilon_i x_i = 0 \end{align*} $$  
> **username_2**: @BeautifulMindset One way to see this is to notice that OLS minimizes $\frac{1}{n} \sum_i (y_i - \alpha - \beta x)^2$ with respect to $\alpha$ and $\beta$. This gives the conditions $\frac{1}{n} \sum_i (y_i - \alpha - \beta x) = 0$ and $\frac{1}{n} \sum_i (y_i - \alpha - \beta x) x = 0$. Subsituting back $\varepsilon = (y - \alpha - \beta x)$ gives you the two moment conditions. Alternatively, you can also see the conditions as the method of moments estimator (see for example [here](https://www.math.canterbury.ac.nz/~m.reale/econ324/Topic1.pdf)).  

---

### Answer by username_1 on 2021-06-17. Score: 2

While the previous answer was very instructive, the correct answer for Stata is that `xtreg y x, nocons` will result in error `r(198) option noconstant not allowed`. I don't know why Stata programmers did not allow noconstant option for random effects model, but that's a different question.


---

