Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stargazer - user supplied coefficients and SE

Tags:

r

stargazer

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)         

-----------------------------------------------
like image 379
paljenczy Avatar asked Aug 19 '16 14:08

paljenczy


People also ask

Why does Stargazer automatically recalculate T values with new coefficients?

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.

How to use robust standard errors in Stargazer?

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.

What is p value in Stargazer?

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.

What is the Stargazer command?

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.


1 Answers

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
like image 123
Weihuang Wong Avatar answered Sep 20 '22 12:09

Weihuang Wong