library(readxl)
library(data.table); library(dplyr); library(lubridate);
library(stargazer); library(sandwich); library(lmtest); library(statar);


dt_lbo <- read_excel("./LBO_HLP.xlsx", sheet = "data", skip = 1) %>% data.table
setnames(dt_lbo, c("date", "date_ym", "rp", "hy", "ebitda", "gz", "vol", "scaled_vol", "at_val") )
dt_lbo[, dateq := as.quarterly(date) ]
dt_lbo[, quarter := as.factor(quarter(date)) ]

dateq_start <- as.quarterly(ISOdate(1982, 12, 1))
dt_lbo[ dateq >= dateq_start ] %>% sum_up
dt_lbo <- dt_lbo[ dateq >= dateq_start ]

r1 <- lm(scaled_vol ~ rp + quarter, dt_lbo)
r2 <- lm(scaled_vol ~ ebitda + quarter, dt_lbo)
r3 <- lm(scaled_vol ~ rp + ebitda + quarter, dt_lbo)
r4 <- lm(scaled_vol ~ hy + quarter, dt_lbo)
r5 <- lm(scaled_vol ~ rp + hy + quarter, dt_lbo)
r6 <- lm(scaled_vol ~ gz + quarter, dt_lbo)
r7 <- lm(scaled_vol ~ rp + gz + quarter, dt_lbo)
r8 <- lm(scaled_vol ~ ebitda + hy + gz + quarter, dt_lbo)
r9 <- lm(scaled_vol ~ rp + ebitda + hy + gz + quarter, dt_lbo)

r1 <- coeftest(r1, df = Inf, vcov = NeweyWest(r1, lag=4, prewhite = F) )
r2 <- coeftest(r2, df = Inf, vcov = NeweyWest(r2, lag=4, prewhite = F) )
r3 <- coeftest(r3, df = Inf, vcov = NeweyWest(r3, lag=4, prewhite = F) )
r4 <- coeftest(r4, df = Inf, vcov = NeweyWest(r4, lag=4, prewhite = F) )
r5 <- coeftest(r5, df = Inf, vcov = NeweyWest(r5, lag=4, prewhite = F) )
r6 <- coeftest(r6, df = Inf, vcov = NeweyWest(r6, lag=4, prewhite = F) )
r7 <- coeftest(r7, df = Inf, vcov = NeweyWest(r7, lag=4, prewhite = F) )
r8 <- coeftest(r8, df = Inf, vcov = NeweyWest(r8, lag=4, prewhite = F) )
r9 <- coeftest(r9, df = Inf, vcov = NeweyWest(r9, lag=4, prewhite = F) )

stargazer(r1, r2, r3, r4, r5, r6, r7, r8, r9,
          type = "text", digits = 2, keep = c("rp", "ebitda", "hy", "gz") )

r1 <- lm(at_val ~ rp + quarter, dt_lbo)
r2 <- lm(at_val ~ ebitda + quarter, dt_lbo)
r3 <- lm(at_val ~ rp + ebitda + quarter , dt_lbo)
r4 <- lm(at_val ~ hy + quarter, dt_lbo)
r5 <- lm(at_val ~ rp + hy + quarter, dt_lbo)
r6 <- lm(at_val ~ gz + quarter, dt_lbo)
r7 <- lm(at_val ~ rp + gz + quarter, dt_lbo)
r8 <- lm(at_val ~ ebitda + hy + gz + quarter, dt_lbo)
r9 <- lm(at_val ~ rp + ebitda + hy + gz + quarter, dt_lbo)

r1 <- coeftest(r1, df = Inf, vcov = NeweyWest(r1, lag=4, prewhite = F) )
r2 <- coeftest(r2, df = Inf, vcov = NeweyWest(r2, lag=4, prewhite = F) )
r3 <- coeftest(r3, df = Inf, vcov = NeweyWest(r3, lag=4, prewhite = F) )
r4 <- coeftest(r4, df = Inf, vcov = NeweyWest(r4, lag=4, prewhite = F) )
r5 <- coeftest(r5, df = Inf, vcov = NeweyWest(r5, lag=4, prewhite = F) )
r6 <- coeftest(r6, df = Inf, vcov = NeweyWest(r6, lag=4, prewhite = F) )
r7 <- coeftest(r7, df = Inf, vcov = NeweyWest(r7, lag=4, prewhite = F) )
r8 <- coeftest(r8, df = Inf, vcov = NeweyWest(r8, lag=4, prewhite = F) )
r9 <- coeftest(r9, df = Inf, vcov = NeweyWest(r9, lag=4, prewhite = F) )

stargazer(r1, r2, r3, r4, r5, r6, r7, r8, r9,
          type = "text", digits = 2, keep = c("rp", "ebitda", "hy", "gz") )