##load in packages/data

library(pacman)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
p_load("ivreg")
p_load("tidyverse")
p_load("fixest")
p_load("plm")
setwd('C:/Users/mooph/OneDrive/Documents/Grad HW/Metrics Term 3')
p_load("haven")
data<-read_csv("aeapnp_bedard_lee_royer.csv")
## Rows: 1351 Columns: 29
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): sex, title
## dbl (27): year, school_id, yearofphd, phd_id, business, basesalary, othersal...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Step 1.01

data$sexdummy<-ifelse(data$sex == "Female",1,0)

plot1<-ggplot(data[data$sexdummy!=0,],aes(x=salary))+
  xlab("Salary of Female Faculty")+
  ylab("Number of Faculty")+
  geom_histogram(color="black", alpha=1, position = 'identity')+
  ggtitle("Female Faculty Pay Distribution")
  

plot2<-ggplot(data[data$sexdummy!=1,],aes(x=salary))+
  xlab("Salary of Non-Female Faculty")+
  ylab("Number of Faculty")+
  geom_histogram(color="black", alpha=1, position = 'identity')+
  ggtitle("Non-Female Faculty Pay Distribution")

plot1+scale_x_continuous(labels=function(x)format(x,scientific= FALSE))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 5 rows containing non-finite values (`stat_bin()`).

plot2+scale_x_continuous(labels=function(x)format(x,scientific= FALSE))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 7 rows containing non-finite values (`stat_bin()`).

The figures above suggest that there is a pay gap where non-female faculty on average earn slightly more, and have a much greater share of the higher salary positions. So this is consistent with a sex pay gap.

Step 1.02

fit<-lm(salary~sexdummy,data=data)
lnfit<-lm(log(salary)~sexdummy,data=data)

summary(fit)
## 
## Call:
## lm(formula = salary ~ sexdummy, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -155872  -51252  -18365   42141  323755 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   180872       2238  80.813  < 2e-16 ***
## sexdummy      -18138       5231  -3.467 0.000543 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 74160 on 1342 degrees of freedom
##   (7 observations deleted due to missingness)
## Multiple R-squared:  0.008878,   Adjusted R-squared:  0.008139 
## F-statistic: 12.02 on 1 and 1342 DF,  p-value: 0.0005427
summary(lnfit)
## 
## Call:
## lm(formula = log(salary) ~ sexdummy, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.89526 -0.25843 -0.02462  0.29703  1.17091 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 12.02189    0.01228 978.840  < 2e-16 ***
## sexdummy    -0.09784    0.02871  -3.408 0.000674 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.407 on 1342 degrees of freedom
##   (7 observations deleted due to missingness)
## Multiple R-squared:  0.008581,   Adjusted R-squared:  0.007842 
## F-statistic: 11.62 on 1 and 1342 DF,  p-value: 0.0006736

Since we are trying to estimate the pay gap between female and non-female faculty it would be best to use the second regression where we are using log(salary). This is because we are regressing something that looks like the distribution is skewed to the right (from the histograms), and second off using log salary will give us a percentage change in salary instead of a nominal change (which is also more applicable to this topic.)

Step 1.03

We are trying to estimate the average treatment effect of being assigned the sex of female on the salaries of the faculty members. If there are variables that effect the status of treatment, and the outcome of salary we need to control for that. Good thing nature does a good job at randomly selecting sex at the begining of peoples lives, so there probably aren’t many omitted variables that effect treatment status and outcome. Bad controls would be things that are affected by sex assignment and the salary, those variables are “immoralities” and should be not be controlled for. There are plenty of other things we could control on like experience, age etc… but then that is trying to estimate a conditional average treatment effect not a ATE.

Step 1.04

