Fit a Fixed Effects (“within”) estimator explaining a panel of dependent_tickers (the entities) by a regressor x, controlling for entity-specific (and/or time-specific) fixed effects.

Also known as: within estimator, FE, least squares dummy variable (LSDV) estimator.

Unlike this module’s other regression methods (get_ols, get_wls, …), which each compare a handful of individual ticker return series on equal footing, this treats dependent_tickers as a genuine panel of entities – e.g. every stock in the Toolkit instance – observed over time. The regressor x is built in exactly one of two ways (provide exactly one of the two arguments below):

  • independent_tickers: a COMMON factor (or factors) applied identically to every entity at each date (e.g. a market benchmark, mirroring a Fama-French-style factor regression).
  • independent_column: a PER-ENTITY regressor – each entity’s own value of a different historical data column (e.g. does "Volume" explain "Return", across the panel).

Fixed Effects removes any purely entity-specific, time-invariant characteristic (e.g. a stock’s typical risk premium) before estimating the regressor’s coefficient(s), by demeaning every variable by its entity’s mean. See panel_data_model.get_fixed_effects for the full formula and references.

The formula is as follows:

\[\text{ỹᵢₜ} = \text{yᵢₜ} - \text{mean}_{t}(\text{yᵢₜ}) \text{and}\; \text{x̃ᵢₜ} = \text{xᵢₜ} - \text{mean}_{t}(\text{xᵢₜ}) (\text{entity\_effects} = \text{True},\; \text{the default}) \text{;} \text{time\_effects} = \text{True also removes each date's mean} (\text{two-way fixed effects})\] \[\text{betâ\_FE} = (\text{X̃'X̃}) \text{⁻¹X̃'ỹ},\;\; \text{without a separate constant (linearmodels PanelOLS, unadjusted covariance)}\] \[\text{Entity Effect:}\;\; \text{alphaᵢ} = \text{mean}_{t}(\text{yᵢₜ} - \text{xᵢₜ'betâ\_FE}) \text{;} \;\text{Time}\; \text{Effect:} \text{lambdaₜ} = \text{mean}_{i}(\text{yᵢₜ} - \text{xᵢₜ'betâ\_FE})\]
  • yᵢₜ is each dependent ticker’s column (Return by default)

Fixed Effects in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_fixed_effects as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["XOM", "CVX", "SHEL", "BP", "TTE"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_fixed_effects(independent_tickers="Benchmark")

Or, after setting up the Finance Toolkit MCP, ask:

How sensitive were the daily returns of ExxonMobil, Chevron, Shell, BP and TotalEnergies to the S&P 500 from 2021 to 2025, controlling for company fixed effects?

Which returns:

  Coefficient Std. Error t-Statistic P-Value
Benchmark 0.5795 0.0183 31.7272 0
Entity Effect: BP 0.0004 nan nan nan
Entity Effect: CVX 0.0004 nan nan nan
Entity Effect: SHEL 0.0005 nan nan nan
Entity Effect: TTE 0.0004 nan nan nan
Entity Effect: XOM 0.0008 nan nan nan

Using Your Own Data

get_fixed_effects runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany, where each country is a column:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

Then call econometrics.get_fixed_effects with independent_tickers or independent_column, using the column names of the data as tickers.

Parameters

get_fixed_effects accepts the following parameters.

ParameterTypeDescriptionExample
independent_tickersstr | list[str] | NoneThe factor ticker(s), whose column values are broadcast identically to every entity at each date. Mutually exclusive with independent_column."Benchmark"
independent_columnstr | NoneA different historical data column, taken per-entity from each of dependent_tickers’ own data, to use as the regressor. Mutually exclusive with independent_tickers."Volume"
dependent_tickersstr | list[str] | NoneThe panel of entity tickers to explain. Defaults to None, meaning every ticker in the Toolkit instance (other than independent_tickers, if given).["AAPL", "MSFT", "GOOGL"]
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe dependent variable’s historical data column. Defaults to “Return”."Return"
include_benchmarkboolWhether to include “Benchmark” among the entities. Defaults to False.True
entity_effectsboolWhether to control for time-invariant entity-specific characteristics. Defaults to True.False
time_effectsboolWhether to control for entity-invariant, time-specific shocks. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
Share