knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Load the hayashir
package
library(hayashir)
And other libraries we need for this chapter
library(skimr) # summary stats library(dplyr) # data manipulation library(systemfit) # for fitting system of regressions
Let's get a quick look at our data by looking at the first 10 rows:
head(greene, 10)
# assign the greene data to the object 'df' df <- greene df %>% mutate(output = output / 1e3) %>% select(output, labor_share, capital_share, fuel_share) %>% skim()
Following the text, the two equations we want to estimate are:
First, specify the equations we want to estimate:
eq1 <- labor_share ~ log(price_labor / price_fuel) + log(price_capital / price_fuel) + log(output) eq2 <- capital_share ~ log(price_labor / price_fuel) + log(price_capital / price_fuel) + log(output)
As Hayashi tells us, the unique symmetry restriction is then
restrict <- c( "labor_log(price_capital/price_fuel) = capital_log(price_labor/price_fuel)" )
We estimate with the systemfit
function from the package with the same name:
sur_results <- systemfit(list(labor = eq1, capital = eq2), method = "SUR", restrict.matrix = restrict, data= df) summary(sur_results)
Which yields approximately the same coefficients as in the text.
Then we can calculate estimates of the remaining coefficients using adding up restrictions, homogeneity and symmetry. For example: $$ \hat{\gamma}{33} = \hat{\gamma}{11} + 2 \hat{\gamma}{12} + \hat{\gamma}{22} $$
So that
gamma_11 <- sur_results$coefficients["labor_log(price_labor/price_fuel)"] gamma_12 <- sur_results$coefficients["labor_log(price_capital/price_fuel)"] gamma_22 <- sur_results$coefficients["capital_log(price_capital/price_fuel)"] gamma_33 <- gamma_11 + 2 * gamma_12 + gamma_22 print(paste("gamma_33 is: ", round(gamma_33,3)))
Run the three regressions via pooled OLS. The equations are:
eq1a <- labor_share ~ log(price_labor) + log(price_capital) + log(price_fuel) + log(output) eq2a <- capital_share ~ log(price_labor) + log(price_capital) + log(price_fuel) + log(output) eq3a <- fuel_share ~ log(price_labor) + log(price_capital) + log(price_fuel) + log(output)
Then estimate:
pooled_ols <- systemfit(list(labor = eq1a, capital = eq2a, fuel = eq3a), method = "OLS", data= df) summary(pooled_ols)
And extract the residual covariance matrix:
pooled_ols$residCov
The cross elasticity (from eq 4.7.9) is:
$$ \eta_{jk} = \frac{\gamma_{jk} + s_j s_k}{s_j s_k} $$
So we calculate these for each data point, and then find the mean in our data. Let's do this for the labor-capital elasticity, $\eta_{12}$:
# the coefficient we are after gamma_12 <- sur_results$coefficients["labor_log(price_capital/price_fuel)"] # the fitted values fitted_vals <- fitted( sur_results) elasticity <- fitted_vals %>% mutate(eta_12 = (gamma_12 + (labor * capital)) / (labor * capital) ) %>% summarise(eta_12 = mean(eta_12)) print(paste0("Capital-Labor elasticity is: ", round(elasticity$eta_12, 2)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.