regTex: Write regression output to LaTeX

Description Usage Arguments Examples

View source: R/regTex.R

Description

A flexible way to create a publication-worthy LaTeX table from a list of regressions. Requires the siunitx LaTeX package for compilation.

Usage

1
2
3
4
5
regTex(regs, vars, file, depvars = NULL, vcov = NULL, intercept = FALSE,
       fixed.effects = NULL, number.format = "%.2f",
       stars = c(0.1, 0.05, 0.01), parentheses = "se", stats = c("N"),
       table.env = FALSE, caption = " ", caption.position = "bottom",
       stand.alone = FALSE, compile = FALSE)

Arguments

regs

A list of model objects (e.g. lm, glm).

vars

A list with variable labels you want to use. The names of each element in the list must match the variable name stored in the model object. For example, in a model with regressors a and b, you can do:

vars <- list(a = c("Label A", ""), b = c("Very long", "label B"))

Variable labels can be split over two lines if they are long, as in the example above.

file

Filename of the resulting ".tex" file. If omitted it will print the LaTeX source on the screen.

depvars

This option can only be omitted if the dependent variable is the same in each model. If the dependent variables differ, the option must be specified as a list of dependent variable labels. Long dependent variable names can continue on any number of new rows. For example:

depvars <- list(c("Long", "label"), "Short label")

If the dependent variable is the same in each model, then the variable label can optionally be given as a scalar character argument, for example:

depvars <- "Dependent variale label"

vcov

A list of variance covariance matrices to use for each model. If omitted it will use the default standard errors given from vcov()

intercept

Whether or not the intercept should be included in the output

fixed.effects

A list specifying which fixed effects were included in the regressions. For example, if there were two regressions with two types of fixed effects, you could have:

fixed.effects <- list(c("Year FE", "Yes", "No"), c("State FE", "No", "Yes"))

The length of the list is the number of fixed effects. The length of each element in the list must by one plus the number of models included. This could also be useful for speficying other types of controls or what subsample of the data you are using.

number.format

Number format as in the sprintf function. Default is two decimal places ("%.2f").

stars

A vector speficying the significance levels to use for stars. The default uses one star for significance at the 10 at the 5 stars.

parentheses

What to include in the parentheses under the coefficients. Can be one of "se" (standard error), "t", (t-statistic) or "p" (p-value). Default is standard error.

stats

The statistics to display at the bottom of the output and in which order you want them. Possible options are "N" (included by default), "R.squared", "adj.R.squared" and "F".

table.env

If TRUE, the output table will be wrapped inside a LaTeX table environment.

caption

If wrapping in a table environment, a caption may be provided here as a character argument. Requires table.env = TRUE

caption.position

If using a caption, use "top" to place it above the table and "bottom" to place it below the table.

stand.alone

Specifies whether or not the LaTeX preamble should be included in the output. This is useful for testing out the function.

compile

If TRUE, automatically compile the pdf document. This implies setting stand.alone = TRUE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Create fake data:
N <- 200
test.df <- data.frame(a = rnorm(N), b = runif(N), c =  rpois(N, 2),
                      d = sample(0:1, N, replace = TRUE))

## Run some regresions:
regs <- list()
regs[[1]] <- lm(a ~ b + c, test.df)
regs[[2]] <- lm(a ~ b + d, test.df)
regs[[3]] <- lm(b ~ c + d, test.df)

## Set up the inputs to the function:
vars <- list(b = c("Variable B"),
             c = c("Variable C"),
             d = c("Long label", "for D"))
depvars <- list("Variable A", "Variable A", c("Long", "label B"))
fe <- list(c("State Fixed Effects", "Yes", "No", "No"),
           c("Year Fixed Effects",  "No",  "No", "Yes"))

## Write LaTeX output:
regTex(regs = regs, vars = vars, depvars = depvars, fixed.effects = fe,
       intercept = TRUE)

walshc/regTex documentation built on May 3, 2019, 11:51 p.m.