r - R 中的面板数据

标签 r panel time-series regression

我一直在与 zoo 合作,利用我的时间序列数据的滞后和差分。我不使用由公司和日期组成的面板数据集。单独落后于每个公司然后合并结果变得非常麻烦。 R 中是否有任何可以处理面板数据的好包?我目前了解 plm。其他的? plm 有一个奇怪的问题,即lag顺序(即-1 vs +1)与zoots完全相反code> 因此我预见到 future 会令人头痛。有没有人喜欢的包?

最佳答案

ddply函数,在 plyr包裹, 通常使这种手术无痛 (但在大型数据集上可能会很慢)。

# Sample data
library(quantmod)
d <- NULL
for(s in c("^GSPC","^N225")) {
  tmp <- getSymbols(s,auto.assign=FALSE)
  tmp <- Ad(tmp)
  names(tmp) <- "price"
  tmp <- data.frame( date=index(tmp), id=s, price=coredata(tmp) )
  d[[s]] <- tmp
}
d <- do.call(rbind, d)
rownames(d) <- NULL

# Sample computations: lag the prices and compute the logarithmic returns
library(plyr)
d <- ddply(
  d, "id", 
  mutate,
  previous_price = lag(xts(price,date)),
  log_return = log(price / previous_price)
) 

关于r - R 中的面板数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9798441/

相关文章:

c# - UWP:显示排列成圆圈的 ListView 项目

c# - 面板重绘

r - 如何重新加载 Shiny 的应用程序

r - Microsoft R - 没有包找不到 RevoScaleR?

r - 如何将经纬度网格添加到投影 map ?

r - 如何循环和修改R中的多个数据帧

objective-c - 订购彩色面板

python - 具有多个列的时间序列,每个列都有重复的条目。如何在 Pandas 中处理

clojure - 在 clojure 中迭代时间序列的问题

r - 使用 `midasr` 包 : Inclusion of new high-frequency value 进行预测