Why isn't stargazer outputting standard errors and stars in the below table?
How can I get stargazer (or another table package) to present the standard errors in parentheses below the coefficient, and present significance stars next to the coefficient?
As you can see at bottom, right now it only outputs the coefficients.
Just for slight background, because of the nature of the analysis, I need to save each coefficient separately. I cannot save each model as a model object.
For each model I have twelve coefficients, the standard errors, and the p-values. I then feed these values into stargazer with the se=
and p=
commands, but I am clearly making a mistake.
Right now I am using stargazer()
but I would be happy to accept an answer using any R->TeX package (e.g., xtable()
).
set.seed(961)
# Two models, twelve variables each.
# Create empty matrices to store results below
coefs <- matrix(NA, nrow = 12, ncol = 2)
ses <- matrix(NA, nrow = 12, ncol = 2)
p_values <- matrix(NA, nrow = 12, ncol = 2)
colnames(coefs) <- c("Model 1", "Model 2")
rownames(coefs) <- c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12")
colnames(ses) <- c("Model 1", "Model 2")
rownames(ses) <- c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12")
colnames(p_values) <- c("Model 1", "Model 2")
rownames(p_values) <- c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12")
for(i in 1:2){
coefs[, i] <- rnorm(12, 0, 5) # Random coefficients
ses[, i] <- coefs[, i]*seq(0.1, 1.2, by = 0.1) #Define standard error for coef
z <- coefs[, i] / ses[, i] # Calculate Z-score for each coef
p_values[, i] <- 2*pnorm(-abs(z)) # Calculate p-value for each coef
}
stargazer(coefs, se = ses, p = p_values)
===================
Model 1 Model 2
-------------------
V1 -0.500 0.054
V2 7.667 -8.738
V3 0.631 2.266
V4 -4.003 3.759
V5 -4.608 -8.939
V6 -7.241 0.893
V7 6.799 13.984
V8 -5.981 3.577
V9 3.041 10.789
V10 -6.941 -1.109
V11 0.776 -5.073
V12 2.277 8.667
-------------------