如何在 R 中查找平衡面板数据(又名,如何查找面板中的哪些条目在给定窗口内完整)
我有来自 Compustat 的大量数据。我向其中添加了一些手工收集的数据(认真地从一堆旧书中手工收集)。但我不想手工收集整个面板,只想随机选择一个子集。为了找到更大的集合(我从中随机选择),我想从 Compustat 的平衡面板开始。
我看到 plm
库可用于处理不平衡面板,但我想保持它平衡。有没有一种干净的方法可以做到这一点,而不是搜索和抛弃不运行样本期的公司(面板语言中的个人)?谢谢!
I have a big panel of data from Compustat. To it I am adding some hand-collected data (seriously hand-collected from a stack of old books). But I don't want to hand-collect for the entire panel, only a randomly selected subset. To find the larger set (from which I'm randomly selecting) I would like to start with the balanced panel from Compustat.
I see the plm
library for working with unbalanced panels, but I would like to keep it balanced. Is there a clean way to do this short of searching for and throwing out firms (individuals in panelspeak) that don't run the sample period? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
经过再三思考,有一种更简单的方法可以做到这一点。
看看这个:
After a second thought, there is a much easier way for doing this.
Look at this:
现在看,我丢失了一些数据的格式,但我可以稍后解决。这是我尝试获取面板的平衡部分:
Looking at it now, I lost the formatting on some of the data, but I can figure that out later. Here's my attempt at taking the balanced portion of the panel:
更新:我认为这个解决方案不如我上面发布的另一个解决方案好,但我将其作为解决方案的示例 - 这不太好:) *
Hi Rishard,
有点如果没有一些样本数据的帮助,这很困难。
但听起来您可以使用“reshape”包中的“melt”和“cast”来重塑数据。这样做将使您能够找到每个主题的观察太少的地方,然后使用该信息对数据进行子集化。
以下是如何完成此操作的示例代码:
干杯,
Tal
Update: I think this solution is less good then the other one I posted above, but I am leaving it as an example of a solution - which is not so good :) *
Hi Rishard,
It's a bit difficult with out some sample data to help.
But it sound like you could reshape your data using "melt" and "cast" from the "reshape" package. Doing that will enable you to find where you have too few observation per subject, and then use that information to subset your data.
Here is an example code of how this can be done:
Cheers,
Tal