I am using the stargazer
package for regression outputs in R. I have a customized estimation procedure that does not result in a model object but only a vector of coefficients and standard errors. Is there a way I can supply these to stargazer
and get a nicely formatted output table?
Example:
dep.var <- "foo"
regressors <- c("bar", "baz", "xyz")
vec.coeffs <- c(1.2, 2.3, 3.4)
vec.se <- c(0.1, 0.1, 0.3)
Output should look akin to:
===============================================
Dependent variable:
---------------------------
foo
-----------------------------------------------
bar 1.200***
(0.100)
baz 2.300***
(0.100)
xyz 3.400***
(0.300)
-----------------------------------------------
It turns out that if you apply any function over the coefficients (or any other statistic), stargazer automatically recalculates t values with the new coefficients! This means that the significance of my model will depend on the new values and we surely wouldn’t want that.
If you want to use robust standard errors (or clustered), stargazer allows for replacing the default output by supplying a new vector of values to the option se.
a logical value that indicates whether stargazer should calculate the p-values, using the standard normal distribution, if coefficients or standard errors are supplied by the user (from arguments coef and se) or modified by a function (from arguments apply.coef or apply.se ). If FALSE, the package will use model's default values if p is NULL.
The stargazer command produces LaTeX code, HTML code and ASCII text for well-formatted tables that hold regression analysis results from several models side-by-side. It can also output summary statistics and data frame content. stargazer supports a large number model objects from a variety of packages. Please see stargazer models.
Here's one suggestion: the main idea is to make a fake lm
object, and then apply custom coefficients, SEs, etc. to the stargazer
output:
d <- as.data.frame(matrix(rnorm(10 * 4), nc = 4))
names(d) <- c(dep.var, regressors)
f <- as.formula(paste(dep.var, "~ 0 +", paste(regressors, collapse = "+")))
p <- lm(f, d)
stargazer(p, type = "text",
coef = list(vec.coeffs),
se = list(vec.se),
t = list(vec.coeffs / vec.se),
omit.stat = "all")
# =================================
# Dependent variable:
# ---------------------------
# foo
# ---------------------------------
# bar 1.200***
# (0.100)
# baz 2.300***
# (0.100)
# xyz 3.400***
# (0.300)
# =================================
# =================================
# Note: *p<0.1; **p<0.05; ***p<0.01
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With