尝试在 R 的反垄断包中打印结果时出错

Error while trying to print the results in R's Antitrust Package

我正在使用 R's Package Antitrust 计算需求自身和交叉价格弹性,并打印公司间合并的汇总结果。使用的模型是 Epstein and Rubinfeld (2007) 发布的 PC-AIDS(Proportionally Calibrated Almost Ideal Demand System)。这是一种品牌级模拟,公司可以在标准模拟中拥有多个品牌,正如我在 excel 中看到的那样。我的愿望是充分打印结果,在两家公司之间的合并中,其中一家拥有多个品牌(合并前)。

不过,我的问题似乎是 programming/understanding 代码输出的问题。我将 post 与我所做的类似的代码:

require(antitrust)

ownerPre<-c("a","a","b","c")

ownerPost<-c("a","a","a","c")

shares<-c(0.30,0.20,0.20,0.30)

knownelast<- -1.5
mktelast  <- -1.0

results<-pcaids(shares,knownelast, mktelast, ownerPre=ownerPre,ownerPost=ownerPost,
               labels=ownerPre,knownElastIndex=1)
resume<-summary(results)

resume

results<-summary(results) 行之后,我的输出出现以下错误 window:

Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘* a’

summary(results) 保存价格变化、产量变化等结果

也许 Antitrust 没有像我见过的 PC-AIDS 的其他版本那样预先编程,也许我无法从这个包中获得这样的结果——这使得写这个问题的练习几乎毫无意义。但是,如果这恰好是一个编程问题,在 R 方面更有经验的人可能会提供帮助,我邀请一个有用的答案。

当行名相同时打印 data.frame 个对象时出现问题:

mat <- matrix(1:10, ncol=2)
mat
     [,1] [,2]
[1,]    1    6
[2,]    2    7
[3,]    3    8
[4,]    4    9
[5,]    5   10

rownames(mat) <- rep("a", 5)
mat
  [,1] [,2]
a    1    6
a    2    7
a    3    8
a    4    9
a    5   10

现在让我们把它变成 data.frame:

temp <- as.data.frame(mat)
temp

Error in data.frame(V1 = c("1", "2", "3", "4", "5"), V2 = c(" 6", " 7", : duplicate row.names: a

您的问题的解决方案是重命名标签,使每个标签都不同:

ownerPreLab <- c("a.1","a.2","b","c")

results <- pcaids(shares, knownelast, mktelast, ownerPre=ownerPre, ownerPost=ownerPost,
                  labels=ownerPreLab, knownElastIndex=1)

resume<-summary(results)

Merger simulation results under 'PCAIDS' demand:

      priceDelta sharesPre sharesPost outputDelta
* a.1         44        30         29        -2.4
* a.2         44        20         20        -2.4
* b           81        20         16       -18.4
  c           11        30         35        16.4

    Notes: '*' indicates merging parties' products. Deltas are percent changes.
    Output is based on revenues.


Share-Weighted Price Change:    38.55
Share-Weighted CMCR:    37.58