我试图从矩阵创建一个系数图(https://lrberge.github.io/fixest/reference/coefplot.html).(这是为了显示交互作用项的线性组合,请参见下面的示例代码.文档-见上面的链接-表明这应该是可能的:对象可以是系数表的矩阵.或者,我应该能够提供一个估计向量,加上置信区间信息,以创建coefplot.我没能做到.
我try 了以下几种方法:
##packages and libraries required:
##fixest
##biostat3
library(biostat3)
library(fixest)
##load example data
data(base_did)
base_inter = base_did
##Run simple regression with interactions
A <- lm(y ~factor(period)*treat, base_inter)
##Create linear combinations
C<-lincom(A,c("treat","treat+factor(period)2:treat","treat+factor(period)3:treat", "treat+factor(period)10:treat"))
##Transform to matrix
T<-as.matrix(C)
##Remove unnecessary information and dimension names
T<-T[,1:3]
dimnames(T) <- NULL
##run coefplot from fixest
fixest::coefplot(T[,1],ci_low=T[,2],ci_high=T[,3])
我收到一个错误:
Error in data.frame(estimate = estimate, ci_low = ci_low, ci_high = ci_high, :
arguments imply differing number of rows: 4, 0
我不明白这一点,因为矩阵T有三列四行,所以维度应该是正确的.
[,1] [,2] [,3]
[1,] -1.061001 -2.99068 0.8686775
[2,] -0.7100586 -2.639737 1.21962
[3,] 1.458543 -0.4711357 3.388222
[4,] 7.90124 5.971561 9.830918