简体   繁体   English

model 在 R 中的 plm package 中具有三个固定效果

[英]model with three fixed effects in plm package in R

I am trying to estimate the model with 3 fixed effects.我正在尝试估计具有 3 个固定效果的 model。 One is a customer-fixed effect, another one is good fixed effect and the third one is time-fixed effect.一种是客户固定效果,另一种是良好的固定效果,第三种是时间固定效果。 I am new to plm package, but as I understand, if I had just 2 fixed effects (time and good).我是 plm package 的新手,但据我所知,如果我只有 2 个固定效果(时间和良好)。 I would do something like this:我会做这样的事情:

  fe <- plm(outcome ~ dependent variable + explanatory variable 1 + explanatory variable 2, 
            data = mydata, index = c("good_id", "time"), model = 'within', effect = "twoways")

But how I approach this problem in plm package if I have not 2 fixed effects, but 3?但是,如果我没有 2 个固定效果,而是 3 个,我如何在 plm package 中解决这个问题?

You may add the third fixed effect as a dummy variable using factor() .您可以使用factor()将第三个固定效应添加为虚拟变量。 Example:例子:

library(plm)
data("Produc", package="plm")

# plm FE model
zz1 <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp + 
             factor(region),
          data=Produc, index=c("state","year"), model='within', effect="twoways")

# LSDV model
zz2 <- lm(log(gsp) ~ 0 + log(pcap) + log(pc) + log(emp) + unemp
         + factor(state) + factor(year) + factor(region),
          data=Produc)

summary(zz1)$coe
#               Estimate  Std. Error   t-value      Pr(>|t|)
# log(pcap) -0.030176057 0.026936544 -1.120265  2.629606e-01
# log(pc)    0.168828035 0.027656339  6.104497  1.655450e-09
# log(emp)   0.769306196 0.028141794 27.336786 1.275556e-114
# unemp     -0.004221093 0.001138837 -3.706493  2.256597e-04

summary(zz2)$coe[1:4,]
#               Estimate  Std. Error   t value      Pr(>|t|)
# log(pcap) -0.030176057 0.026936544 -1.120265  2.629606e-01
# log(pc)    0.168828035 0.027656339  6.104497  1.655450e-09
# log(emp)   0.769306196 0.028141794 27.336786 1.275556e-114
# unemp     -0.004221093 0.001138837 -3.706493  2.256597e-04

Yielding identical coefficients and statistics.产生相同的系数和统计数据。

Thanks to everyone for help: I actually found another solution myself which may add to provided ideas: https://cran.r-project.org/web/packages/fixest/vignettes/fixest_walkthrough.html#1_simple_example_using_trade_data This package allows inclusion of multiple fixed effects感谢大家的帮助:我自己实际上找到了另一个解决方案,可以添加到提供的想法: https://cran.r-project.org/web/packages/fixest/vignettes/fixest_walkthrough.html#1_simple_example_using_trade_data这个 package 允许包含多个固定效应

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

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