Customization of Defaults
RegressionTables.below_decoration
RegressionTables.categorical_equal
RegressionTables.cluster_suffix
RegressionTables.default_align
RegressionTables.default_below_statistic
RegressionTables.default_breaks
RegressionTables.default_confint_level
RegressionTables.default_depvar
RegressionTables.default_digits
RegressionTables.default_drop
RegressionTables.default_extralines
RegressionTables.default_file
RegressionTables.default_fixedeffects
RegressionTables.default_groups
RegressionTables.default_header_align
RegressionTables.default_keep
RegressionTables.default_labels
RegressionTables.default_number_regressions
RegressionTables.default_order
RegressionTables.default_print_clusters
RegressionTables.default_print_control_indicator
RegressionTables.default_print_estimator
RegressionTables.default_print_fe
RegressionTables.default_print_fe_suffix
RegressionTables.default_print_randomeffects
RegressionTables.default_regression_statistics
RegressionTables.default_render
RegressionTables.default_section_order
RegressionTables.default_standardize_coef
RegressionTables.default_stat_below
RegressionTables.default_symbol
RegressionTables.default_transform_labels
RegressionTables.default_use_relabeled_values
RegressionTables.estim_decorator
RegressionTables.fe_suffix
RegressionTables.fe_value
RegressionTables.interaction_combine
RegressionTables.label
RegressionTables.label_distribution
RegressionTables.label_iv
RegressionTables.label_ols
RegressionTables.label_p
RegressionTables.number_regressions_decoration
RegressionTables.random_effect_separator
RegressionTables.wrapper
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_digits
— Functiondefault_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"
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)"
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"
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)"
Default Keyword Arguments
RegressionTables.default_section_order
— Functiondefault_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)
RegressionTables.default_align
— Functiondefault_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
RegressionTables.default_header_align
— Functiondefault_header_align(render::AbstractRenderType)
Defaults to :c
for all render types, possible options are :r, :l, :c This affects the header (all sections up before :coef, see default_section_order
) of each part of the table
RegressionTables.default_depvar
— Functiondefault_depvar(render::AbstractRenderType)
Defaults to true
for all render types, if false
the dependent variable ("Y") is not printed
RegressionTables.default_number_regressions
— Functiondefault_number_regressions(render::AbstractRenderType, rrs)
Defaults to true
if there is more than one regression, if false
the regression number is not printed
RegressionTables.default_print_fe
— Functiondefault_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
RegressionTables.default_groups
— Functiondefault_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.
RegressionTables.default_extralines
— Functiondefault_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.
RegressionTables.default_keep
— Functiondefault_keep(render::AbstractRenderType, rrs)
Defaults to Vector{String}()
, which means all variables are printed. Also see Keep Drop and Order Arguments for more information.
RegressionTables.default_drop
— Functiondefault_drop(render::AbstractRenderType, rrs)
Defaults to Vector{String}()
, which means no variables are dropped. Also see Keep Drop and Order Arguments for more information.
RegressionTables.default_order
— Functiondefault_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.
RegressionTables.default_fixedeffects
— Functiondefault_fixedeffects(render::AbstractRenderType, rrs)
Defaults to Vector{String}()
, which means any fixed effects available are printed.
RegressionTables.default_labels
— Functiondefault_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")
RegressionTables.default_transform_labels
— Functiondefault_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.
RegressionTables.default_below_statistic
— Functiondefault_below_statistic(render::AbstractRenderType)
Defaults to StdError
, which means the standard error is printed below the coefficient. See AbstractUnderStatistic
for more information.
RegressionTables.default_stat_below
— Functiondefault_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)
RegressionTables.default_render
— Functiondefault_render(rrs)
Defaults to AsciiTable()
, any concrete AbstractRenderType
is allowed
RegressionTables.default_file
— Functiondefault_file(render::AbstractRenderType, renderSettings::Tuple{<:AbstractRenderType, String}, rrs)
Defaults to nothing
, which means no file is saved.
RegressionTables.default_print_fe_suffix
— Functiondefault_print_fe_suffix(render::AbstractRenderType)
Whether or not a suffix will be applied to the fixed effects, defaults to true
.
RegressionTables.default_print_control_indicator
— Functiondefault_print_control_indicator(render::AbstractRenderType)
Defaults to true
, which means if the regression has any variables ommitted (due to keep
or drop
), then a line is placed with Controls
and Yes
.
RegressionTables.default_standardize_coef
— Functiondefault_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.
RegressionTables.default_print_estimator
— Functiondefault_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
.
RegressionTables.default_regression_statistics
— Functiondefault_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
.
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]
.
RegressionTables.default_print_randomeffects
— Functiondefault_print_randomeffects(render::AbstractRenderType, rrs)
Defaults to true
, but the section will not be printed if there are not random effects.
RegressionTables.default_print_clusters
— Functiondefault_print_clusters(render::AbstractRenderType, rrs)
Defaults to false
, which means no cluster information is printed.
RegressionTables.default_use_relabeled_values
— Functiondefault_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.
RegressionTables.default_confint_level
— Functiondefault_confint_level(render::AbstractRenderType, rrs)
Defaults to 0.95
, which means the 95% confidence interval is printed below the coefficient.
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_breaks
— Functiondefault_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%.
RegressionTables.default_symbol
— Functiondefault_symbol(render::AbstractRenderType)
The default symbol to use for the p-value. The default is '*'
.
RegressionTables.interaction_combine
— Functioninteraction_combine(render::AbstractRenderType) = " & "
interaction_combine(render::AbstractLatex) = " \$\times\$ "
interaction_combine(render::AbstractHtml) = " × "
Used to separate pieces of InteractedCoefName
and defaults to:
- " & " in the general case
"$ \times $"
in Latex" × "
in HTML
Change this by rerunning the function with the desired default, for example:
RegressionTables.interaction_combine(render::AbstractLatex) = " \& "
RegressionTables.categorical_equal
— Functioncategorical_equal(render::AbstractRenderType)
Used to separate the name and level of CategoricalCoefName
and defaults to ": ".
RegressionTables.random_effect_separator
— Functionrandom_effect_separator(render::AbstractRenderType)
Used to separate the left and right hand side of RandomEffectCoefName
and defaults to " | ".
RegressionTables.estim_decorator
— Functionestim_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
RegressionTables.below_decoration
— Functionbelow_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)"
RegressionTables.number_regressions_decoration
— Functionnumber_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)"
RegressionTables.fe_suffix
— Functionfe_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"
RegressionTables.wrapper
— Functionwrapper(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}$"
RegressionTables.fe_value
— Functionfe_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"
RegressionTables.cluster_suffix
— Functioncluster_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"
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.label
— Functionlabel(render::AbstractRenderType, x::Type{Nobs}) = "N"
label(render::AbstractLatex, x::Type{Nobs}) = "\$N\$"
label(render::AbstractHtml, x::Type{Nobs}) = "<i>N</i>"
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>"
label(render::AbstractRenderType, x::Type{R2McFadden}) = "Pseudo " * label(render, R2)
label(render::AbstractRenderType, x::Type{R2CoxSnell}) = "Cox-Snell " * label(render, R2)
label(render::AbstractRenderType, x::Type{R2Nagelkerke}) = "Nagelkerke " * label(render, R2)
label(render::AbstractRenderType, x::Type{R2Deviance}) = "Deviance " * label(render, R2)
label(render::AbstractRenderType, x::Type{AdjR2}) = "Adjusted " * label(render, R2)
label(render::AbstractRenderType, x::Type{AdjR2McFadden}) = "Pseudo " * label(render, AdjR2)
label(render::AbstractRenderType, x::Type{AdjR2Deviance}) = "Deviance " * label(render, AdjR2)
label(render::AbstractRenderType, x::Type{DOF}) = "Degrees of Freedom"
label(render::AbstractRenderType, x::Type{LogLikelihood}) = "Log Likelihood"
label(render::AbstractRenderType, x::Type{AIC}) = "AIC"
label(render::AbstractRenderType, x::Type{AICC}) = "AICC"
label(render::AbstractRenderType, x::Type{BIC}) = "BIC"
label(render::AbstractRenderType, x::Type{FStat}) = "F"
label(render::AbstractLatex, x::Type{FStat}) = "\$F\$"
label(render::AbstractHtml, x::Type{FStat}) = "<i>F</i>"
label(render::AbstractRenderType, x::Type{FStatPValue}) = label(render, FStat) * "-test " * label_p(render) * " value"
label(render::AbstractRenderType, x::Type{FStatIV}) = "First-stage " * label(render, FStat) * " statistic"
label(render::AbstractRenderType, x::Type{FStatIVPValue}) = "First-stage " * label_p(render) * " value"
label(render::AbstractRenderType, x::Type{R2Within}) = "Within " * label(render, R2)
label(render::AbstractRenderType, x::Type{RegressionType}) = "Estimator"
label(render::AbstractRenderType, x::Type{HasControls}) = "Controls"
label(render::AbstractRenderType, x::Type{RegressionNumbers}) = ""
RegressionTables.label_p
— Functionlabel_p(render::AbstractRenderType) = "p"
label_p(render::AbstractLatex) = "\$p\$"
label_p(render::AbstractHtml) = "<i>p</i>"
RegressionTables.label_ols
— Functionlabel_ols(render::AbstractRenderType) = "OLS"
Also see RegressionType
RegressionTables.label_iv
— Functionlabel_iv(render::AbstractRenderType) = "IV"
Also see RegressionType
RegressionTables.label_distribution
— Functionlabel_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"