Statistics Assignment Help

Statistics – Supply and Demand Task

Solution for Statistics - Supply and Demand Task

(a) β̂1 = −0.75317
 Confidence interval is: ( −0.8050502, −0.7012837 )
 (b) For a variable to be valid instrument for log_p , it should be correlated with log_p but
 uncorrelated with error term (UI
 )



For this data
 Cov(log _ p , distance _ oil1000) = 0.03071227
 and Cov(log _ p , log _ q) = −3.55e − 19~0
 Hence distance _ oil1000 is a valid instrument
 (c) If we regress log_p on distance_oil1000 and perform t-test on the mean of error term the
 following output is obtained:

This indicates we accept null hypothesis
 (d) β̂1 = −1.20575
 Confidence interval is: ( −1.295918, −0.663003 )
 (e) OLS Regression: β̂1 = −0.98471
 Confidence interval is: ( −1.032832, −0.9365815 )
 IV Regression: β̂1 = −1.63115
 Confidence interval is: ( −1.713983, −1.548315




library(foreign)
 data=read.dta("gasoline_demand_BHP2012.dta")
 new_data=data[-which(is.na(data$distance_oil1000)==TRUE),]
 #OLS
 model=lm(log_q~log_p,data=new_data)
 s=summary(model)
 #HC standard error
 hc_error=vcovHC(model,type="HC")

#conf interval
 lower=s$coefficients[2]-(1.96*hc_error[2,2])
 upper=s$coefficients[2]+(1.96*hc_error[2,2])

#instrument
 error=new_data$log_q-model$fitted.values

#checking covariance condition for instruement variable
 cov(error,new_data$log_p)
 cov(new_data$distance_oil1000,new_data$log_p)

#regressing on instrument variable
 m=lm(log_p~distance_oil1000,data=new_data,x=TRUE)
 t.test(new_data$log_p,new_data$distance_oil1000)

#iv regression
 library(AER)
 library(ivpack)
 ivmodel=ivreg(log_q~log_p|distance_oil1000,data=new_data,x=TRUE)
 s1=summary(ivmodel)
 #HC Standard error
 hc_error1=vcovHC(ivmodel,type="HC")

#conf interval
 lower1=s1$coefficients[2]-(1.96*hc_error1[2,2])
 upper1=s$coefficients[2]+(1.96*hc_error1[2,2])
 #setup 2
 #OLS
 mod=lm(log_q~log_p+log_y, data=new_data)
 s_mod=summary(mod)
 #HC Standard error
 hc_mod=vcovHC(mod,type="HC")
 #confidence interval
 lower_mod=s_mod$coefficients[2]-1.96*hc_mod[2,2]
 upper_mod=s_mod$coefficients[2]+1.96*hc_mod[2,2]

#IV
 ivmod=ivreg(log_q~log_p+log_y|distance_oil1000+log_y,data=new_data,x=TRUE)
 s_ivmod=summary(ivmod)
 #HC Standard error
 hc_ivmod=vcovHC(ivmod,type="HC")
 #confidence interval
 lower_ivmod=s_ivmod$coefficients[2]-1.96*hc_ivmod[2,2]
 upper_ivmod=s_ivmod$coefficients[2]+1.96*hc_ivmod[2,2]