Customization of Defaults

Principles

Within most publications, the tables look similar. This package tries to provide easy access to almost any setting so you can "set and forget" while producing tables that you need. For example, suppose you are using Latex and want to use the tabular* environment instead of the default tabular. Thanks to the Julia type system, this is possible, simply run

RegressionTables.tablestart(::RegressionTables.AbstractLatex, align) = "\\begin{tabular*}{\\linewidth}{$(align[1])@{\\extracolsep{\\fill}}$(align[2:end])}"
RegressionTables.tableend(::RegressionTables.AbstractLatex) = "\\end{tabular*}"

These two lines change all AbstractLatex tables.

The Julia type system also allows customization for more individualized tables. For example, you might include some descriptive tables in a paper, but it might make sense to use different rounding for descriptive data (such as making sure floats that are stored as integers are displayed as integers or rounding for large numbers). This needs to happen without changing the rounding in most tables. To do so, you can create a new type and set the display option for that type:

struct LatexDescriptiveTable <: RegressionTables.AbstractLatex end
function Base.repr(::LatexDescriptiveTable, x::Float64; args...)
    if isinteger(x)
        format(Int(x); commas=true)
    else
        precision = x > 1000 ? 1 : 3
        format(x; commas=true, precision)
    end
end

Now, when creating a descriptive table (see RegressionTable for an example), pass render=LatexDescriptiveTable() to use your formatting function.

The rest of this page goes through the defaults, showing what they are and what you might change each to.

Rounding Digits

RegressionTables.default_digitsFunction
default_digits(render::AbstractRenderType, x::AbstractRegressionStatistic)

Default for regression statistics (R2, AIC), defaults to the general setting of 3 digits

Examples

julia> RegressionTables.default_digits(::AbstractRenderType, x::RegressionTables.AbstractRegressionStatistic) = 4;

julia> x = R2(1.234567);

julia> repr(AsciiTable(), x)
"1.2346"

julia> repr(LatexTable(), x)
"1.2346"
source
default_digits(render::AbstractRenderType, x::AbstractUnderStatistic)

Default for under statistics (TStat, StdError), defaults to the general setting of 3 digits

Examples

julia> RegressionTables.default_digits(::RegressionTables.AbstractAscii, x::RegressionTables.AbstractUnderStatistic) = 4;

julia> x = StdError(1.234567);

julia> repr(AsciiTable(), x)
"(1.2346)"

julia> repr(LatexTable(), x) # unchanged since the default_digits was only changed for Ascii
"(1.235)"
source
default_digits(render::AbstractRenderType, x::.CoefValue)

Default for CoefValue, defaults to the general setting of 3 digits

Examples

julia> RegressionTables.default_digits(::AbstractRenderType, x::RegressionTables.CoefValue) = 2

julia> x = RegressionTables.CoefValue(1.234567, 1); # 1 is for the p value

julia> repr(HtmlTable(), x)
"1.23"
source
default_digits(render::AbstractRenderType, x)

The default for for all other values not otherwise specified, defaults to 3 digits

Examples

julia> RegressionTables.default_digits(::AbstractRenderType, x) = 4

julia> x = 1.234567;

julia> y = TStat(1.234567);

julia> repr(LatexTable(), x)
"1.2346"

julia> repr(LatexTable(), y) # Also changes since the default_digits for other types default to this value
"(1.2346)"
source

Default Keyword Arguments

RegressionTables.default_section_orderFunction
default_section_order(render::AbstractRenderType)

Default section order for the table, defaults to [:groups, :depvar, :number_regressions, :break, :coef, :break, :fe, :break, :randomeffects, :break, :clusters, :break, :regtype, :break, :controls, :break, :stats, :extralines]

:break is a special keyword that adds a line break between sections (e.g. between \midrule in Latex)

source
RegressionTables.default_alignFunction
default_align(render::AbstractRenderType)

Defaults to :r for all render types, possible options are :r, :l, :c This affects each part of the table after the header and the leftmost column always has the :l alignment

