为什么我的fe数据表现不佳lm无法从plm,lfe和lsdv中再现系数?

如何解决为什么我的fe数据表现不佳lm无法从plm,lfe和lsdv中再现系数?

我正在尝试使用不同的软件包和技术为面板数据重现固定效果系数:(1)plm(),(2)lfe(),(3)带lm()的dummy-lsdv ,和(4)用lm()贬值。

我的数据集包含1581个观测值和13个变量。它是来自527个受访者(无声=响应者)的3次波动(无声=波动)的调查数据。我有一个DV(y)和10个IV(x1至x10)。

数据集如下:

  respondent  wave      y    x1    x2    x3    x4    x5    x6    x7    x8    x9   x10
       <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1          1     1  1         1     2    NA    NA     2   1     1.5  NA      NA     2
2          1     2 NA         2    NA     0     0     0   1     4     4       1     3
3          1     3 NA         4     5    NA    NA    NA  NA     8    NA      NA     1
4          2     1  0.931     3     3     2     2     2   4     7.5   7.5    NA     3
5          2     2  0.986     4    NA    NA     2     2   4.5   6.5   5       3     4
6          2     3  0.986     4     3     2     2     2   3     3     3       2     3

我的问题:当我使用(1)plm(),(2)lfe()和(3)dummy-lsdv使用{{1}执行固定效果回归时},模型总是返回相同的系数。但是,当我使用(4)淡入淡出的数据和lm()包执行固定效果回归时,我得到了不同的系数。这让我感到困惑,我想知道:为什么?

这是我的代码:

1。 lm()

输入:

plm()

输出:

library(plm)
model_plm <- plm(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10,data = dataset,index=c("respondent","wave"),model = "within",effect = 'individual')
summary(model_plm)

2。 Unbalanced Panel: n = 228,T = 1-2,N = 316 Residuals: Min. 1st Qu. Median 3rd Qu. Max. -0.3240866 -0.0048416 0.0000000 0.0048416 0.3240866 Coefficients: Estimate Std. Error t-value Pr(>|t|) x1 -0.0216484 0.0167614 -1.2916 0.20032 x2 0.0178114 0.0141219 1.2613 0.21097 x3 -0.0145262 0.0103954 -1.3974 0.16627 x4 -0.0061660 0.0133069 -0.4634 0.64439 x5 0.0174401 0.0144256 1.2090 0.23032 x6 -0.0053556 0.0067210 -0.7968 0.42796 x7 0.0065517 0.0097627 0.6711 0.50415 x8 -0.0151375 0.0081992 -1.8462 0.06865 . x9 0.0235351 0.0092612 2.5412 0.01303 * x10 0.0235181 0.0228927 1.0273 0.30745 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

输入:

lfe()

输出:

library(lfe)
model_lfe <- felm(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 | respondent,data = dataset)
summary(model_lfe)

3。带有Coefficients: Estimate Std. Error t value Pr(>|t|) x1 -0.021648 0.016761 -1.292 0.2003 x2 0.017811 0.014122 1.261 0.2110 x3 -0.014526 0.010395 -1.397 0.1663 x4 -0.006166 0.013307 -0.463 0.6444 x5 0.017440 0.014426 1.209 0.2303 x6 -0.005356 0.006721 -0.797 0.4280 x7 0.006552 0.009763 0.671 0.5041 x8 -0.015138 0.008199 -1.846 0.0687 . x9 0.023535 0.009261 2.541 0.0130 * x10 0.023518 0.022893 1.027 0.3074 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 的LSDV:

输入:

lm()

输出:

model_lsdv <- lm(y ~ as_factor(respondent) + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10,data = dataset)
options(max.print=2000)
summary(model_lsdv)

4。 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.9499746 0.1505806 6.309 1.57e-08 *** [...] x1 -0.0216484 0.0167614 -1.292 0.20032 x2 0.0178114 0.0141219 1.261 0.21097 x3 -0.0145262 0.0103954 -1.397 0.16627 x4 -0.0061660 0.0133069 -0.463 0.64439 x5 0.0174401 0.0144256 1.209 0.23032 x6 -0.0053556 0.0067210 -0.797 0.42796 x7 0.0065517 0.0097627 0.671 0.50415 x8 -0.0151375 0.0081992 -1.846 0.06865 . x9 0.0235351 0.0092612 2.541 0.01303 * x10 0.0235181 0.0228927 1.027 0.30745 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 使FE贬值:

输入:

lm()

输出:

dataset_demeaned <- with(dataset,data.frame(respondent = respondent,wave = wave,y = y - ave(y,respondent,FUN=function(x) mean(x,na.rm=T)),x1 = x1 - ave(x1,x2 = x2 - ave(x2,x3 = x3 - ave(x3,x4 = x4 - ave(x4,x5 = x5 - ave(x5,x6 = x6 - ave(x6,x7 = x7 - ave(x7,x8 = x8 - ave(x8,x9 = x9 - ave(x9,x10 = x10 - ave(x10,na.rm=T))
                                            )
                        )

model_dmd <- lm(y ~ 0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10,data = dataset_demeaned)
summary(model_dmd)

更多信息:
我已经执行了以下检查:

  • 我已经使用其他方式对数据进行举止,例如Coefficients: Estimate Std. Error t value Pr(>|t|) x1 -0.006223 0.008220 -0.757 0.44957 x2 0.013181 0.007880 1.673 0.09543 . x3 -0.012807 0.005484 -2.335 0.02018 * x4 -0.006431 0.006311 -1.019 0.30900 x5 0.015455 0.005941 2.602 0.00973 ** x6 -0.001429 0.003402 -0.420 0.67483 x7 0.004362 0.004698 0.929 0.35387 x8 -0.009336 0.004366 -2.139 0.03326 * x9 0.015731 0.005267 2.987 0.00305 ** x10 0.007631 0.010922 0.699 0.48529 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 函数。 ->与4中相同的结果。
  • 我已经手工计算了一些脱气数据,这些数据产生的结果与demean()ave()函数相同。
  • 我一直尝试使用demean()选项,因为我希望问题可能是由于对缺失值的不同处理而导致的。但这并没有改变结果。
  • 我曾经在(4)个行为举止的fe模型中包含响应变量na.action。像:as_factor。这种方法再现了正确的系数。但是,贬低应该已经解决了未观察到的异质性,因此将假人包括在内似乎是多余的。

所以我最好的猜测是问题不是出自贬低的过程,而是来自model_dmd <- lm(y ~ 0 + as_factor(respondent) + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10,data = dataset_demeaned)函数。也许小组是lm()的事实在这里发挥了作用?

非常感谢您的任何建议和解释!


解决方案

由于@ G.Grothendieck,我可以在此处发布解决方案。正确的(4)用unbalanced表现为FE的正确代码应为:

输入:

lm()

输出:

# Delete all rows with NAs
dataset <- na.omit(dataset)

# Demean the rows that are left behind
dataset_demeaned <- with(dataset,na.rm=T))
                                             )
                         )

model_dmd <- lm(y ~ 0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10,data = dataset_demeaned)
summary(model_dmd)

解决方法

通过分别分隔每一列,这将不一致地处理NA。每行都必须使用或不使用。一个变量不能行,另一个变量不能行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-