I have a question about the constant value of a fixed effects model.

I am currently conducting research using a fixed effects model that controls for the effects of companies using Python's linearmodels package.

These are the results from Python and Stata when analyzing the same model.

python panelols

Stata fe model result

It's not exactly the same, but you can see that most of the results are similar. However, in Stata’s result, one constant coefficient value and standard error value are shown, but Python does not show a constant.

In many research papers they show a constant value for fixed effects models, and I want to show that one intercept value and $p$-value can be obtained in my research.

I also looked up a lot of Internet data and looked for results like Stata's constant, but I couldn't find a way in Python (PanelOLS) or R (plm), so I'd like to ask experts in this forum.

import statsmodels.formula.api as smf
import statsmodels.api as sm
from linearmodels.panel import PanelOLS

model = PanelOLS.from_formula(‘Y ~ X1 + X2 + X3 + X4 + X5  + EntityEffects', data = df.set_index(['firm', 'date']))
results = model.fit(cov_type = 'clustered', cluster_entity = True)
  • 1
    $\begingroup$ Welcome. Did you ask for the intercept? You didn't show your code so I can't offer anything specific, but suppose you fit your model in Python and stored the results in, say, results. Try results.params['const']. In Stata, and most other software packages, the intercept is the average value of the fixed effects. In R, try the within_intercept() function in the plm package (see my answer here for more on this). $\endgroup$ Nov 24, 2021 at 18:35
  • $\begingroup$ Thank you so much for the Great answer. Come to think of it, I didn't attach my Python code. I currently uploaded Python code I had tied. And I used PanelOLS in Linearmodel package. $\endgroup$ Nov 25, 2021 at 5:55
  • $\begingroup$ When I used the Python code you taught me, I wasn't sure how to derive the one constant value from whole model. results.params[‘const’] Could you explain more detail? $\endgroup$ Nov 25, 2021 at 6:00
  • $\begingroup$ First, were you able to extract the coefficient(s)? $\endgroup$ Nov 25, 2021 at 6:32
  • $\begingroup$ You mean every, each firms and day coefficients? It comes from results.estimated_effects isn’t it? $\endgroup$ Nov 25, 2021 at 6:45

1 Answer 1


If all you want is the intercept, then try extracting it manually. In Python's linearmodels package, try the params attribute, indexing by the constant term:

results = model.fit(...)

Or, if you want all the estimated panel level effects, then try using the estimated_effects attribute:

results = model.fit(...)

In my opinion, the git documentation is inexhaustive to say the least, but it should help to get you what you want.

In Stata, the intercept is succinctly referred to as the "average value" of the fixed effects. To be clear, you're actually considering the following fixed effects model:

$$ y_{it} = \alpha + x_{it}'\beta + \mu_{i} + \epsilon_{it}, $$

where $\alpha$ is a global intercept (i.e., constant term) and $\mu_{i}$ denotes entity (e.g., individual, firm, state, etc.) fixed effects. Note how you cannot estimate a constant term and the entity-specific effects without imposing some kind of constraint. The constraint StataCorp places on the system is that the panel fixed effects sum to 0 across all observations in the sample.

In short, the "intercept" in -xtreg, fe- is the average of $\alpha + \mu_{i}$. Stata's support page discusses this in further detail.

R's plm package estimates a within model using the following equation:

$$ y_{it} = \alpha_{i} + x_{it}'\beta + \epsilon_{it}, $$

where $\alpha_{i}$ denotes entity fixed effects. This amounts to fitting a separate intercept for each unit in your panel. Note how the overall intercept parameter, $\alpha$ (unsubscripted), is not specified. In this context, $\alpha$ would be perfectly collinear with $\alpha_{i}$, as the sum of all the entity-specific effects (i.e., $\alpha_{i}$'s) is one. In R, we can extract these entity-specific intercepts (i.e., fixed effects) from a plm object using the fixef() function.

I should also note that a within_intercept() function is also available in the plm package. I always found it a bit artificial but it does return an "overall intercept" for within models and its accompanying standard error. Under the hood, it's simply a weighted mean of the fixed effects. Review my response here or this answer here for other R applications.

In sum, I wouldn't go looking for consistency across statistical software packages. In my opinion, the intercept is a trivial parameter in fixed effects applications. It's generally safe to omit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.