source
RegressionTables.default_print_feFunction
default_print_fe(render::AbstractRenderType, rrs)

Defaults to true, but the section will not be printed if there are not fixed effects. If false the fixed effects are not printed

source
RegressionTables.default_groupsFunction
default_groups(render::AbstractRenderType, rrs)

Defaults to nothing, groups are printed above the dependent variable Setting a default should also use rrs (the regression results) since that determines the number of columns in the table.

source
RegressionTables.default_extralinesFunction
default_extralines(render::AbstractRenderType, rrs)

Defaults to nothing, extra lines are printed at the end of the table. Setting a default should also use rrs (the regression results) since that determines the number of columns in the table.

source
RegressionTables.default_orderFunction
default_order(render::AbstractRenderType, rrs)

Defaults to Vector{String}(), which means the order is not changed. Also see Keep Drop and Order Arguments for more information.

In settings where the primary variables of interest are static throughout the tests, it can help to set default_order to a regex that includes that variable. For example, if the primary variables are interactions, then

RegressionTables.default_order(::AbstractRenderType, rrs) = [r" & "]

will prioritize the interactions in the table.

source
RegressionTables.default_labelsFunction
default_labels(render::AbstractRenderType, rrs)

Defaults to Dict{String, String}(), which means no coefficients are changed. If you have a master dictionary of variables to change, it can help to set default_labels to that dictionary. It is also possible to set default_labels for each table type, allowing for labels to escape special characters in Latex.

Examples

RegressionTables.default_labels(render::AbstractRenderType, rrs) = Dict("first" => "New First", "second" => "X > Y")
RegressionTables.default_labels(render::RegressionTables.AbstractLatex, rrs) = Dict("first" => "New First", "second" => "X $>$ Y")
source
RegressionTables.default_transform_labelsFunction
default_transform_labels(render::AbstractRenderType, rrs) = Dict{String, String}()
default_transform_labels(render::AbstractLatex, rrs) = :latex

transform_labels apply a replace function to the coefficients, dependent variables and fixed effects. The default for AbstractLatex is used to escape special characters in Latex.

source
RegressionTables.default_stat_belowFunction
default_stat_below(render::AbstractRenderType)

Defaults to true, which means the standard error (or t-stat) is printed below the coefficient. If false, the standard error is printed to the right of the coefficient (in the same column)

source
RegressionTables.default_fileFunction
default_file(render::AbstractRenderType, renderSettings::Tuple{<:AbstractRenderType, String}, rrs)

Defaults to nothing, which means no file is saved.

source
RegressionTables.default_standardize_coefFunction
default_standardize_coef(render::AbstractRenderType, rrs)

Defaults to false. Standardizing the coefficient divides the coefficient by its standard deviation and multiplies it by the standard deviation of the dependent variable. It is only possible for models that store the matrix, such as those in GLM.jl and MixedModels.jl. If it is not possible, the coefficients will not change.

source
RegressionTables.default_print_estimatorFunction
default_print_estimator(render::AbstractRenderType, rrs)

Defaults to true if more than one type of estimator is used. For example, if all regressions are "OLS", then this section will default to false, while if one regression is "OLS" and another is "IV", then this section will default to true.

source
RegressionTables.default_regression_statisticsFunction
default_regression_statistics(rr::RegressionModel)

Returns a vector of AbstractRegressionStatistic objects. This is used to display the statistics in the table. This is customizable for each RegressionModel type. The default is to return a vector of Nobs and R2.

source
default_regression_statistics(render::AbstractRenderType, rrs)

Defaults to a union of the default_regression_statistics for each regression. For example, an "OLS" regression (with no fixed effects) will default to including [Nobs, R2], and a Probit regression will include [Nobs, PseudoR2], so the default will be [Nobs, R2, PseudoR2].

source
RegressionTables.default_use_relabeled_valuesFunction
default_use_relabeled_values(render::AbstractRenderType, rrs) = true

