library(foreign)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
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
#Grab hjones.dta file
hjones.dt <- read.dta(file.choose())
#1) Plot of Output to labor vs Capital to Labor
p <- plot_ly(hjones.dt, x = ~hjlogyl, y = ~hjlogkl, type = 'scatter',
mode = 'text', text = ~wbcode, textposition = 'middle right',
textfont = list(color = '#000000', size = 8)) %>%
layout(title = 'Output/Labor and Capital/Labor',
xaxis = list(title = 'Output/Labor',
zeroline = TRUE),
yaxis = list(title = 'Capital/Labor'
))
p
## Warning: Ignoring 25 observations
#2) Linear Model
lm(hjlogyl ~ hjlogkl, data =hjones.dt )
##
## Call:
## lm(formula = hjlogyl ~ hjlogkl, data = hjones.dt)
##
## Coefficients:
## (Intercept) hjlogkl
## 2.7048 0.6545
#for everyone 1 unit change in the log of capital to labor ratio,
#the output to labor ration increases by .6545
#3) TFP
TFP.fct <- function(output, capital, labor) {
return((output/(labor^.07*capital^.03)))
}
#Calculate TFP for each country
hjones.dt <- hjones.dt %>%
mutate(TFP = TFP.fct(hjlogyl, hjlogkl, hjloghl))
#Average TFP
mean(hjones.dt$TFP, na.rm = TRUE)
## [1] 8.582785