5

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)         

-----------------------------------------------
paljenczy
  • 4,779
  • 8
  • 33
  • 46

1 Answers1

6

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
Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48