Defaults to true, which means the keep, drop and order arguments will use the relabeled values instead of the original values.

source

Other Defaults

While the user can adjust almost any part of this package (see How Types are Displayed), here are the remaining major defaults that are settable.

RegressionTables.default_breaksFunction
default_breaks(render::AbstractRenderType)

The default cutoffs for the number of "*" (or other value set by default_symbol). The default is [0.001, 0.01, 0.05], corresponding to a p-value of 0.1%, 1%, and 5%.

source
RegressionTables.interaction_combineFunction
interaction_combine(render::AbstractRenderType) = " & "
interaction_combine(render::AbstractLatex) = " \$\times\$ "
interaction_combine(render::AbstractHtml) = " &times; "

Used to separate pieces of InteractedCoefName and defaults to:

  • " & " in the general case
  • "$ \times $" in Latex
  • " &times; " in HTML

Change this by rerunning the function with the desired default, for example:

RegressionTables.interaction_combine(render::AbstractLatex) = " \& "
source
RegressionTables.estim_decoratorFunction
estim_decorator(render::AbstractRenderType, s, pval; breaks=default_breaks(render), sym=default_symbol(render))

Decorates a value with a symbol based on p-value. In many journals, the symbol is a * and the p-value has three cutoffs, either 0.001, 0.01, and 0.05 or 0.01, 0.05, and 0.10.

It is possible to wrap the symbols in an additional element, for example, in Latex it is common to wrap the symbol as a superscript. To do so in all tables, run

RegressionTables.wrapper(::AbstractLatex, deco) = "\$^{$deco}\$"

It is also possible to change the cutoffs or symbols. To change the cutoffs, run

RegressionTables.default_breaks(::AbstractLatex) = [0.01, 0.05, 0.10] # make sure these are in order

And to change the cutoffs run

RegressionTables.default_symbol(::AbstractLatex) = "x" # or whatever you want
source
RegressionTables.below_decorationFunction
below_decoration(render::AbstractRenderType, s)

Used to decorate a string below the main string and defaults to "($s)". Change this by running:

RegressionTables.below_decoration(render::AbstractRenderType, s) = "($s)"
source
RegressionTables.number_regressions_decorationFunction
number_regressions_decoration(render::AbstractRenderType, s)

Used to decorate the regression number (e.g., "(1)") and defaults to "($s)". Change this by running:

RegressionTables.number_regressions_decoration(render::AbstractRenderType, s) = "($s)"
source
RegressionTables.fe_suffixFunction
fe_suffix(render::AbstractRenderType)

Used to add a suffix to the fixed effects and defaults to " Fixed Effects". Change this by running:

RegressionTables.fe_suffix(render::AbstractRenderType) = " Fixed Effects"
source
RegressionTables.wrapperFunction
wrapper(render::AbstractRenderType, s)

Used to wrap a string, particularly for estim_decorator and defaults to s (i.e., no wrapper). For example, to wrap the stars in Latex, run:

RegressionTables.wrapper(::AbstractLatex, deco) = "$^{$deco}$"
source
RegressionTables.fe_valueFunction
fe_value(render::AbstractRenderType, v)

Determines how to render a yes/no value for fixed effects, defaults to "Yes" and "". Can be changed by running:

RegressionTables.fe_value(render::AbstractRenderType, v) = v ? "Yes" : "No"
source
RegressionTables.cluster_suffixFunction
cluster_suffix(render::AbstractRenderType)

Used to add a suffix to the clustering and defaults to " Clustering". Change this by running:

RegressionTables.cluster_suffix(render::AbstractRenderType) = " Clustering"
source

Labels

Labels are customizable by running the function that defines them. This makes it possible to change the labels once and then not worry about them on subsequent tables. To change a label, run:

RegressionTables.label(render::AbstractRenderType, ::Type{Nobs}) = "Obs."

Labels use the Julia type system, so it is possible to create different labels depending on the table type. This is done by default for cases such as Nobs and R2, where the defaults for Latex and HTML are different. In such cases, it is necessary to set the label for all types that are used:

