estimatr (version 0.20.0)

starprep: Prepare model fits for stargazer

Description

Prepare model fits for stargazer

Usage

starprep(..., stat = c("std.error", "statistic", "p.value", "ci", "df"),
  se_type = NULL, clusters = NULL, alpha = 0.05)

Arguments

...

a list of lm_robust or lm objects

stat

either "std.error" (the default), "statistic" (the t-statistic), "p.value", "ci", or "df"

se_type

(optional) if any of the objects are lm objects, what standard errors should be used. Must only be one type and will be used for all lm objects passed to starprep. See commarobust for more.

clusters

(optional) if any of the objects are lm objects, what clusters should be used, if clusters should be used. Must only be one vector and will be used for all lm objects passed to starprep. See commarobust for more.

alpha

(optional) if any of the objects are lm objects, what significance level should be used for the p-values or confidence intervals

Value

a list of vectors of extracted statistics for stargazers

Details

Used to help extract statistics from lists of model fits for stargazer. Prefers lm_robust objects, but because stargazer does not work with lm_robust objects, starprep can also take lm objects and calls commarobust to get the preferred, robust statistics.

Examples

Run this code
# NOT RUN {
library(stargazer)

lm1 <- lm(mpg ~ hp, data = mtcars)
lm2 <- lm(mpg ~ hp + wt, data = mtcars)

# Use default "HC2" standard errors
stargazer(lm1, lm2,
          se = starprep(lm1, lm2),
          p = starprep(lm1, lm2, stat = "p.value"),
          omit.stat = "f")
# NB: We remove the F-stat because stargazer only can use original F-stat
# which uses classical SEs

# Use default "CR2" standard errors with clusters
stargazer(lm1, lm2,
          se = starprep(lm1, lm2, clusters = mtcars$carb),
          p = starprep(lm1, lm2, clusters = mtcars$carb, stat = "p.value"),
          omit.stat = "f")

# Can also specify significance levels and different standard errors
stargazer(lm1, lm2,
          ci.custom = starprep(lm1, lm2, se_type = "HC3", alpha = 0.1, stat = "ci"),
          omit.stat = "f")

# }

Run the code above in your browser using DataCamp Workspace