20

Newey-West 標準エラーをパッケージpmg()からの (Mean Groups/Fama-MacBeth estimator)の出力で動作させようとしています。plm

hereの例に従ってください:

require(foreign)
require(plm)
require(lmtest)
test <- read.dta("http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/test_data.dta")

fpmg <- pmg(y~x, test, index=c("firmid", "year")) # Time index in second position, unlike the example

coeftestFama-MacBeth 標準エラーを取得するために直接使用できます。

# Regular “Fama-MacBeth” standard errors
coeftest(fpmg)

# t test of coefficients:
#   
#             Estimate Std. Error t value Pr(>|t|)    
# (Intercept) 0.032470   0.071671   0.453   0.6505    
# x           0.969212   0.034782  27.866   <2e-16 ***
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

ただし、Newey-West 推定量を使用しようとすると失敗します。

# Newey-West standard-errors
coeftest(fpmg, vcov = NeweyWest(fpmg, lag=3))

# Error in UseMethod("estfun") : 
#   no applicable method for 'estfun' applied to an object of class "c('pmg', 'panelmodel')"

plmこれはパッケージの欠点のようです。これを機能させる方法を知っていますか?オブジェクトestfun用に独自のコードを作成する必要がありますか? pmgNewey-West 推定量をゼロからコーディングしますか? plmまたは、パッケージを完全にバイパスする必要がありますか?

4

2 に答える 2

2

現在、これは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

念のため、それらが両方の方法で同一であることを確認してください。最後に、平均値の 1 つのラグ調整済み t 統計量を使用して Newey-West (1987) を取得できます。

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

アップデート

私の答えでは、t統計量の「手動」計算のみを含めました。これは、計算が高速であるためです。より一般的な解決策は、Newey-West 補正された t 統計とその 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 ***
于 2016-06-24T15:51:13.560 に答える