Instrumental Variables & Panel Models
1/47
Table of Contents
Instrumental Variables
Context & Definitions Canonical Examples Estimation
Practical Considerations R Example
Panel Models
Motivation
Pooled Model
Fixed Effects Model Random Effects Model R Example
2/47
Table of Contents
Instrumental Variables
Context & Definitions Canonical Examples Estimation
Practical Considerations R Example
Panel Models
Motivation
Pooled Model
Fixed Effects Model Random Effects Model R Example
3/47
Motivation
In economics, we’re often interested in identifying not just correlative relationships, but causal relationships
Causality is most easily identifiable in the context of randomized, controlled experiments (i.e., in a lab setting)
Unfortunately, it may be not be ethical or feasible to run large scale economic experiments
4/47
Motivation (cont.)
To try and identify the casual relationships between variables, we often turn to using regressions:
Y = βX + ε
In other words, we want to identify the following:
X?Y
In a perfect world, if the true data generating process were X → Y , then β would be the correctly estimated causal effect.
5/47
Motivation (cont.)
The problem is there often exists some sort of confounding effect that affects both the covariates X and the dependent variable of interest, Y :
X?Y
U
This sort of confounding effect is often referred to within econometrics as endogeneity.
6/47
Endogeneity
When would X be correlated with the error term?
1. Changes in the dependent variable results in changes in one of the covariates (i.e., we want to know the effect of X → Y , but there exists some sort of effect Y → X).
2. Omitted variables that affect both dependent and independent variables.
3. Covariates have persistent measurement error (non-random).
When there exists endogeneity, we end up with biased estimates from our regression! In other words, the estimated β is no longer a good estimate for the causal relationship between X and Y .
7/47
Instruments
A solution to this is to use something known as instrumental variables.
Definition: Instrument
An instrument, Z, induces changes in the covariates X, but does not affect Y. ZX?Y
U
8/47
Instruments (cont.)
What constitutes a valid instrument?
1. Z must be correlated with X.
2. Z cannot be correlated with the error term (i.e., the confounding effect cannot also affect the instrument)
This second criteria is known as the exclusion restriction.
9/47
Example: Military Service in Vietnam (Angrist, 1990)
Context: Estimate the effect of serving in Vietnam on individual earnings Confounding Effect:
People who choose to serve in the military are likely different than people who do not
Proposed Solution: Use draft lottery numbers as an instrument for service.1
1We can think of the draft lottery numbers as an assignment mechanism; those who ‘win’ the lottery can dodge the draft (non-compliers), or serve (compliers).
10/47
Example: Streams and School Choice (Hoxby, 2000)
Context: Effect of amount of school choice in the school market on educational achievement
Dependent variable: some measure of achievement Covariates:
Individual level data
District averages
Market (overall) averages
What is the problem?
The amount of choice is likely endogenous in this case.
Proposed solution: School district boundaries were determined by geographical boundaries (like rivers). As such, the number of streams in a given area was used as an instrument for amount of school choice.
11/47
Example: Rainfall and Civil Wars (Miguel et. al, 2004)
Context: Effect of growth on the probability of civil war in Africa
What confounders may exist between economic growth and civil unrest?
Proposed Solution: Rainfall drives economic growth, and is likely to be pretty random as to when it happens.
As a result, rainfall for each region used as an instrument.
12/47
Estimation
Two-Stage Least Squares
We can think of IV estimation as a simple 2SLS process:
Stage 1: Regress X on Z (i.e., X ∼ Z).
Save the predicted values from this regression (i.e., Xˆ)
Stage 2: Regress Y on the predicted values from the first stage (i.e., Y ∼ Z). The β identified in Stage 2 will be the approximate effect.
13/47
How do we know if the instrument is good?
To assess strength of instrument:
In the first part of the regression (i.e., stage 1: X ∼ Z ), the F -statistic for this regression should be larger than 10.
To test correlation with error term (i.e., confounding effects):
Methods are built on idea that residuals should be uncorrelated with X if instruments are truly exogenous
Examples of tests we can run:
Sargan-Hansen Test
Wu Test for Exogeneity
14/47
How do we know if the instrument is good? (cont.)
Intuition behind Exogeneity Tests:
Regress the instrument with the covariate X:
X∼Z Save the predicted values (denoted as XˆZ )
Then run the following regression:
Y ∼ X + Xˆ Z
If the coefficient in front of XˆZ is statistically significant, then Z is likely also endogenous.2
2This follows from the fact that the first step is essentially a projection of X into the space of Z (represented by XˆZ ). Therefore, if XˆZ is significant in the second step, then Z cannot be orthogonal to Y .
15/47
R Example
Case Study: Wage Equation
Consider the following wage equation:
Weeksi,t =γ1 +γ2logWagei,t +γ3Educi +γ4Unioni,t +γ5Femalei +ui,t,
where Weeksi,t is the number of weeks worked.
We want to determine the effect of wages on the number of weeks worked. To
do so, we can begin by running a simple regression:
model_ols<-lm(WKS~LWAGE + ED + UNION + FEM, data = wages)
summary(model_ols)
16/47
R Example (cont.)
##
## Call:
## lm(formula = WKS ~ LWAGE + ED + UNION + FEM, data = wages)
##
## Residuals:
## Min 1Q Median 3Q Max
## -41.720 -0.807 1.301 2.834 7.172
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 44.76655
1.21528 36.836 < 2e-16 ***
0.19718 3.715 0.000206 ***
0.03206 -4.778 1.83e-06 ***
0.17006 -11.737 < 2e-16 ***
0.26417 -5.109 3.38e-07 ***
## LWAGE
## ED
## UNION
## FEM
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
0.73260
-0.15318
-1.99604
-1.34978
## Residual standard error: 5.027 on 4160 degrees of freedom
## Multiple R-squared: 0.04035, Adjusted R-squared: 0.03942
## F-statistic: 43.72 on 4 and 4160 DF, p-value: < 2.2e-16
17/47
R Example (cont.)
If the number of weeks worked and the wage that is provided are determined simultaneously, then we would expect there to be some sort of confounding effect.
Let Z be a vector of values:
Z = Ind Educ Union Female ,
where Ind is whether or not the individual works in manufacturing or not.
We run Wu’s test for exogeneity:
m1<-lm(LWAGE~IND+ED+UNION+FEM, data = wages)
lwage_hat<-fitted(m1)
m2<-lm(WKS~LWAGE + ED + UNION + FEM + lwage_hat, data = wages)
summary(m2)
18/47
R Example (cont.)
##
## Call:
## lm(formula = WKS ~ LWAGE + ED + UNION + FEM + lwage_hat, data = wages)
##
## Residuals:
## Min 1Q Median 3Q Max
## -41.538 -0.808 1.313 2.835 7.204
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 18.8987
## LWAGE 0.6938
## ED -0.4600
## UNION -2.3602
## FEM 0.6957
## lwage_hat 4.4891
## —
12.3284 1.533 0.125367
0.1980 3.505 0.000462 ***
0.1490 -3.087 0.002034 **
0.2423 -9.740 < 2e-16 ***
1.0054 0.692 0.489015
2.1290 2.108 0.035048 *
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## Residual standard error: 5.025 on 4159 degrees of freedom
## Multiple R-squared: 0.04137, Adjusted R-squared: 0.04022
## F-statistic: 35.9 on 5 and 4159 DF, p-value: < 2.2e-16
19/47
R Example (cont.)
We consider two sets of instruments:
Z1 = Ind Educ Union Female
Z2 = SMSA Educ Union Female ,
where SMSA is an indicator that tells us if someone lives in an area with a high
population density.
model_iv1 <- ivreg(WKS~LWAGE + ED + UNION + FEM |
IND+ED+UNION+FEM, data = wages)
model_iv2<-ivreg(WKS~LWAGE + ED + UNION + FEM |
IND+ED+UNION+FEM+SMSA, data = wages)
20/47
R Example (cont.)
summary(model_iv1)
##
## Call:
## ivreg(formula = WKS ~ LWAGE + ED + UNION + FEM | IND + ED + UNION +
## FEM, data = wages)
##
## Residuals:
## Min 1Q Median 3Q Max
## -41.2800 -1.9887 0.9795 3.3733 11.9176
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 18.8987 13.0668 1.446 0.1482
## LWAGE 5.1828
## ED -0.4600
## UNION -2.3602
## FEM 0.6957
## —
2.2468 2.307
0.1579 -2.913
0.2568 -9.189
1.0656 0.653
0.0211 *
0.0036 **
<2e-16 ***
0.5139
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## Residual standard error: 5.326 on 4160 degrees of freedom
## Multiple R-Squared: -0.07716, Adjusted R-squared: -0.0782
## Wald test: 37.21 on 4 and 4160 DF, p-value: < 2.2e-16
21/47
R Example (cont.)
summary(model_iv2)
##
## Call:
## ivreg(formula = WKS ~ LWAGE + ED + UNION + FEM | IND + ED + UNION +
## FEM + SMSA, data = wages)
##
## Residuals:
## Min 1Q Median 3Q Max
## -41.114 -1.375 1.162 3.064 9.699
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.70439
5.00266 6.138 9.16e-10 ***
0.85773 3.675 0.000241 ***
0.06611 -4.840 1.35e-06 ***
0.18607 -11.791 < 2e-16 ***
0.46821 -0.508 0.611499
## LWAGE
## ED
## UNION
## FEM
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
3.15182
-0.31997
-2.19398
-0.23784
## Residual standard error: 5.117 on 4160 degrees of freedom
## Multiple R-Squared: 0.005619, Adjusted R-squared: 0.004663
## Wald test: 42.24 on 4 and 4160 DF, p-value: < 2.2e-16
22/47
Table of Contents
Instrumental Variables
Context & Definitions Canonical Examples Estimation
Practical Considerations R Example
Panel Models
Motivation
Pooled Model
Fixed Effects Model Random Effects Model R Example
23/47
Motivation
What is panel data?
Panel data consists of cross-sectional units (i.e., people, households, firms, states, countries) that are observed over time.
Notation: N total units, and T total time periods.
Examples:
Panel Study of Income Dynamics (PSID): 8,000 families tracked since 1968
National Longitudinal Surveys (NLS) by the US Department of Labor:
12,000 individuals who have been annually interviewed since 1994
Penn World Table: purchasing power parity for 189 countries over
1950-2007
Generally in these kinds of data sets, there exists a large degree of unobserved individual differences within the units (formally referred to as heterogeneity).
24/47
Motivation (cont.)
Definitions
Heterogeneity: unobserved individual differences at a unit level
Balanced panel: when all individuals have the same number of observations across time
i.e., For all N individuals, we have all T observations, for a total of N · T observations
When this is not the case, we say the data is unbalanced.
25/47
Pooled Model
A naive approach would be to take the entire data set and simply run a regression by pooling all observations together:
Yi,t =α+βXit +εit
When we run a pooled model, we impose the following assumptions about the
data generating process:
1. There exists a constant relationship between X and Y across time (i.e., β does not change over time)
2. There exists a constant relationship between X and Y across sub-groups (i.e., β does not change over the different units in the data set)
26/47
Fixed Effects Model
Let’s begin by relaxing the assumption that all individuals have the same coefficient:
Yi,t =αi +βiXit +εit
In this case, note that the coefficient β now has a subscript i, implying that depending on the unit i, the relationship between Xi and Yi will change.
Intuitively, we can think of this as subsetting the data cube such that we have N individual data sets corresponding to each of the N units, each with T observations.
Problem: When N >> T , this is not a very valid estimation process.
27/47
Fixed Effects Model (cont.)
Fixed Effect Model Specification
Instead of including N different βi ’s for each unit, we can simply allow for variation in the intercept term:
Yi,t =αi +βXit +εit αi is referred to as the fixed effect.
The imposed assumption here is that all the heterogeneity is captured by this intercept term.
28/47
Fixed Effects – Estimation
There are two different ways to estimate a fixed effects model.
Approach 1: Least Squares Dummy Variable Estimation
We can rewrite the fixed effect model as:
N
Yi,t =α+βXit +γjdj +εit,
j=1
As such, the αi from the previous slide will be equivalent to α + γi .
This approach is intuitive, but can be a problem when there are a large number of individuals!
wheredj =1ifi=j,andis0otherwise.
29/47
Fixed Effects – Estimation (cont.)
Using dummy variables, assessing whether the fixed effects are valid or not is equivalent to seeing whether or not the different intercepts αi across all N units are statistically significantly different.
Equivalent to checking the following:
γ1 = γ2 = …γN
If this is true, then the fixed effect is the same across all models, and the fixed effect model should be the same as the pooled model.
If some γi ̸= γj (where i ̸= j), then there exists some fixed effect.
To test this, we can simply do ANOVA against a pooled model.
30/47
Fixed Effects – Estimation (cont.)
Approach 2: Fixed Effect Estimator
Let Y ̄i be the average Yi value across all T time periods) and X ̄i be defined equivalently for Xi . We can then transform our model to be:
Yit −Y ̄i =βXi −X ̄i+(εit −ε ̄i)
We have basically taken the data and de-meaned the observations across
time. In doing so, the fixed effect αi gets cancelled out.
The coefficient estimates depend only the variation within individuals (and heterogeneity across individuals is cancelled).
31/47
Random Effects Model
Random Effects
In the fixed effect, we assumed that all the individual differences are fixed (i.e., the heterogeneity is equal to αi ).
However, in random effects, the individual differences are seen as random perturbations from the population average:
α i = α ̄ + u i ,
where α ̄ is equal to the population average intercept.
ui are the random individual differences, known as random effects
32/47
Random Effects Model (cont.)
Properties of Random Effects
The properties of ui are very similar to the random error term in regression: E(ui)=0
cov(ui,uj) = 0 for i ̸= j
var(ui ) = σu2
In other words, ui is i.i.d. from some distribution with mean 0 and variance σu2 for all i ∈ {1,…,N}.
33/47
Random Effects Model (cont.)
Testing for Random Effects
Lagrange Multiplier Test (Breusch and Pagan, 1980): H 0 : σ u2 = 0
H A : σ u2 ̸ = 0
Hausman Test: compares whether we should use fixed or random effects
H0 : βRE is consistent HA : βRE is inconsistent
34/47
Random Effects Model (cont.)
Testing for Random Effects (cont.)
Hausman Test (cont.)
The Hausman Test can be summarized as:
H0 is true Random Effects Consistent
Fixed Effects Consistent Inefficient
HA is true Inconsistent
Consistent
Efficient
Therefore, if we use the Hausman Test and fail to reject the null, we have evidence to believe that we should use a random effects model over a fixed effects model.
35/47
R Example
Case Study: Airline Service Cost Equation
Let’s look at a case study about costs of airline services.
The
Firm output
cost equation given has the following inputs:
Price of Fuel
Load
The (1970-1984).
data set contains complete information for 5 firms and 15 years
36/47
R Example (cont.)
We fit four different models:
1. Full fixed effect model, with both firm level and time effects 2. Model with only time effects
3. Model with only firm effects
4. Pooled model
37/47
R Example (cont.)
To load in the data:
data(“USAirlines”, package= “AER”)
head(USAirlines)
## firm year output cost price load
##1 1 1970 0.952757 1140640 106650 0.534487
##2 1 1971 0.986757 1215690 110307 0.532328
##3 1 1972 1.091980 1309570 110574 0.547736
##4 1 1973 1.175780 1511530 121974 0.540846
##5 1 1974 1.160170 1676730 196606 0.591167
##6 1 1975 1.173760 1823740 265609 0.575417
38/47
R Example (cont.)
#Full Fixed Effect (and time effect):
fm_full<-lm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load + year + firm,
data = USAirlines)
#Only Time:
fm_time<-lm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load + year,
data = USAirlines)
#Only Firm:
fm_firm<-lm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load + firm,
data = USAirlines)
#Pooled:
fm_no<-lm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load, data = USAirlines)
39/47
R Example (cont.)
We can run ANOVA to see which of the effects we’ve included are valid:
anova(fm_full, fm_no)
## Analysis of Variance Table
##
## Model 1: log(cost) ~ log(output) + I(log(output)^2) + log(price) +
## load + year + firm
## Model 2: log(cost) ~ log(output) + I(log(output)^2) + log(price) + load ## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 66 0.17257
## 285 1.27492 -19 -1.1023 22.189 < 2.2e-16 ***
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
40/47
R Example (cont.)
anova(fm_full, fm_firm)
## Analysis of Variance Table
##
## Model 1: log(cost) ~ log(output) + I(log(output)^2) + log(price) +
## load + year + firm
## Model 2: log(cost) ~ log(output) + I(log(output)^2) + log(price) +
## load + firm
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1
## 2
## —
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
66 0.17257
80 0.26815 -14 -0.095584 2.6112 0.004582 **
41/47
R Example (cont.)
anova(fm_full, fm_time)
## Analysis of Variance Table
##
## Model 1: log(cost) ~ log(output) + I(log(output)^2) + log(price) +
## load + year + firm
## Model 2: log(cost) ~ log(output) + I(log(output)^2) + log(price) +
## load + year
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1
## 2
## —
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
66 0.17257
71 1.03470 -5 -0.86213 65.945 < 2.2e-16 ***
42/47
R Example (cont.)
Comparing the estimated coefficients:
Dependent variable:
log(output) I(log(output)ˆ2) log(price)
load
Constant
Observations R2
Adjusted R2
Note:
Full
0.887∗∗∗ (0.063)
0.013 (0.010)
0.128 (0.166)
−0.885∗∗∗ (0.261)
90 0.916 0.887
Time
0.917∗∗∗ (0.030)
0.021∗ (0.011)
−0.457 (0.358)
−1.807∗∗∗ (0.441)
90 0.987 0.983
Firm
1.045∗∗∗ (0.055)
0.026∗∗∗ (0.010)
0.398∗∗∗ (0.016)
−1.104∗∗∗ (0.195)
90 0.993 0.992
Pooled
0.935∗∗∗ (0.029)
0.023∗∗ (0.011)
0.458∗∗∗ (0.020)
−1.537∗∗∗ (0.342)
9.421∗∗∗ (0.230)
90 0.989 0.988
log(cost)
∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
43/47
R Example (cont.)
Comparing the different fixed effects:
Estimated Year Effect
0.0
−0.5
−1.0
−1.5
−2.0
1972
1976
Year
Full
1980
Model
Time
44/47
Estimate
R Example (cont.)
To estimate random effects, we can use the plm library: library(plm)
usair <- plm.data(USAirlines, c("firm", "year"))
#Fixed Effects:
fm_firm<-plm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load, data = usair,
model = "within", effect = "individual")
#Random Effects:
fm_rfirm <- plm(log(cost) ~ log(output) + I(log(output)^2) +
log(price) + load, data = usair,
model = "random")
45/47
R Example (cont.)
Comparing the coefficient estimates to the fixed effect models:
Dependent variable:
log(cost)
log(output) I(log(output)ˆ2) log(price)
load
Constant
Observations R2
Adjusted R2
Note:
Full FE
0.887∗∗∗ (0.063)
0.013 (0.010)
0.128 (0.166)
−0.885∗∗∗ (0.261)
90 0.916 0.887
Firm FE
1.045∗∗∗ (0.055)
0.026∗∗∗ (0.010)
0.398∗∗∗ (0.016)
−1.104∗∗∗ (0.195)
90 0.993 0.992
Pooled
0.935∗∗∗ (0.029)
0.023∗∗ (0.011)
0.458∗∗∗ (0.020)
−1.537∗∗∗ (0.342)
9.421∗∗∗ (0.230)
90 0.989 0.988
Firm RE
0.948∗∗∗ (0.037)
0.015∗ (0.009)
0.424∗∗∗ (0.014)
−1.060∗∗∗ (0.206)
9.614∗∗∗ (0.190)
90 0.992 0.992
∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01
46/47
R Example (cont.)
We can run a Hausman Test:
phtest(fm_firm, fm_rfirm)
##
## Hausman Test
##
## data: log(cost) ~ log(output) + I(log(output)^2) +
## log(price) + load
## chisq = 5.6153, df = 4, p-value = 0.2298
## alternative hypothesis: one model is inconsistent
We fail to reject the null hypothesis.
=⇒ We should use the random effects model.
47/47