RegressionTables.label(render::AbstractLatex, ::Type{Nobs}) = "Obs."
RegressionTables.label(render::AbstractHtml, ::Type{Nobs}) = "Obs."

Some labels (notably the R2 group), call another label function. For example:

label(render::AbstractRenderType, ::Type{AdjR2}) = "Adjusted " * label(render, R2)

Ths means that the label for AdjR2 relies on the label for R2. This also means that changing the label for R2 will change the labels for all other R2 types.

RegressionTables.labelFunction
label(render::AbstractRenderType, x::Type{Nobs}) = "N"
label(render::AbstractLatex, x::Type{Nobs}) = "\$N\$"
label(render::AbstractHtml, x::Type{Nobs}) = "<i>N</i>"
source
label(render::AbstractRenderType, x::Type{R2}) = "R2"
label(render::AbstractLatex, x::Type{R2}) = "\$R^2\$"
label(render::AbstractHtml, x::Type{R2}) = "<i>R</i><sup>2</sup>"
source
label(render::AbstractRenderType, x::Type{R2McFadden}) = "Pseudo " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{R2CoxSnell}) = "Cox-Snell " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{R2Nagelkerke}) = "Nagelkerke " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{R2Deviance}) = "Deviance " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{AdjR2}) = "Adjusted " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{AdjR2McFadden}) = "Pseudo " * label(render, AdjR2)
source
label(render::AbstractRenderType, x::Type{AdjR2Deviance}) = "Deviance " * label(render, AdjR2)
source
label(render::AbstractRenderType, x::Type{DOF}) = "Degrees of Freedom"
source
label(render::AbstractRenderType, x::Type{LogLikelihood}) = "Log Likelihood"
source
label(render::AbstractRenderType, x::Type{AIC}) = "AIC"
source
label(render::AbstractRenderType, x::Type{AICC}) = "AICC"
source
label(render::AbstractRenderType, x::Type{BIC}) = "BIC"
source
label(render::AbstractRenderType, x::Type{FStat}) = "F"
label(render::AbstractLatex, x::Type{FStat}) = "\$F\$"
label(render::AbstractHtml, x::Type{FStat}) = "<i>F</i>"
source
label(render::AbstractRenderType, x::Type{FStatPValue}) = label(render, FStat) * "-test " * label_p(render) * " value"
source
label(render::AbstractRenderType, x::Type{FStatIV}) = "First-stage " * label(render, FStat) * " statistic"
source
label(render::AbstractRenderType, x::Type{FStatIVPValue}) = "First-stage " * label_p(render) * " value"
source
label(render::AbstractRenderType, x::Type{R2Within}) = "Within " * label(render, R2)
source
label(render::AbstractRenderType, x::Type{RegressionType}) = "Estimator"
source
label(render::AbstractRenderType, x::Type{HasControls}) = "Controls"
source
label(render::AbstractRenderType, x::Type{RegressionNumbers}) = ""
source
RegressionTables.label_pFunction
label_p(render::AbstractRenderType) = "p"
label_p(render::AbstractLatex) = "\$p\$"
label_p(render::AbstractHtml) = "<i>p</i>"
source
RegressionTables.label_distributionFunction
label_distribution(render::AbstractRenderType, d::D) where {D <: UnivariateDistribution} = string(Base.typename(D).wrapper)
label_distribution(render::AbstractRenderType, d::NegativeBinomial) = "Negative Binomial"
label_distribution(render::AbstractRenderType, d::InverseGaussian) = "Inverse Gaussian"

How to label non-linear regressions and defaults to the name of the distribution. For example, Probit will be "Probit". Two exceptions are given for NegativeBinomial and InverseGaussian, which are "Negative Binomial" and "Inverse Gaussian", respectively. This can be changed for a specific distribution by running:

RegressionTables.label_distribution(render::AbstractRenderType, d::Poisson) = "Poisson"
source