# Exogeneity: Wu-Hausman and Sargan Tests in Python Videos

Last Update: March 24, 2022

My online video tutorials are hosted at YouTube channel.

For learning this concept, you can view my online video tutorials: Exogeneity: Wu-Hausman and Sargan Tests in Python (Spyder) and Exogeneity: Wu-Hausman and Sargan Tests in Python (Jupyter).

Videos Code

1. Packages

``````import statsmodels.api as sm
import statsmodels.formula.api as smf
import linearmodels.iv.model as lm
``````

2. Data

``````houseprices_object = sm.datasets.get_rdataset(dataname="HousePrices",
package="AER", cache=True)
houseprices = houseprices_object.data
print(houseprices_object.__doc__)
``````

3. Model

``````mlr1 = smf.ols(formula="price ~ lotsize + bedrooms",
data=houseprices).fit()
``````

4. Exogeneity

Two Stage Least Squares

``````mdatac = sm.add_constant(data=houseprices, prepend=False)
mlr2 = lm.IV2SLS(dependent=mdatac["price"],
exog=mdatac[["const", "bedrooms"]],
endog=mdatac["lotsize"],
instruments=mdatac[["driveway", "garage"]]).fit(
cov_type="homoskedastic", debiased=True)
``````

Wu-Hausman Tests

``````print(mlr2.wu_hausman())
print(mlr2.wooldridge_regression)
``````

Sargan Over-identifying Restrictions Test

``print(mlr2.sargan)``

Courses

My online courses are hosted at Teachable website.

For more details on this concept, you can view my Linear Regression in Python Course.

+