logfit<-lm(log(salary)~year,data=data)
bias_test<-lm(sexdummy~year,data=data)
summary(logfit)
## 
## Call:
## lm(formula = log(salary) ~ year, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.46452 -0.26954 -0.07358  0.25670  1.33729 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -80.617821   4.304081  -18.73   <2e-16 ***
## year          0.045967   0.002136   21.52   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3534 on 1347 degrees of freedom
##   (2 observations deleted due to missingness)
## Multiple R-squared:  0.2558, Adjusted R-squared:  0.2553 
## F-statistic: 463.1 on 1 and 1347 DF,  p-value: < 2.2e-16
summary(bias_test)
## 
## Call:
## lm(formula = sexdummy ~ year, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.2002 -0.1959 -0.1873 -0.1442  0.8903 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -8.507526   4.713244  -1.805   0.0713 .
## year         0.004313   0.002339   1.844   0.0654 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3863 on 1344 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.002523,   Adjusted R-squared:  0.001781 
## F-statistic:   3.4 on 1 and 1344 DF,  p-value: 0.06543

Omitting year from the regression above should create bias on the average treatment effect of sex on salary since we should be controlling for things that affect both the outcome and likelihood of treatment. The last year that we observe each faculty member in their panel will definitely affect their salary due to inflation and other factors, and that could also affect the likelihood of a faculty member being female. The latter of the two affects is probably lesser, but in general the share of academic faculty members that are female in 2005 is probably significantly less than in 2018. It appears that the regression backs this up, as omitting years in the previous regression lead to a negative bias of the absolute value of the gender pay gap.

Step 1.05

