Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add star_get_lhs_names #16

Open
ChandlerLutz opened this issue Apr 21, 2023 · 0 comments
Open

Add star_get_lhs_names #16

ChandlerLutz opened this issue Apr 21, 2023 · 0 comments

Comments

@ChandlerLutz
Copy link
Owner

star_get_lhs_names <- function(star) {
  ## Assume that the lhs vars are right below the "Dependent variable" line
  dep.var.row <- which(grepl("Dependent variable", x = star))
  col.numbers.row <- star[c(dep.var.row + 3)]
  if (!grepl("\\(1\\)", col.numbers.row)) 
    stop("Error: `star_get_lhs_names` only works on a default stargazer regression latex table")
  
  lhs.vars <- star[c(dep.var.row + 2)] %>%
    gsub("\\\\\\\\", "", x = .) %>%
    sub("\\[-1.8ex\\]", "", x = .) %>%
    strsplit(x = ., "&") %>%
    unlist(.) %>%
    stringr::str_trim() %>%
    .[2:length(.)]

  if (length(lhs.vars) != (star_ncol(star) - 1))
    stop("Error: In `star_get_lhs_names`, the length of the LHS variables is not equal to `1 - star_ncol(star)`. Are you sure you are passing a default stargazer latex regression table to `star_get_lhs_names`")

  return(lhs.vars)

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant