繁体   English   中英

小组分组回归

[英]Panel regression by group

我搜索了许多问题,但是没有一个人使用plm

我有一个公司年面板数据dt ,每个公司都有不同的年观察值。 我有一个面板回归:

plm(y~ lag(x1, 1)+ lag(x2, 1)+ lag(log(x3), 1),
data= dt, model= "within", effect= "twoways", index= c("firm", "fyear"))

我想对每个企业集团使用这种面板回归。 我试过by ,在dplyr group bylmList ,但是它们都不适用于plm 由于回归中存在滞后项,因此必须使用plm回归。

假设您有一个group列:

library(plm)
#get data
data("Produc", package = "plm")
dt=Produc[,c("state","year","gsp","pcap","pc","emp","region")]
colnames(dt)=c("firm","fyear","y","x1","x2","x3","group") #your names + group
plm(y~ lag(x1, 1)+ lag(x2, 1)+ lag(log(x3), 1),
    data= dt, model= "within", effect= "twoways", index= c("firm", "fyear"))
#Model Formula: y ~ lag(x1, 1) + lag(x2, 1) + lag(log(x3), 1)
#
#Coefficients:
#     lag(x1, 1)      lag(x2, 1) lag(log(x3), 1) 
#       -0.50586         0.88671     12417.08080 

# split and lapply
dts=split(dt,dt$group)
regs=lapply(dts,function(dtt)plm(y~ lag(x1, 1)+ lag(x2, 1)+ lag(log(x3), 1),
                            data= dtt, model= "within", effect= "twoways", 
                            index= c("firm", "fyear"))$coefficients)
do.call("rbind",regs)

# > do.call("rbind",regs)
# lag(x1, 1) lag(x2, 1) lag(log(x3), 1)
# 1 -1.51064158 1.96541347        8163.974
# 2 -0.06268382 0.95112243      110801.043
# 3  1.06379297 0.06485576       63507.876
# 4  1.10813773 0.56661881        7429.956
# 5  0.90277939 0.52108922       46308.862
# 6  2.38345950 0.36220682       73134.118
# 7  2.68155543 0.31143095      -23427.304
# 8  1.94446802 0.22973996        5196.212
# 9  1.35110639 1.25191285      -82916.241

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM