Created
November 4, 2014 15:04
-
-
Save andrewheiss/7942480391f67809bc57 to your computer and use it in GitHub Desktop.
mtable and stargazer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(memisc) | |
library(stargazer) | |
library(pander) | |
lm0 <- lm(sr ~ pop15 + pop75, data = LifeCycleSavings) | |
lm1 <- lm(sr ~ dpi + ddpi, data = LifeCycleSavings) | |
lm2 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings) | |
mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2, summary.stats=c("sigma","R-squared","F","p","N")) | |
pander(mtable123) | |
# ----------------------------------------------------- | |
# Model 1 Model 2 Model 3 | |
# ----------------- ----------- ----------- ----------- | |
# **(Intercept)** 30.628***\ 6.360***\ 28.566***\ | |
# (7.409) (1.252) (7.355) | |
# **pop15** -0.471**\ \ -0.461**\ | |
# (0.147) (0.145) | |
# **pop75** -1.934\ \ -1.691\ | |
# (1.041) (1.084) | |
# **dpi** \ 0.001\ -0.000\ | |
# (0.001) (0.001) | |
# **ddpi** \ 0.529*\ 0.410*\ | |
# (0.210) (0.196) | |
# **sigma** 3.931 4.189 3.803 | |
# **R-squared** 0.262 0.162 0.338 | |
# **F** 8.332 4.528 5.756 | |
# **p** 0.001 0.016 0.001 | |
# **N** 50 50 50 | |
# ----------------------------------------------------- | |
stargazer(lm0, lm1, lm2, type="text", | |
star.cutoffs=c(0.05, 0.01, 0.001), model.names=FALSE, | |
dep.var.labels.include=FALSE, dep.var.caption="", | |
notes=c("Here are some useful notes about the results", | |
"Like stuff about robust standard errors and whatnot")) | |
# =================================================================================== | |
# (1) (2) (3) | |
# ----------------------------------------------------------------------------------- | |
# pop15 -0.471** -0.461** | |
# (0.147) (0.145) | |
# pop75 -1.934 -1.691 | |
# (1.041) (1.084) | |
# dpi 0.001 -0.0003 | |
# (0.001) (0.001) | |
# ddpi 0.529* 0.410* | |
# (0.210) (0.196) | |
# Constant 30.628*** 6.360*** 28.566*** | |
# (7.409) (1.252) (7.355) | |
# ----------------------------------------------------------------------------------- | |
# Observations 50 50 50 | |
# R2 0.262 0.162 0.338 | |
# Adjusted R2 0.230 0.126 0.280 | |
# Residual Std. Error 3.931 (df = 47) 4.189 (df = 47) 3.803 (df = 45) | |
# F Statistic 8.332*** (df = 2; 47) 4.528* (df = 2; 47) 5.756*** (df = 4; 45) | |
# =================================================================================== | |
# Note: *p<0.05; **p<0.01; ***p<0.001 | |
# Here are some useful notes about the results | |
# Like stuff about robust standard errors and whatnot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is that Pandoc's markdown has a limited support for tables -- so that it can be truly compatible with most document formats. E.g. it does not support col/row spanning and borders, that's why Roman and I came up with the workaround of putting two values in a cell with the help of so called "hard breaks" inside of cells. Notes below tables are not supported similarly, only captions can be added.
If we want the Observations/R2 etc to be separated from the other model parameters, it could be returned in a separate table, like it's done for a simple linear model:
And it comes with some minor functions as well:
It seems to me that if you would like to get
stargazer
-like markdown output, then it requires same trade-off (as seen above), and it has to be implemented separately fromstargazer
as it returns ASCII that cannot be (easily) post-processed. But please let me know what features you miss, and I will be happy to try to resolve those.