Yi=β0+β1Xi+ui
Error term, ui includes all other variables that affect Y
Every regression model always has omitted variables assumed in the error
Again, we assume u is random, with E[u|X]=0 and var(u)=σ2u
Sometimes, omission of variables can bias OLS estimators (^β0 and ^β1)
1. Z is a determinant of Y
1. Z is a determinant of Y
2. Z is correlated with the regressor X
^β1 is biased: E[^β1]≠β1
^β1 systematically over- or under-estimates the true relationship (β1)
^β1 “picks up” both:
Example: Consider our recurring class size and test score example: Test scorei=β0+β1STRi+ui
Example: Consider our recurring class size and test score example: Test scorei=β0+β1STRi+ui
Example: Consider our recurring class size and test score example: Test scorei=β0+β1STRi+ui
Zi: time of day of the test
Zi: parking space per student
Example: Consider our recurring class size and test score example: Test scorei=β0+β1STRi+ui
Zi: time of day of the test
Zi: parking space per student
Zi: percent of ESL students
E[^β1]=β1+cor(X,u)σuσX
E[^β1]=β1+cor(X,u)σuσX
1) If X is exogenous: cor(X,u)=0, we're just left with β1
E[^β1]=β1+cor(X,u)σuσX
1) If X is exogenous: cor(X,u)=0, we're just left with β1
2) The larger cor(X,u) is, larger bias: (E[^β1]−β1)
E[^β1]=β1+cor(X,u)σuσX
1) If X is exogenous: cor(X,u)=0, we're just left with β1
2) The larger cor(X,u) is, larger bias: (E[^β1]−β1)
3) We can “sign” the direction of the bias based on cor(X,u)
† See 2.4 class notes for proof.
# Select only the three variables we want (there are many)CAcorr<-CASchool %>% select("str","testscr","el_pct")# Make a correlation tablecorr<-cor(CAcorr)corr
## str testscr el_pct## str 1.0000000 -0.2263628 0.1876424## testscr -0.2263628 1.0000000 -0.6441237## el_pct 0.1876424 -0.6441237 1.0000000
el_pct
is strongly (negatively) correlated with testscr
(Condition 1)
el_pct
is reasonably (positively) correlated with str
(Condition 2)
# Make a correlation plotlibrary(corrplot)corrplot(corr, type="upper", method = "number", # number for showing correlation coefficient order="original")
el_pct
is strongly correlated with testscr
(Condition 1)el_pct
is reasonably correlated with str
(Condition 2) # make a new variable called EL# = high (if el_pct is above median) or = low (if below median)CASchool<-CASchool %>% # next we create a new dummy variable called ESL mutate(ESL = ifelse(el_pct > median(el_pct), # test if ESL is above median yes = "High ESL", # if yes, call this variable "High ESL" no = "Low ESL")) # if no, call this variable "Low ESL"# get average test score by high/low ELCASchool %>% group_by(ESL) %>% summarize(Average_test_score=mean(testscr))
ABCDEFGHIJ0123456789 |
ESL <chr> | Average_test_score <dbl> | |||
---|---|---|---|---|
High ESL | 643.9591 | |||
Low ESL | 664.3540 |
ggplot(data = CASchool)+ aes(x = testscr, fill = ESL)+ geom_density(alpha=0.5)+ labs(x = "Test Score", y = "Density")+ ggthemes::theme_pander( base_family = "Fira Sans Condensed", base_size=20 )+ theme(legend.position = "bottom")
esl_scatter<-ggplot(data = CASchool)+ aes(x = str, y = testscr, color = ESL)+ geom_point()+ geom_smooth(method="lm")+ labs(x = "STR", y = "Test Score")+ ggthemes::theme_pander( base_family = "Fira Sans Condensed", base_size=20 )+ theme(legend.position = "bottom")esl_scatter
esl_scatter+ facet_grid(~ESL)+ guides(color = F)
E[^β1]=β1+bias
cor(STR,u) is positive (via %EL)
cor(u,Test score) is negative (via %EL)
β1 is negative (between Test score and STR)
Bias is positive
If school districts with higher Test Scores happen to have both lower STR AND districts with smaller STR sizes tend to have less %EL ...
If school districts with higher Test Scores happen to have both lower STR AND districts with smaller STR sizes tend to have less %EL ...
Consider an ideal random controlled trial (RCT)
Randomly assign experimental units (e.g. people, cities, etc) into two (or more) groups:
Compare results of two groups to get average treatment effect
Example: Imagine an ideal RCT for measuring the effect of STR on Test Score
School districts would be randomly assigned a student-teacher ratio
With random assignment, all factors in u (family size, parental income, years in the district, day of the week of the test, climate, etc) are distributed independently of class size
Example: Imagine an ideal RCT for measuring the effect of STR on Test Score
Thus, cor(STR,u)=0 and E[u|STR]=0, i.e. exogeneity
Our ^β1 would be an unbiased estimate of β1, measuring the true causal effect of STR → Test Score
But our data is not an RCT, it is observational data!
“Treatment” of having a large or small class size is NOT randomly assigned!
%EL: plausibly fits criteria of O.V. bias!
Thus, “control” group and “treatment” group differs systematically!
Treatment Group
Control Group
Causal pathways connecting str and test score:
DAG rules tell us we need to control for ESL in order to identify the causal effect of
So now, how do we control for a variable?
Look at effect of STR on Test Score by comparing districts with the same %EL.
The simple fix is just to not omit %EL!
Treatment Group
Control Group
Look at effect of STR on Test Score by comparing districts with the same %EL.
The simple fix is just to not omit %EL!
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
Yi=β0+β1X1i+β2X2i+⋯+βkXki+ui
† Note Bailey defines k to include both the number of variables plus the constant.
Yi=β0+β1X1i+β2X2i
Y=β0+β1X1+β2X2Before the change
Yi=β0+β1X1i+β2X2i
Y=β0+β1X1+β2X2Before the changeY+ΔY=β0+β1(X1+ΔX1)+β2X2After the change
Yi=β0+β1X1i+β2X2i
Y=β0+β1X1+β2X2Before the changeY+ΔY=β0+β1(X1+ΔX1)+β2X2After the changeΔY=β1ΔX1The difference
Yi=β0+β1X1i+β2X2i
Y=β0+β1X1+β2X2Before the changeY+ΔY=β0+β1(X1+ΔX1)+β2X2After the changeΔY=β1ΔX1The differenceΔYΔX1=β1Solving for β1
β1=ΔYΔX1 holding X2 constant
β1=ΔYΔX1 holding X2 constant
Similarly, for β2:
β2=ΔYΔX2 holding X1 constant
β1=ΔYΔX1 holding X2 constant
Similarly, for β2:
β2=ΔYΔX2 holding X1 constant
And for the constant, β0:
β0=predicted value of Y when X1=0,X2=0
Alternatively, we can write the population regression equation as: Yi=β0X0i+β1X1i+β2X2i+ui
Here, we added X0i to β0
X0i is a constant regressor, as we define X0i=1 for all i observations
Likewise, β0 is more generally called the “constant” term in the regression (instead of the “intercept”)
This may seem silly and trivial, but this will be useful next class!
Example:
Beer Consumptioni=β0+β1Pricei+β2Incomei+β3Nachos Pricei+β4Wine Price+ui
Example:
Beer Consumptioni=β0+β1Pricei+β2Incomei+β3Nachos Pricei+β4Wine Price+ui
Let's see what you remember from micro(econ)!
What measures the price effect? What sign should it have?
Example:
Beer Consumptioni=β0+β1Pricei+β2Incomei+β3Nachos Pricei+β4Wine Price+ui
Let's see what you remember from micro(econ)!
What measures the price effect? What sign should it have?
What measures the income effect? What sign should it have? What should inferior or normal (necessities & luxury) goods look like?
Example:
Beer Consumptioni=β0+β1Pricei+β2Incomei+β3Nachos Pricei+β4Wine Price+ui
Let's see what you remember from micro(econ)!
What measures the price effect? What sign should it have?
What measures the income effect? What sign should it have? What should inferior or normal (necessities & luxury) goods look like?
What measures the cross-price effect(s)? What sign should substitutes and complements have?
Example:
^Beer Consumptioni=20−1.5Pricei+1.25Incomei−0.75Nachos Pricei+1.3Wine Pricei
# run regression of testscr on str and el_pctschool_reg_2 <- lm(testscr ~ str + el_pct, data = CASchool)
lm(y ~ x1 + x2, data = df)
y
is dependent variable (listed first!)~
means “modeled by”x1
and x2
are the independent variabledf
is the dataframe where the data is stored# look at reg objectschool_reg_2
## ## Call:## lm(formula = testscr ~ str + el_pct, data = CASchool)## ## Coefficients:## (Intercept) str el_pct ## 686.0322 -1.1013 -0.6498
lm
object called school_reg_2
, a list
objectsummary(school_reg_2) # get full summary
## ## Call:## lm(formula = testscr ~ str + el_pct, data = CASchool)## ## Residuals:## Min 1Q Median 3Q Max ## -48.845 -10.240 -0.308 9.815 43.461 ## ## Coefficients:## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 686.03225 7.41131 92.566 < 2e-16 ***## str -1.10130 0.38028 -2.896 0.00398 ** ## el_pct -0.64978 0.03934 -16.516 < 2e-16 ***## ---## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1## ## Residual standard error: 14.46 on 417 degrees of freedom## Multiple R-squared: 0.4264, Adjusted R-squared: 0.4237 ## F-statistic: 155 on 2 and 417 DF, p-value: < 2.2e-16
# load packageslibrary(broom)# tidy regression outputtidy(school_reg_2)
ABCDEFGHIJ0123456789 |
term <chr> | estimate <dbl> | std.error <dbl> | |
---|---|---|---|
(Intercept) | 686.0322487 | 7.41131248 | |
str | -1.1012959 | 0.38027832 | |
el_pct | -0.6497768 | 0.03934255 |
library(huxtable)huxreg("Model 1" = school_reg, "Model 2" = school_reg_2, coefs = c("Intercept" = "(Intercept)", "Class Size" = "str", "%ESL Students" = "el_pct"), statistics = c("N" = "nobs", "R-Squared" = "r.squared", "SER" = "sigma"), number_format = 2)
Model 1 | Model 2 | |
---|---|---|
Intercept | 698.93 *** | 686.03 *** |
(9.47) | (7.41) | |
Class Size | -2.28 *** | -1.10 ** |
(0.48) | (0.38) | |
%ESL Students | -0.65 *** | |
(0.04) | ||
N | 420 | 420 |
R-Squared | 0.05 | 0.43 |
SER | 18.58 | 14.46 |
*** p < 0.001; ** p < 0.01; * p < 0.05. |
Yi=β0+β1Xi+ui
Error term, ui includes all other variables that affect Y
Every regression model always has omitted variables assumed in the error
Again, we assume u is random, with E[u|X]=0 and var(u)=σ2u
Sometimes, omission of variables can bias OLS estimators (^β0 and ^β1)
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |