A rather hackish idea using texreg
. Use the base model x
and, using the override .*
options of the texreg::*reg
functions, put in the AMEs. When you first create tables for the base models without overiding anything, the AME tables will look similar.
The AMEs should be extended by a preceding NA
for the intercept and a following for the interaction (just to get the AMEs congruent to the coefficients). To ged rid of the GOFs use readLines
identify the corresponding lines and omit them. cat
saves the code into a file in your working directory.
sm <- rbind(NA, summary(m), NA)
library(texreg)
ame <- list(l=x, custom.model.names="AME", override.coef=sm[, 2], digits=3,
override.se=sm[, 3], override.pvalues=sm[, 5], omit.coef="\\(|:",
caption="Average marginal effects")
## html version
ame.html <- do.call("htmlreg", ame)
tmp <- tempfile()
cat(ame.html, sep="\n", file=tmp)
ame.html <- readLines(tmp)
ame.html <- ame.html[-(el(grep("R<sup>2", ame.html)):grep("<tfoot>", ame.html))]
cat(ame.html, sep="\n", file="ame.html")
## latex version
ame.latex <- do.call("texreg", ame)
tmp <- tempfile()
cat(ame.latex, sep="\n", file=tmp)
ame.latex <- readLines(tmp)
ame.latex <- ame.latex[-(el(grep("R\\$\\^2\\$", ame.latex)):grep("multicolumn", ame.latex))]
cat(ame.latex, sep="\n", file="ame.tex")
## console version
ame.screen <- do.call("screenreg", ame)
tmp <- tempfile()
cat(ame.screen, sep="\n", file=tmp)
ame.screen <- readLines(tmp)
ame.screen <- ame.screen[-(grep("---", ame.screen)[2]:(grep("\\=", ame.screen)[2] - 1))]
cat(ame.screen, sep="\n")
Note: I tried to make the grep
s general, but you may need to adjust them according to your model.
Result
(showing console)
=====================
AME
---------------------
cyl 0.038
(0.600)
hp -0.046 **
(0.015)
wt -3.120 ***
(0.661)
=====================
*** p < 0.001; ** p < 0.01; * p < 0.05