Ответ 1
В настоящее время это невозможно с пакетом plm
.
Однако вы можете просто создать их самостоятельно.
Предположим, что у вас есть:
fpmg <- pmg(y~x, test, index = c('year', 'firmid'))
fpmg.coefficients <- fpmg$coefficients
# (Intercept) x
# 0.03127797 1.03558610
coeftest(fpmg)
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 0.031278 0.023356 1.3392 0.1806
# x 1.035586 0.033342 31.0599 <2e-16 ***
Затем вы можете просто создать оценки самостоятельно, как в:
the.years <- unique(test$year)
a.formula <- y ~ x
first.step <- lapply(the.years, function(a.year) {
temp.data <- test[test$year == a.year, ]
an.lm <- lm(a.formula, data = temp.data)
the.coefficients <- an.lm$coef
the.results <- as.data.frame(cbind(a.year, t(the.coefficients)))
the.results
})
first.step.df <- do.call('rbind', first.step)
second.step.coefficients <- apply(first.step.df[, -1], 2, mean)
second.step.coefficients
# (Intercept) x
# 0.03127797 1.03558610
identical(fpmg.coefficients, second.step.coefficients)
# [1] TRUE
Убедитесь, что они одинаковы в обоих направлениях на всякий случай. Наконец, вы можете получить Newey-West (1987) с заданной t-статистикой с задержкой для средств с:
library(sandwich)
second.step.NW.sigma.sq <- apply(first.step.df[, -1], 2,
function(x) sqrt(NeweyWest(lm(x ~ 1),
lag = 1, prewhite = FALSE)['(Intercept)',
'(Intercept)']))
second.step.NW.sigma.sq
# (Intercept) x
# 0.02438398 0.02859447
t.statistics.NW.lag.1 <- second.step.coefficients / second.step.NW.sigma.sq
t.statistics.NW.lag.1
# (Intercept) x
# 1.282726 36.216301
Update
В моем ответе я включил "ручной" расчет t-статистики, потому что он вычисляется быстрее.
Более общее решение состоит в том, чтобы вычислить t-статистику, скорректированную по Newey-West, и их p-значения с помощью функции coeftest()
пакета lmtest
.
coeftest(lm(first.step.df$'(Intercept)' ~ 1), vcov = NeweyWest(lm(first.step.df$'(Intercept)' ~ 1), lag = 1, prewhite = FALSE))
# t test of coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 0.031278 0.024384 1.2827 0.2316
coeftest(lm(first.step.df$x ~ 1), vcov = NeweyWest(lm(first.step.df$x ~ 1), lag = 1, prewhite = FALSE))
# t test of coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 1.035586 0.028594 36.216 4.619e-11 ***