Hausman-Wu Test
Calculate a regression-based Hausman-Wu test for the endogeneity of suspect_ticker in a regression of dependent_ticker on suspect_ticker (and, optionally, other_independent_tickers), using instrument_tickers as instruments for suspect_ticker.
OLS requires every regressor to be uncorrelated with the error term. When that fails, for example because of an omitted common driver, reverse causality or measurement error, the regressor is “endogenous” and OLS is biased; an instrumental-variables approach such as get_iv_2sls is then needed. This test checks whether that is the case before committing to a full IV fit, using two auxiliary OLS regressions:
- Regress
suspect_tickeron the instruments (and the other tickers, if given) and keep the residuals: the part ofsuspect_tickerthat the instruments do not explain. - Regress
dependent_tickeronsuspect_ticker, those residuals (and the other tickers) and test whether the coefficient on the residuals is zero.
If suspect_ticker is exogenous the residuals add no information, so their coefficient should be statistically zero. A low p-value is evidence that suspect_ticker is endogenous and that the OLS estimate is unreliable. The test is only as good as the instruments: they must be correlated with suspect_ticker but not with the error term.
The formula is as follows:
\[\text{Stage 1:}\;\; \text{Xₜ} = \text{pi₀} + \text{pi'Zₜ} + \text{δ'Wₜ} + \text{vₜ},\;\; \text{the OLS regression of suspect\_ticker (X) on a constant},\;\; \text{the instruments (Z) and other\_independent\_tickers (W)},\;\; \text{keeping the residuals v̂ₜ}\] \[\text{Stage 2:}\;\; \text{yₜ} = \text{beta₀} + \text{beta₁} \cdot \text{Xₜ} + \rho \cdot \text{v̂ₜ} + \text{γ'Wₜ} + \text{epsilonₜ},\;\; \text{the OLS regression of dependent\_ticker (y)}\] \[t = \text{rhô} / \operatorname{SE}(\text{rhô}),\;\; \text{with the classical OLS standard error and a Student-t distribution with n - k degrees of freedom; endogeneity is flagged when the p-value is below 0.05}\]- All variables are the tickers’
column(Return by default)
For more information about the method, see the following papers:
- Wu, D-M. (1973). “Alternative Tests of Independence Between Stochastic Regressors and Disturbances.” Econometrica, 41(4), 733-750.
- Hausman, J.A. (1978). “Specification Tests in Econometrics.” Econometrica, 46(6), 1251-1271.
Also known as: Hausman test, Durbin-Wu-Hausman test, regression test for endogeneity.
Hausman-Wu Test in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_hausman_wu_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["SMCI", "NVDA", "TSM"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_hausman_wu_test(
dependent_ticker="SMCI", suspect_ticker="NVDA", instrument_tickers="TSM"
)
Or, after setting up the Finance Toolkit MCP, ask:
Were Nvidia's daily returns endogenous in a regression of Super Micro Computer's returns in 2025, with TSMC as the instrument?
Which returns:
| Value | |
|---|---|
| V-Hat Coefficient | -0.4021 |
| T-Statistic | -2.3377 |
| Degrees of Freedom | 246 |
| P-Value | 0.0202 |
| Endogenous (5%) | 1 |
Using Your Own Data
get_hausman_wu_test 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_hausman_wu_test with dependent_ticker, suspect_ticker and instrument_tickers, using the column names of the data as tickers.
Parameters
get_hausman_wu_test accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | The dependent (predicted) asset. | "AAPL" |
suspect_ticker | str | The (possibly endogenous) asset being tested. | "MSFT" |
instrument_tickers | str | list[str] | One or more instrument asset(s) for suspect_ticker – assets correlated with suspect_ticker but assumed uncorrelated with dependent_ticker’s error term. | "Benchmark" |
other_independent_tickers | str | list[str] | None | Any other (assumed exogenous) independent asset(s) to include. Defaults to None. | "GOOGL" |
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to regress on. Defaults to “Return”. | "Return" |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |