Fit a Random Effects estimator explaining a panel of dependent_tickers (the entities) by a regressor x, via Swamy-Arora feasible Generalized Least Squares.

Also known as: RE, GLS panel estimator, Swamy-Arora estimator.

See get_fixed_effects for how dependent_tickers/independent_tickers/ independent_column are shaped into a panel, and panel_data_model.get_random_effects for the full estimator formula, references, and how it compares to Fixed Effects. Unlike Fixed Effects, Random Effects retains and estimates a single, population-average intercept rather than one intercept per entity – more efficient than Fixed Effects if entity effects are indeed uncorrelated with the regressor(s) (see get_hausman_test to check that assumption).

The formula is as follows:

\[\text{thetaᵢ} = 1 - \sqrt{\sigma ^{\text{2\_epsilon}} / (\sigma ^{\text{2\_epsilon}} + \text{Tᵢ} \cdot \sigma ^{2_{u}})},\;\; \text{with the Swamy-Arora estimates of the idiosyncratic} (\sigma ^{\text{2\_epsilon}}) \text{and entity} (\sigma ^{2_{u}}) \text{variance components}\] \[y \cdot \text{ᵢₜ} = \text{yᵢₜ} - \text{thetaᵢ} \cdot \text{mean}_{t}(\text{yᵢₜ}) \text{and}\; x \cdot \text{ᵢₜ} = \text{xᵢₜ} - \text{thetaᵢ} \cdot \text{mean}_{t}(\text{xᵢₜ}),\;\; \text{the constant becoming 1 - thetaᵢ}\] \[\text{betâ\_RE} = \text{OLS of}\; y \cdot \text{on}\; x \cdot (\text{linearmodels RandomEffects}),\;\; \text{with yᵢₜ each dependent ticker's column (Return by default)}\]

Random Effects in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_random_effects as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["JPM", "BAC", "C", "WFC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

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

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

How sensitive were the daily returns of JPMorgan Chase, Bank of America, Citigroup and Wells Fargo to the S&P 500 from 2021 to 2025, in a random effects panel?

Which returns:

  Coefficient Std. Error t-Statistic P-Value
Intercept 0.0003 0.0002 1.7192 0.0856
Benchmark 0.9788 0.0183 53.4931 0

Using Your Own Data

get_random_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_random_effects with independent_tickers or independent_column, using the column names of the data as tickers.

Parameters

get_random_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. Since this Toolkit instance’s historical data is aligned onto a common calendar across tickers, a broadcast factor’s entity mean is identical for every entity, leaving no between-entity variation to identify Random Effects’ between-regression step – prefer independent_column here unless dependent_tickers genuinely differ in their date coverage (e.g. different listing histories)."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
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
Share