View source: R/star_change_felm_rhs_names.R
star_change_felm_rhs_names | R Documentation |
To change the right-hand-side (rhs) variable names of an felm model. This is often useful when you want display instrumental variable regressions on the same row as ols regressions (see examples).
star_change_felm_rhs_names(felm.model, old, new)
felm.model |
An |
old |
A character vector of the original rhs names |
new |
A character vector of the new rhs names |
the felm
model with the rhs names
library(stargazer); library(lfe)
data(mtcars)
# -- Trivial example -- #
mod <- felm(mpg ~ hp + wt, data = mtcars)
stargazer(mod, type = "text")
# Rename the rhs variables and re-print the stargazer table
mod <- star_change_felm_rhs_names(mod, old = c("hp", "wt"), new = c("x1", "x2"))
stargazer(mod, type = "text")
# -- Combining OLS and IV on a single line using stargazer -- #
mod.ols <- felm(mpg ~ hp, data = mtcars)
mod.iv <- felm(mpg ~ 1 | 0 | (hp ~ cyl), data = mtcars)
# Original stargazer output
# Notice how the two `hp` coefficients are on different lines
stargazer(mod.ols, mod.iv, type = "text", keep.stat = "n")
# In the IV model, replace the RHS var name to just "hp"
mod.iv <- star_change_felm_rhs_names(mod.iv, old = "`hp(fit)`", new = "hp")
# Reprint the stargazer output, notice how the ols and iv rhs variables
# are now in the same row
stargazer(mod.ols, mod.iv, type = "text", keep.stat = "n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.