我想知道是否有一种方法可以以自定义的方式格式化etable
中报告的系数。
例如,在下面的回归中
library(fixest)
feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width | Species, iris)
model_fit = feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width | Species, iris)
etable(model_fit)
model_fit
Dependent Var.: Sepal.Length
Sepal.Width 0.4959. (0.1206)
Petal.Length 0.8292* (0.0970)
Petal.Width -0.3152 (0.1096)
Fixed-Effects: ----------------
Species Yes
_______________ ________________
S.E.: Clustered by: Species
Observations 150
R2 0.86731
Within R2 0.65201
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
我只想乘以100乘以Sepal.Width
的系数进行报告,并为调整写一个单独的注释,这样etable
的报告看起来像
model_fit
Dependent Var.: Sepal.Length
Sepal.Width 49.59 (0.1206)
Petal.Length 0.8292* (0.0970)
Petal.Width -0.3152 (0.1096)
Fixed-Effects: ----------------
Species Yes
_______________ ________________
S.E.: Clustered by: Species
Observations 150
R2 0.86731
Within R2 0.65201
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
在fixest
etable
中有没有一种方便的方法可以实现这一点?
缩放Sepal.Width
列并重新运行回归对我来说是最不可取的选择。
谢谢。
您可以这样做:
- 创建一个助手函数,该函数将
etable(model_fit)$model_fit
返回的对象中的一个字符串条目作为x
,并使用正则表达式提取系数,乘以m=100
,然后将其粘贴回原始字符串x
f <- function(x,m=100) {
coef = regmatches(x,regexec("^-?\d+[.]?\d+",x,perl=T))[[1]]
paste0(as.numeric(coef)*m, gsub(coef,"",x))
}
- 将
etable(model_fit)
分配给对象k
k = etable(model_fit)
- 现在,使用
f()
更改k$model_fit
中的一个值
k$model_fit[3] <- f(k$model_fit[3])
print(k)
model_fit
Dependent Var.: Sepal.Length
Sepal.Width 49.59. (0.1206)
Petal.Length 0.8292* (0.0970)
Petal.Width -0.3152 (0.1096)
Fixed-Effects: ----------------
Species Yes
_______________ ________________
S.E.: Clustered by: Species
Observations 150
R2 0.86731
Within R2 0.65201
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1