num_var<-lm(log(salary)~as.numeric(year)+sexdummy,data=data)
FE<-feols(log(salary)~sexdummy|year,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
summary(num_var)
## 
## Call:
## lm(formula = log(salary) ~ as.numeric(year) + sexdummy, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.48642 -0.26428 -0.06159  0.25116  1.31460 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      -80.993941   4.289550 -18.882  < 2e-16 ***
## as.numeric(year)   0.046165   0.002129  21.684  < 2e-16 ***
## sexdummy          -0.124185   0.024741  -5.019 5.88e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3503 on 1341 degrees of freedom
##   (7 observations deleted due to missingness)
## Multiple R-squared:  0.266,  Adjusted R-squared:  0.2649 
## F-statistic: 242.9 on 2 and 1341 DF,  p-value: < 2.2e-16
summary(FE)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year: 21
## Standard-errors: Clustered (year) 
##          Estimate Std. Error  t value   Pr(>|t|)    
## sexdummy -0.12352   0.021735 -5.68302 1.4611e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.34444     Adj. R2: 0.27748 
##                 Within R2: 0.018606

It looks like controlling for year does matter. The original thought that omitting year would bring a negative bias towards our first regression is confirmed, and it is likely that year does affect salary and treatment status, so it is a good control. Our estimate for gender pay gap increased, and became more significant.

Step 1.06

data$yearsince<-data$year-data$yearofphd
data$group<-with(data,ifelse(yearsince<=9,1,ifelse(yearsince<=19,2,3)))
data$group1<-ifelse(data$yearsince<=9,1,0)
data$group2<-ifelse(data$yearsince>=10 & data$yearsince<=19,1,0)
data$group3<-ifelse(data$yearsince>=20,1,0)

as_num<-feols(log(salary)~sexdummy+as.numeric(yearsince)|year,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
bygroup<-feols(log(salary)~sexdummy|year&group,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
allgroup<-plm(log(salary)~sexdummy+group1+group2,data=data,model='within')
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
##  to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
## Warning in pdata.frame(data, index): at least one NA in at least one index dimension in resulting pdata.frame
##  to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
summary(as_num)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year: 21
## Standard-errors: Clustered (year) 
##                        Estimate Std. Error  t value   Pr(>|t|)    
## sexdummy              -0.058203   0.020708 -2.81072 1.0798e-02 *  
## as.numeric(yearsince)  0.008323   0.001457  5.71098 1.3728e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.324855     Adj. R2: 0.356821
##                  Within R2: 0.127034
summary(bygroup)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##           Estimate Std. Error  t value   Pr(>|t|)    
## sexdummy -0.097837   0.028707 -3.40809 0.00067356 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.406667     Adj. R2: 0.007842
##                  Within R2: 0.008581
summary(allgroup)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = log(salary) ~ sexdummy + group1 + group2, data = data, 
##     model = "within")
## 
## Unbalanced Panel: n = 2, T = 246-1098, N = 1344
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -2.029901 -0.216206  0.024274  0.224207  1.121085 
## 
## Coefficients:
##          Estimate Std. Error  t-value Pr(>|t|)    
## group1 -0.4084290  0.0223255 -18.2943   <2e-16 ***
## group2  0.0056702  0.0264170   0.2146   0.8301    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    222.27
## Residual Sum of Squares: 170.99
## R-Squared:      0.23068
## Adj. R-Squared: 0.22896
## F-statistic: 200.904 on 2 and 1340 DF, p-value: < 2.22e-16

Step 1.07

tenure<-feols(log(salary)~sexdummy+i_tenure|year&group,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
bus<-feols(log(salary)~sexdummy+i_tenure+business|year&group,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
curr_inst <-feols(log(salary)~sexdummy+i_tenure+business+school_id|year&group,data=data) 
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
phd_inst<-feols(log(salary)~sexdummy+i_tenure+business+school_id+phd_id|year&group,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
kitchen_sink<-feols(log(salary)~sexdummy+i_tenure+business+school_id+phd_id+micro+macromoney+metrics+labor+io+public+enviroenergy+develop+intl+finance+health+expbehave+political+urban+econhist+educ|year&group,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
summary(tenure)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##           Estimate Std. Error   t value  Pr(>|t|)    
## sexdummy -0.008792   0.024982 -0.351955   0.72493    
## i_tenure  0.452339   0.020660 21.894720 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.349038     Adj. R2: 0.268572
##                  Within R2: 0.269661
summary(bus)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##           Estimate Std. Error   t value  Pr(>|t|)    
## sexdummy -0.008799   0.024994 -0.352053   0.72485    
## i_tenure  0.452353   0.020682 21.872332 < 2.2e-16 ***
## business -0.000498   0.026760 -0.018623   0.98514    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.349038     Adj. R2: 0.268026
##                  Within R2: 0.269661
summary(curr_inst)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##            Estimate Std. Error   t value   Pr(>|t|)    
## sexdummy  -0.009556   0.024758 -0.385954 6.9959e-01    
## i_tenure   0.453887   0.020489 22.153099  < 2.2e-16 ***
## business   0.075436   0.030317  2.488266 1.2958e-02 *  
## school_id  0.000817   0.000158  5.161202 2.8237e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.345617     Adj. R2: 0.281768
##                  Within R2: 0.283907
summary(phd_inst)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##            Estimate Std. Error   t value   Pr(>|t|)    
## sexdummy  -0.009649   0.024758 -0.389735 6.9679e-01    
## i_tenure   0.453875   0.020489 22.152634  < 2.2e-16 ***
## business   0.075101   0.030319  2.477057 1.3370e-02 *  
## school_id  0.000824   0.000158  5.200073 2.3022e-07 ***
## phd_id    -0.000135   0.000135 -1.005095 3.1503e-01    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.345487     Adj. R2: 0.281774
##                  Within R2: 0.284448
summary(kitchen_sink)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year & group: 1
## Standard-errors: IID 
##               Estimate Std. Error   t value   Pr(>|t|)    
## sexdummy     -0.002727   0.025194 -0.108231 9.1383e-01    
## i_tenure      0.457321   0.020468 22.343471  < 2.2e-16 ***
## business      0.074484   0.030788  2.419234 1.5687e-02 *  
## school_id     0.000804   0.000160  5.037976 5.3561e-07 ***
## phd_id       -0.000103   0.000135 -0.763935 4.4504e-01    
## micro         0.020712   0.025798  0.802861 4.2220e-01    
## macromoney    0.041573   0.025107  1.655843 9.7991e-02 .  
## metrics       0.067545   0.025817  2.616297 8.9902e-03 ** 
## labor         0.041541   0.027618  1.504114 1.3279e-01    
## io            0.061741   0.032962  1.873103 6.1275e-02 .  
## public        0.019722   0.031139  0.633374 5.2660e-01    
## enviroenergy  0.060462   0.044516  1.358208 1.7463e-01    
## develop      -0.057379   0.032784 -1.750233 8.0310e-02 .  
## intl          0.021311   0.030254  0.704391 4.8131e-01    
## finance       0.032507   0.028232  1.151409 2.4977e-01    
## health        0.045670   0.042730  1.068817 2.8535e-01    
## expbehave     0.115174   0.039020  2.951682 3.2162e-03 ** 
## political     0.036832   0.047416  0.776788 4.3742e-01    
## urban         0.169946   0.068240  2.490420 1.2881e-02 *  
## econhist     -0.009277   0.055277 -0.167830 8.6674e-01    
## educ          0.099835   0.048777  2.046779 4.0877e-02 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.340664     Adj. R2: 0.293232
##                  Within R2: 0.304283

Step 1.08

If we believe all the things we are controlling for affect selection into treatment and the outcome than adding all of these controls will remove selection bias as we add more and more. Tenure (similarly to year) definitely affects salary, and possibly the likelihood of faculty being female since tenure takes a while and reflects admissions decisions and gender disparities of 7+ years ago. Which is a pretty weak stance since things don’t change too much in a decade. Each control after is weaker and weaker in terms of affecting selection into treatment. So maybe the first, or second control would help with selection bias, but after that it will not improve upon selection bias and could even make it worse when you throw the “whole kitchen sink” at it in the last regression.

Step 1.09

Up until this point we have been using vanilla standard errors, which assume independence between all observations (lm regressions) and cluster-robust standard errors (feols regressions). We should use cluster robust standard errors if we think that errors are correlated in clusters but not across clusters. In this case then yes we should use cluster-robust standard errors if we think that the errors across years are uncorrelated but within years are, and same goes for groups.

Step 1.10

best_est <-feols(log(salary)~sexdummy+i_tenure+as.numeric(yearsince)|year,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
summary(best_est)
## OLS estimation, Dep. Var.: log(salary)
## Observations: 1,344 
## Fixed-effects: year: 21
## Standard-errors: Clustered (year) 
##                        Estimate Std. Error   t value   Pr(>|t|)    
## sexdummy              -0.047683   0.017675 -2.697788 1.3845e-02 *  
## i_tenure               0.397789   0.035490 11.208497 4.4954e-10 ***
## as.numeric(yearsince) -0.000415   0.001958 -0.211910 8.3432e-01    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 0.297345     Adj. R2: 0.460736
##                  Within R2: 0.268629

This is my favorite estimate! its a combination of 1.05,1.06 and 1.07. The conditional independence assumption of this model is that conditional on tenure, their last year on the panel, and the years since they got a phd; a faculty member being female is “as good as random”. Although selection into treatment conditional on these controls isn’t as good as random, I think that is just as or more plausible for this model than the previous models. This is because for all of the variables in the dataset those are the only three that I think actually have an effect on whether a faculty member is female or not. My inference approach is to try to control for anything that could effect both outcome and treatment status, while trying not to have any “overlap” or redundency. This is why I excluded controlling for the three groups, because I felt that was trying to group faculty into young, middle and old, but tenure already does that atleast for younger and older. This being said, overall experience is still important, which is why I included the numeric for years since the phd.

Step 1.11

best_est1 <-feols(salary~sexdummy+i_tenure+as.numeric(yearsince)|year,data=data)
## NOTE: 7 observations removed because of NA values (LHS: 2, RHS: 5).
summary(best_est1)
## OLS estimation, Dep. Var.: salary
## Observations: 1,344 
## Fixed-effects: year: 21
## Standard-errors: Clustered (year) 
##                        Estimate Std. Error   t value   Pr(>|t|)    
## sexdummy              -7770.243   3012.759 -2.579112 1.7917e-02 *  
## i_tenure              66548.356   5103.253 13.040380 3.0863e-11 ***
## as.numeric(yearsince)   155.954    349.504  0.446216 6.6023e-01    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## RMSE: 57,804.3     Adj. R2: 0.386496
##                  Within R2: 0.238608

Changing log(salary) to salary obviously changes the outcome from a percentage to a nominal term. But this nominal term matches up with our log(salary) estimate, but seams to be slightly less significant.

Step1.12

A matching estimator would work in this setting, but it is not 100% clear how accurate it would be. This is because there are only 1350 observations, with a minority of the observations being female, so as you look to match on more covariates, the number of close or exact matches for the females will drop quickly. This being said, only matching on a relevant variable or two (year,tenure) would probably prove a solid estimator.

Step 2.01

set.seed(123)
n=1000
z_1 =runif(n, min = -5, max = 5)
z_2 =runif(n, min = -5, max = 5)
v = rnorm(n,sd=1)
w = rnorm(n,sd=sqrt(2))
p=rbinom(n,1,prob=0.2)
x=1+z_1+z_2-2*z_2*p+v+w
u=rnorm(n,sd=1)
y=2+3*x+x*p+2*u+w

ATE<- mean(y[p==1])-mean(y[p==0])
print(ATE)
## [1] 1.26135

The average treatment effect represents the differences in the mean outcomes of of when p=1 and p=0 since that is is our treatment and control groups. So in this case with this DGP the ATE is 1.26135

Step 2.02

This is a two-stage least squares setting, so regressing y on x will not give us the average treatment effect, but the local average treatment effect.

Step 2.03

set.seed(123)
n_iter=1000
n_obs = 1000
est<- matrix(NA,nrow=n_iter,ncol=5)
for (i in 1:n_iter){
z_1 =runif(n_obs, min = -5, max = 5)
z_2 =runif(n_obs, min = -5, max = 5)
v = rnorm(n_obs,sd=1)
w = rnorm(n_obs,sd=sqrt(2))
p=rbinom(n_obs,1,prob=0.2)
x=1+z_1+z_2-2*z_2*p+v+w
u=rnorm(n_obs,sd=1)
y=2+3*x+x*p+2*u+w

ols<-lm(y~x)
est[i,1]<-coef(ols)['x']

iv_1<-ivreg(y~x|z_1)
est[i,2]<-coef(iv_1)['x']

iv_2<-ivreg(y~x|z_2)
est[i,3]<-coef(iv_2)['x']

twosls1<-ivreg(y~x|z_1+z_2)
est[i,4]<-coef(twosls1)['x']

twosls2<-ivreg(y~x|z_1+z_2+z_2*p)
est[i,5]<-coef(twosls2)['x']
}

results<-data.frame(Method=c("OLS","IV_1","IV_2","2SLS_1","2SLS_2"),
        estimate=as.vector(est))

resultplot<-ggplot(results,aes(x=estimate,fill=Method))+
  geom_density(alpha=0.4)+
  xlab("Estimate")+
  ylab("Density")+
  ggtitle("Density Plot of Simulations")

resultplot

Step 2.04

It appears the first IV is more biased than the second which makes sense instrumenting on z1 should be less effective than instrumenting on z2 since z2 interacts with x more than z1. The first 2SLS appears to be the least biased though, which also makes sense because instrumenting on p (with z1 and z2) should add more variance to the estimate versus instrumenting on just z1 and z2. Every estimation technique using either z as an instrument will have bias since both zs effect y.

Step 2.05

It appears the “best” strategy would be the first of the 2SLS estimators. This is because the instrument captures more of the variation in x caused from z, than just the IV estimates. And also the first of the 2SLS estimates will have a tighter variance than the second, like I explained above. So the first 2SLS estimate is the least biased and most consistent of the 5 estimates.