ECO441K Introduction to Econometrics
Interaction Variables, Polynomials, and
Heteroskedasticity
Haiqing Xu
University of Texas
October 25, 2023
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 1 / 22
Lecture 15 — Outline
Interaction Variables and Polynomials
Interaction variables — allowing effect of one variable to vary with
another variable
Polynomials — nonlinear effects of a variable
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 2 / 22
Interaction Variables
Consider a MLR model with two explanatory variables x and z:
y = β0 + β1 x + β2 z + u
Notice that the partial effect of x on y is constant (β 1 ), as is the partial
effect of z on y (β 2 ). The partial effects in this model do not depend on
the values of x and z.
Consider adding an interaction variable to the model, specifically the
interaction of x with z (or mathematically the product of x with z; or in
Stata, ”gen xz=x*z” and ”reg y x z xz”):
y = β 0 + β 1 x + β 2 z + β 3 xz + u
The partial effect of x on y is now
∂E (y |x, z )
= β1 + β3 z
∂x
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 3 / 22
Interaction Variables
The partial effect of x on y now depends on the level of z. If β 3 is positive
(negative), then the effect of x on y is increasing (decreasing) in z.
Now when you describe the partial effect of x on y , you will need to be
clear about what value of z at which you are evaluating it.
We get something similar for the partial effect of z on y :
∂E (y |x, z )
= β2 + β3 x
∂z
Important: If you include an interaction variable xz in a MLR model, you
should always also include x and z in the model as well.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 4 / 22
Interaction Variables — Wage Example
Example: Wages
Recall the wage model with the female indicator
wage = β 0 + β 1 educ + β 2 female + u
In this model, returns to education are the same for females and
non-females.
Add the interaction variable female · educ to the model:
wage = β 0 + β 1 educ + β 2 female + β 3 female · educ + u
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 5 / 22
Interaction Variables — Wage Example
wage = β 0 + β 1 educ + β 2 female + β 3 female · educ + u
What is the expected return to a year of education for females vs
non-females?
What is the expected difference between female and non-female wages?
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 6 / 22
Interaction Variables — Wage Example
Example of graph of returns to education - females vs non-females
Graph of E(wage|educ, female) = b 0 + b 1 female + b 2 educ + + b 3 female · educ
(a) b 1 < 0; b 3 < 0 (b) b 1 < 0; b 3 > 0
wage wage
nonfemale female
nonfemale
female
(a) educ (b) educ
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 7 / 22
Interaction Variables — Chow test
We are sometimes interested in testing whether or not the same model can
be used for different subgroups of the population. For instance, can we use
the same wage-education relationship for females and non-females?
This test is often known as a Chow test, where we
1) interact all explanatory variables in an MLR model with an
indicator (i.e. dummy) variable indicating which subgroup the
observation is in, and then
2) do an F -test on all variables that include the indicator variable.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 8 / 22
Interaction Variables — Chow test
Examples:
For the wage regression with educ
wage = β 0 + β 1 educ + β 2 female + β 3 female · educ + u,
we would want to test the null hypothesis H0 : β 2 = β 3 = 0.
Or, for regression with educ and exper
wage = β 0 + β 1 educ + β 2 female + β 3 female · educ
+ β 4 exper + β 5 female · exper + u,
we would want to test the null hypothesis H0 : β 2 = β 3 = β 5 = 0.
Examples - lec15 [Link]
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 9 / 22
Polynomial Variables
Consider adding a quadratic variable to a linear regression:
y = β0 + β1 x + β2 x 2 + u
Notice that the quadratic x 2 is just x · x and, therefore, is a special case of
an interaction variable (x interacted with itself). So, we should see that
the inclusion of this variable allows the effect of x to depend on x.
∂E (y |x )
= β 1 + 2β 2 x
∂x
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 10 / 22
Polynomial Variables
Quadratic functions are parabolas, and the shape of the parabola depends
on the sign of β 2 . Positive β 2 means a U-shape (convex), negative β 2
menas an inverted U-shape (concave).
A parabola will have a turning point (bottom of the U-shape, top of the
inverted U-shape), which occurs where the partial effect of x is equal to
zero:
β1
β 1 + 2β 2 x ∗ = 0 or x ∗ = −
2β 2
We can estimate the turning point (e.g. maximal profits) by plugging in
our OLS estimates:
βˆ1
x∗ = −
2 βˆ2
Note that the turning point does not need to be in the domain of observed
x, so a quadratic can be used to represent concave or convex functions
that are not U-shaped.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 11 / 22
Polynomial Variables
We’ve omitted other variables, but we could have:
y = β 0 + β 1 x + β 2 x 2 + β 3 z1 + β 4 z2 + · · · + u
The interpretation of partial effects is the same, except that it is
holding the z variables fixed.
We can also add higher order polynomials to the regression
y = β 0 + β 1 x + β 2 x 2 + β 3 x 3 + β 4 z1 + β 5 z2 + · · · + u
What is the partial effect of x on y now?
By adding higher and higher order polynomials to the regression, we
can represent a very general function y = f (x ). This is the simplest
example of ”non-parametric” econometrics/statistics and is also a
simple machine learning algorithm. How flexible you can be depends
on how much data you have.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 12 / 22
Lecture 16 — Outline
Heteroskedasticity
Definition
Why is heteroskedasticity a problem?
Testing for heteroskedasticity
Dealing with heteroskedasticity
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 13 / 22
Heteroskedasticity
Recall the homoskedasticity (constant-variance) assumption MLR.5:
MLR.5: Var (u |x1 , . . . , xk ) = σ2 for all x1 , . . . , xk
More generally this assumption might not hold, i.e. the variance of u
might depend on the RHS variables:
Var (ui |xi1 , . . . , xik ) = σi2 = f (xi1 , . . . , xik ),
where σi2 is no longer constant but rather a function of the RHS
variables.
When we have heteroskedasticity, the residual variance estimator
σ̂2 = n−SSR
k −1 is still a good estimator of the unconditional variance of
u but not the conditional variance(s) Var (u |x1 , . . . , xk ).
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 14 / 22
Heteroskedasticity
We had assumed MLR.5 to greatly simplify the expressions for the
variances of the β̂ j estimates. Also, under homoskedasticity, we
utilized the t-statistic and F -statistic theory for testing and
constructing confidence intervals.
Unfortunately, our usual inference procedures are no longer valid
under heteroskedasticity (and having a large sample does not resolve
the problem).
But remember that OLS estimators are still unbiased and consistent
under heteroskedasticity - it’s the orevious variance formulas and
inferences that are no longer valid.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 15 / 22
Problems caused by heteroskedasticity
Problems caused by heteroskedasticity:
1 standard errors are wrong =⇒ CI’s wrong
2 tests are wrong (t tests, F tests)
3 predictive forecast intervals are wrong
recall Var (ê 0 ) = Var (ŷ 0 ) + Var (u 0 )
4 OLS is no longer the best (lowest variance) estimator (but it is still
unbiased and consistent!)
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 16 / 22
Solutions to problems
1. Standard errors: Use “heteroskedasticity-robust” standard errors. These
standard errors are based upon the correct (more complicated) formulas
for the β j variances that take into account heteroskedasticity. In Stata:
. regr y x1 x2 x3, robust
The heteroskedasticity-robust standard errors are consistent (if n is large,
they accurately estimate the true stdevs of the β̂ j ’s). Confidence intervals
for the β̂ j ’s (or linear combinations of them) can then be based upon these
corrected standard errors.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 17 / 22
Solutions to problems
2. Testing
t-tests: The usual t test will be valid for large n as long as you use the
robust standard error. For testing H0 : β j = a, we have
β̂ j − a
t∗ = ,
se ( β̂ j )
where the denominator is the robust se.
F -tests: The heteroskedasticity-robust F statistics do not have a simple
form (i.e., they can’t be computed easily using R 2 or SSR formulas).
Nonetheless, these F statistics are very easy to compute using Stata — as
long as the robust option was used for a regression, all test commands
afterwards will compute correct, heteroskedasticity-robust, F statistics.
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 18 / 22
Solutions to problems
3. Predictive intervals
Variance with homoskedasticity: Var (ŷ 0 ) + Var (u 0 ) = Var (ŷ 0 ) + σ2
Variance with heteroskedasticity: Var (ŷ 0 ) + Var (u 0 |x10 , . . . , xk0 )
We can compute Var (ŷ 0 ) using lincom (after running regression using
using robust option). For the conditional variance Var (u 0 |x10 , . . . , xk0 ), we
need some sort of model.
A simple model (see Wooldridge, eq (8.12)) is to have
Var (u |x1 , . . . , xk ) = E (u 2 |x1 , . . . , xk ) = δ0 + δ1 x1 + · · · + δk xk
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 19 / 22
Solutions to problems
3. Predictive intervals, cont’d
To estimate δ0 , . . . , δk :
Get ûi values (from OLS of y on x1 , . . . , xk )
Regress ûi2 on x1 , . . . , xk −→ δ̂0 , . . . , δ̂k
Finally, to estimate Var (u 0 |x10 , . . . , xk0 ), we just utilize the model and plug
in our estimates, so that
d (u 0 |x10 , . . . , xk0 ) = δ̂0 + δ̂1 x10 + · · · + δ̂k xk0 .
Var
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 20 / 22
Solutions to problems
4. OLS not efficient (betters estimators of β j ’s exist)
We would like to downweight observations that are really noisy (high
Var (u |x1 , . . . , xk )). The solution is weighted least squares (Wooldridge
Section 8.4; you are not responsible for this on exam).
Model Var (u |x1 , . . . , xk ).
Estimate parameters of this variance model (for example, δ̂0 , . . . , δ̂k
from the simple model above).
For each observation i, get an estimated variance by plugging in the x
values.
yi
Regress √ on each of the x variables also divided by
d (ui |xi1 ,...,xik )
Var
q
d (ui |xi1 , . . . , xik )
Var
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 21 / 22
Testing for heteroskedasticity
Testing for heteroskedasticity:
1 Look at residual plots!
ûi versus individual x variables
ûi versus ŷi fitted values
2 Regression-based test (Breusch-Pagan)
Regress ûi2 on xi 1 , . . . , xik . The underlying variance model is
Var (ui |xi 1 , . . . , xik ) = δ0 + δ1 xi 1 + · · · + δk xik .
Test the null hypothesis (of homoskedasticity):
H0 : δ1 = · · · = δk = 0
(Note that this is just a full F -test on the new regression.)
Haiqing Xu (University of Texas) Chapter 6/7: Issues October 25, 2023 22 / 22