Builds a regression table based on a set of user-specified models or a single model and a partitioning variable.

prepare_regression_table(
  df,
  dvs,
  idvs,
  feffects = rep("", length(dvs)),
  clusters = rep("", length(dvs)),
  models = rep("auto", length(dvs)),
  byvar = "",
  format = "html"
)

Arguments

df

Data frame containing the data to estimate the models on.

dvs

A character vector containing the variable names for the dependent variable(s).

idvs

A character vector or a a list of character vectors containing the variable names of the independent variables.

feffects

A character vector or a a list of character vectors containing the variable names of the fixed effects.

clusters

A character vector or a a list of character vectors containing the variable names of the cluster variables.

models

A character vector indicating the model types to be estimated ('ols', 'logit', or 'auto')

byvar

A factorial variable to estimate the model on (only possible if only one model is being estimated).

format

A character scalar that is passed on stargazer as type to determine the presentation format ("html", "text", or "latex").

Value

A list containing two items

"models"

A list containing the model results and by values if appropriate

"table"

The output of stargazer containing the table

Details

This is a wrapper function calling the stargazer package. For numeric dependent variables the models are estimated using lm for models without and plm for models with fixed effects. Binary dependent variable models are estimated using glm (with family = binomial(link="logit")). You can override this behavior by specifying the model with the models parameter. Multinomial logit models are not supported. Clustered standard errors are estimated using plm's robust covariance matrix estimators for OLS and cluster.vcov for logit models. Only up to two dimensions are supported for fixed effects and standard error clusters need to be also present as fixed effects. If run with byvar, only levels that have more observations than coefficients are estimated.

Examples

df <- data.frame(year = as.factor(floor(stats::time(datasets::EuStockMarkets))), datasets::EuStockMarkets) dvs = c("DAX", "SMI", "CAC", "FTSE") idvs = list(c("SMI", "CAC", "FTSE"), c("DAX", "CAC", "FTSE"), c("SMI", "DAX", "FTSE"), c("SMI", "CAC", "DAX")) feffects = list("year", "year", "year", "year") clusters = list("year", "year", "year", "year") t <- prepare_regression_table(df, dvs, idvs, feffects, clusters, format = "text") t$table
#> [1] "" #> [2] "=========================================================" #> [3] " Dependent variable: " #> [4] " -----------------------------------" #> [5] " DAX SMI CAC FTSE " #> [6] " (1) (2) (3) (4) " #> [7] "---------------------------------------------------------" #> [8] "SMI 0.447*** -0.095 0.566***" #> [9] " (0.046) (0.088) (0.107) " #> [10] " " #> [11] "DAX 0.864*** 0.664*** -0.188 " #> [12] " (0.169) (0.141) (0.180) " #> [13] " " #> [14] "CAC 0.735*** -0.204 0.188* " #> [15] " (0.111) (0.218) (0.102) " #> [16] " " #> [17] "FTSE -0.124 0.722*** 0.112 " #> [18] " (0.125) (0.060) (0.075) " #> [19] " " #> [20] "---------------------------------------------------------" #> [21] "Estimator ols ols ols ols " #> [22] "Fixed effects year year year year " #> [23] "Std. errors clustered year year year year " #> [24] "Observations 1,860 1,860 1,860 1,860 " #> [25] "R2 0.900 0.885 0.811 0.747 " #> [26] "Adjusted R2 0.900 0.884 0.810 0.746 " #> [27] "=========================================================" #> [28] "Note: *p<0.1; **p<0.05; ***p<0.01"
t <- prepare_regression_table(df, "DAX", c("SMI", "CAC", "FTSE"), byvar="year", format = "text") print(t$table)
#> [1] "" #> [2] "==================================================================================================================================" #> [3] " Dependent variable: " #> [4] " ------------------------------------------------------------------------------------------------------------" #> [5] " DAX " #> [6] " Full Sample 1991 1992 1993 1994 1995 1996 1997 1998 " #> [7] " (1) (2) (3) (4) (5) (6) (7) (8) (9) " #> [8] "----------------------------------------------------------------------------------------------------------------------------------" #> [9] "SMI 0.493*** 0.634*** -0.283*** 0.445*** -0.265*** 0.333*** 0.189*** 0.258*** 0.244*** " #> [10] " (0.015) (0.068) (0.056) (0.021) (0.039) (0.043) (0.020) (0.026) (0.043) " #> [11] " " #> [12] "CAC 0.496*** -0.052 0.952*** 0.516*** 0.721*** 0.304*** 0.577*** 1.019*** 1.182*** " #> [13] " (0.015) (0.045) (0.026) (0.033) (0.052) (0.060) (0.039) (0.075) (0.054) " #> [14] " " #> [15] "FTSE -0.017 0.066 -0.069** 0.134*** -0.085** 0.017 0.389*** 0.195*** -0.378*** " #> [16] " (0.021) (0.046) (0.035) (0.040) (0.039) (0.049) (0.027) (0.045) (0.045) " #> [17] " " #> [18] "Constant -175.946*** 458.772*** 575.676*** -688.784*** 1,623.337*** 567.057*** -803.680*** -1,353.434*** 1,146.634***" #> [19] " (44.666) (72.607) (72.806) (56.941) (65.786) (105.476) (68.069) (110.585) (174.146) " #> [20] " " #> [21] "----------------------------------------------------------------------------------------------------------------------------------" #> [22] "Estimator ols ols ols ols ols ols ols ols ols " #> [23] "Fixed effects None None None None None None None None None " #> [24] "Std. errors clustered No No No No No No No No No " #> [25] "Observations 1,860 131 260 260 260 260 260 260 169 " #> [26] "R2 0.990 0.669 0.850 0.973 0.560 0.720 0.932 0.964 0.978 " #> [27] "Adjusted R2 0.990 0.661 0.848 0.973 0.555 0.717 0.931 0.964 0.978 " #> [28] "==================================================================================================================================" #> [29] "Note: *p<0.1; **p<0.05; ***p<0.01"