观星者提取的标签变量

时间:2018-10-26 11:32:50

标签: r label stargazer expss

我正在使用 stargazer 提取乳胶中的一些回归表。 我想知道是否存在一种为所有一次标记标签的方法,而不必每次都通过“ covariate.labels = ... ”重新定义它。 我尝试了库 expss (和 Hmisc ),例如:

library(expss)
library(stargazer)

df <- data.frame(replicate(2,sample(0:1,100,rep=TRUE)))

df = apply_labels(df,
                  X1 =  "label x1",
                  X2 = " label x2")

ols <- lm(formula = X1 ~ X2,
          data= df)

stargazer(ols, 
          # covariate.labels = NULL, 
          title = "Regression Results",
          label = "tab:test",
          out="test.tex")

没有成功... 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

exps use_labels解决方案:

library(expss)
library(stargazer)

df <- data.frame(replicate(2,sample(0:1,100,rep=TRUE)))

df = apply_labels(df,
                  X1 =  "label x1",
                  X2 = " label x2")

ols <- use_labels(df, lm(formula = X1 ~ X2))

res <- stargazer(ols, 
          # covariate.labels = NULL, 
          title = "Regression Results",
          label = "tab:test",
          out="test.tex")

# quick and dirty workaround for removing backticks  
remove_backticks = function(text){
    text = gsub("([^A-z]+)`", "\\1", text, perl = TRUE)
    text = gsub("`([^A-z]+)", "\\1", text, perl = TRUE)
    text = gsub("(^`)|(`$)", "", text, perl = TRUE)
    text
}


res = remove_backticks(res)

writeLines(res, "test.tex")