【发布时间】:2020-09-15 22:37:23
【问题描述】:
我有包含四个变量的每日面板数据:日期、cusip(id 标识符)、PD(默认概率)和价格。 PD 仅在 1 月、4 月、7 月和 10 月的第一天按季度提供。我想使用 tempdisagg 包中的 Chow-Lin 频率转换为 PD 生成每日数据。我知道如何在时间序列上应用td() 函数,但我没有找到面板数据框的示例。这是我使用来自devtools 包的reproduce() 的代码和示例数据,因此只包括几个示例天而不是整个季度。运行td()报错:
td 中的错误(PD ~ 价格,转换 = “first”,方法 = “chow-lin-fixed”,fixed.rho = 0.5) : 在数字模式下,'to' 必须是整数。
我知道价格和PD都是mydata中的高频每日指标,所以我想我需要在PD或类似的东西上使用to.quarterly()函数。
library(dplyr)
library(zoo)
library(tempdisagg)
library(tsbox)
mydata <- structure(list(date = structure(c(13516, 13516, 13517, 13517,13518, 13518, 13521, 13605, 13605, 13606), class = "Date"), cusip = c("31677310","66585910", "31677310", "66585910", "31677310", "66585910", "31677310","66585910", "31677310", "66585910"), PD = c(0.076891, 0.096,NA, NA, NA, NA, NA, 0.094341, 0.08867, NA), price = c(40.98, 61.31,40.99, 60.77, 40.18, 59.97, 39.92, 59.96, 38.6, 60.69)), row.names = c(6L,13L, 36L, 43L, 66L, 73L, 96L, 1843L, 1866L, 1873L), class = "data.frame")
mydata <- mydata%>%
group_by(cusip) %>%
arrange(cusip,date) %>%
mutate(PDdaily = td(PD ~ price, conversion = "first",method = "chow-lin-fixed", fixed.rho = 0.5))
【问题讨论】:
-
你能尝试建立一个可重现的例子吗?包含实际数据的一种。见这里:github.com/christophsax/seasonal/wiki/…
-
@chris 我从我的数据集中包含了一个最小样本,包括 2007 年(1 月和 4 月)的两个公司和两个季度。
标签: r panel-data