在具有不平衡面板的 plm 中实施 Breusch-Pagan 随机效应检验
Implementation of Breusch-Pagan test for random effects in plm with unbalanced panels
我查看了 plm
(用于面板模型的 R 包)如何在 plmtest()
中实现随机效应的 Breusch-Pagan 测试,想知道它是否可以处理不平衡的面板。
对于不平衡的面板,我们需要 Baltagi/Li (1990) 给出的另一个版本的 Breusch-Pagan 随机效应检验:
带有不完整面板的误差分量模型的拉格朗日乘数检验,计量经济学评论,9:1,103-107,DOI:10.1080/07474939008800180。由于这篇论文有点难读,大家也可以看看STATA是怎么做的:http://www.stata.com/manuals13/xtxtregpostestimation.pdf
编辑
允许不平衡面板的修改后的测试现在包含在 CRAN 的包中(自版本 1.6-4 起)。
编辑:plm
的 CRAN 版本从 1.6-4 开始(2016 年 12 月)也具有 plmtest()
中的不平衡测试统计信息。
既然已经解决了,那我就post在这里回答一下。
代码现在在 r-forge plm
的开发版本 v1.15-16 中:
https://r-forge.r-project.org/projects/plm/ and https://r-forge.r-project.org/R/?group_id=406
以下是如何从 Stata 的文档中复制示例:
# get data set from Stata's webpage
# It is an unbalanced panel
require(haven) # required to read Stata data file
nlswork <- read_dta("http://www.stata-press.com/data/r14/nlswork.dta")
nlswork$race <- factor(nlswork$race) # fix data
nlswork$race2 <- factor(ifelse(nlswork$race == 2, 1, 0)) # need this variable for example
pnlswork <- pdata.frame(nlswork, index=c("idcode", "year"), drop.index=F)
# note Stata 14 uses by default a different method compared to plm's Swamy–Arora variance component estimator
# This is why in comparison with web examples from Stata the random effects coefficients slightly differ
plm_re_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "random")
# reassembles the FE estimation by Stata in Example 2 of http://www.stata.com/manuals13/xtxtreg.pdf
plm_fe_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "within")
plm_pool_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "pooling")
# Run Breusch-Pagan test with modification for unbalanced panels of Baltahi/Li (1990)
# Reassembles Example 1 in http://www.stata.com/manuals13/xtxtregpostestimation.pdf
plmtest(plm_pool_nlswork)
## Lagrange Multiplier Test - individual effects - Breusch-Pagan Test for unbalanced Panels as in Baltagi/Li (1990)
## data: ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + ...
## BP_unbalanced = 14779.98, df = 1, p-value < 0.00000000000000022
## alternative hypothesis: significant effects
我查看了 plm
(用于面板模型的 R 包)如何在 plmtest()
中实现随机效应的 Breusch-Pagan 测试,想知道它是否可以处理不平衡的面板。
对于不平衡的面板,我们需要 Baltagi/Li (1990) 给出的另一个版本的 Breusch-Pagan 随机效应检验: 带有不完整面板的误差分量模型的拉格朗日乘数检验,计量经济学评论,9:1,103-107,DOI:10.1080/07474939008800180。由于这篇论文有点难读,大家也可以看看STATA是怎么做的:http://www.stata.com/manuals13/xtxtregpostestimation.pdf
编辑 允许不平衡面板的修改后的测试现在包含在 CRAN 的包中(自版本 1.6-4 起)。
编辑:plm
的 CRAN 版本从 1.6-4 开始(2016 年 12 月)也具有 plmtest()
中的不平衡测试统计信息。
既然已经解决了,那我就post在这里回答一下。
代码现在在 r-forge plm
的开发版本 v1.15-16 中:
https://r-forge.r-project.org/projects/plm/ and https://r-forge.r-project.org/R/?group_id=406
以下是如何从 Stata 的文档中复制示例:
# get data set from Stata's webpage
# It is an unbalanced panel
require(haven) # required to read Stata data file
nlswork <- read_dta("http://www.stata-press.com/data/r14/nlswork.dta")
nlswork$race <- factor(nlswork$race) # fix data
nlswork$race2 <- factor(ifelse(nlswork$race == 2, 1, 0)) # need this variable for example
pnlswork <- pdata.frame(nlswork, index=c("idcode", "year"), drop.index=F)
# note Stata 14 uses by default a different method compared to plm's Swamy–Arora variance component estimator
# This is why in comparison with web examples from Stata the random effects coefficients slightly differ
plm_re_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "random")
# reassembles the FE estimation by Stata in Example 2 of http://www.stata.com/manuals13/xtxtreg.pdf
plm_fe_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "within")
plm_pool_nlswork <- plm(ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + I(tenure^2) + race2 + not_smsa + south
, data = pnlswork, model = "pooling")
# Run Breusch-Pagan test with modification for unbalanced panels of Baltahi/Li (1990)
# Reassembles Example 1 in http://www.stata.com/manuals13/xtxtregpostestimation.pdf
plmtest(plm_pool_nlswork)
## Lagrange Multiplier Test - individual effects - Breusch-Pagan Test for unbalanced Panels as in Baltagi/Li (1990)
## data: ln_wage ~ grade + age + I(age^2) + ttl_exp + I(ttl_exp^2) + tenure + ...
## BP_unbalanced = 14779.98, df = 1, p-value < 0.00000000000000022
## alternative hypothesis: significant effects