## Exercise Chapter 3
## Problem 3
## Background
install.packages(AER)
suppressMessages(library(AER))
## attach the data-set Journals to the current R-session
data(Journals, package = AER)
## ?Journals # Check the help file #
## Select variable subs and price
journals <- Journals[, c(“subs”, “price”)] # subpriceselect## Define variable ‘journals-price per citation’journals$citeprice <- Journals$price/Journals$citations # $Journals## Define variable ‘journals-age’journals$age <- 2020 – Journals$foundingyear # foundingyear## Check variable name in ‘journals’names(journals)## [1] “subs””price” “citeprice” “age”## Estimate the coefficients beta_1 and beta_2 of the linear regression model: log(Y) = beta_1 + beta_2*log(X) + eps## log(Y) = log(subs) and log(X) = log(citeprice)## Problem 3a residuals – fitted valueheteroscedastic error-term variances()## Solutionjour_lm <- lm(log(subs) ~ log(citeprice), data = journals) # lm lm(Y~X1+…+Xk, data), Y~X1+…+Xk XY+## Diagnostic plot residuals against fitted values## plot(y = resid(jour_lm), x = fitted(jour_lm)) # ## Or plot(jour_lm, which = 1) # which## different variance in the error termheteroscedastic## Problem 3b Estimate the standard error of the OLS estimator beta_hat_2## Solution## HC robust variance estimationlibrary(“sandwich”) ## Robust estimation of the variance of hatbetaVar_hat_beta_HC3 <- sandwich::vcovHC(jour_lm, type = “HC3”) # sandwich::vcovHCHeteroscedasticity-Consistent Covariance Matrix EstimationHC3HC3# typeestimation type## Robust standard error of hatbeta_2sqrt(diag(Var_hat_beta_HC3)[2]) # sqrtdiag(x)x22. variance component## log(citeprice) ## 0.03447364 ## Comparison with the classic standard error estimationsqrt(diag(vcov(jour_lm))[2]) # Calculate Variance-Covariance Matrix for a Fitted Model Object## log(citeprice) ## 0.0356132
Reviews
There are no reviews yet.