star_change_felm_rhs_names: To change the RHS variable names of an felm model

View source: R/star_change_felm_rhs_names.R

star_change_felm_rhs_namesR Documentation

To change the RHS variable names of an felm model

Description

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).

Usage

star_change_felm_rhs_names(felm.model, old, new)

Arguments

felm.model

An felm model from the lfe package

old

A character vector of the original rhs names

new

A character vector of the new rhs names

Value

the felm model with the rhs names

Examples

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")

ChandlerLutz/starpolishr documentation built on April 16, 2023, 8:55 a.m.