Estimations table (export the results of multiples estimations to a DF or to Latex)
Aggregates the results of multiple estimations and displays them in the form of either a Latex table or a data.frame
. Note that you will need the booktabs
package for the Latex table to render properly.
etable( ..., vcov = NULL, stage = 2, agg = NULL, se = NULL, ssc = NULL, cluster = NULL, .vcov, .vcov_args = NULL, digits = 4, digits.stats = 5, tex, fitstat, title, coefstat = "se", ci = 0.95, se.row = NULL, se.below = NULL, keep, drop, order, dict, file, replace = FALSE, convergence, signifCode, label, float, headers = list("auto"), fixef_sizes = FALSE, fixef_sizes.simplify = TRUE, keepFactors = TRUE, family, powerBelow = -5, interaction.combine = NULL, interaction.order = NULL, i.equal = NULL, depvar = TRUE, style.tex = NULL, style.df = NULL, notes = NULL, group = NULL, extraline = NULL, fixef.group = NULL, placement = "htbp", drop.section = NULL, poly_dict = c("", " square", " cube"), postprocess.tex = NULL, postprocess.df = NULL, fit_format = "__var__", coef.just = NULL, meta = NULL, meta.time = NULL, meta.author = NULL, meta.sys = NULL, meta.call = NULL, meta.comment = NULL ) setFixest_etable( digits = 4, digits.stats = 5, fitstat, coefstat = c("se", "tstat", "confint"), ci = 0.95, se.below = TRUE, keep, drop, order, dict, signifCode, float, fixef_sizes = FALSE, fixef_sizes.simplify = TRUE, family, powerBelow = -5, interaction.order = NULL, depvar, style.tex = NULL, style.df = NULL, notes = NULL, group = NULL, extraline = NULL, fixef.group = NULL, placement = "htbp", drop.section = NULL, postprocess.tex = NULL, postprocess.df = NULL, fit_format = "__var__", meta.time = NULL, meta.author = NULL, meta.sys = NULL, meta.call = NULL, meta.comment = NULL, reset = FALSE, save = FALSE ) getFixest_etable() esttable( ..., vcov = NULL, stage = 2, agg = NULL, se = NULL, ssc = NULL, cluster = NULL, .vcov, .vcov_args = NULL, digits = 4, digits.stats = 5, fitstat, coefstat = "se", ci = 0.95, se.row = NULL, se.below = NULL, keep, drop, order, dict, file, replace = FALSE, convergence, signifCode, headers = list("auto"), fixef_sizes = FALSE, fixef_sizes.simplify = TRUE, keepFactors = TRUE, family, powerBelow = -5, interaction.combine = NULL, interaction.order = NULL, i.equal = NULL, depvar = TRUE, style.df = NULL, group = NULL, extraline = NULL, fixef.group = NULL, drop.section = NULL, poly_dict = c("", " square", " cube"), postprocess.df = NULL, fit_format = "__var__", coef.just = NULL ) esttex( ..., vcov = NULL, stage = 2, agg = NULL, se = NULL, ssc = NULL, cluster = NULL, .vcov, .vcov_args = NULL, digits = 4, digits.stats = 5, fitstat, title, coefstat = "se", ci = 0.95, se.row = NULL, se.below = NULL, keep, drop, order, dict, file, replace = FALSE, convergence, signifCode, label, float, headers = list("auto"), fixef_sizes = FALSE, fixef_sizes.simplify = TRUE, keepFactors = TRUE, family, powerBelow = -5, interaction.combine = NULL, interaction.order = NULL, i.equal = NULL, depvar = TRUE, style.tex = NULL, notes = NULL, group = NULL, extraline = NULL, fixef.group = NULL, placement = "htbp", drop.section = NULL, poly_dict = c("", " square", " cube"), postprocess.tex = NULL, fit_format = "__var__", meta = NULL, meta.time = NULL, meta.author = NULL, meta.sys = NULL, meta.call = NULL, meta.comment = NULL )
... |
Used to capture different |
vcov |
Versatile argument to specify the VCOV. In general, it is either a character scalar equal to a VCOV type, either a formula of the form: |
stage |
Can be equal to |
agg |
A character scalar describing the variable names to be aggregated, it is pattern-based. All variables that match the pattern will be aggregated. It must be of the form |
se |
Character scalar. Which kind of standard error should be computed: “standard”, “hetero”, “cluster”, “twoway”, “threeway” or “fourway”? By default if there are clusters in the estimation: |
ssc |
An object of class |
cluster |
Tells how to cluster the standard-errors (if clustering is requested). Can be either a list of vectors, a character vector of variable names, a formula or an integer vector. Assume we want to perform 2-way clustering over |
.vcov |
A function to be used to compute the standard-errors of each fixest object. You can pass extra arguments to this function using the argument |
.vcov_args |
A list containing arguments to be passed to the function |
digits |
Integer or character scalar. Default is 4 and represents the number of significant digits to be displayed for the coefficients and standard-errors. To apply rounding instead of significance use, e.g., |
digits.stats |
Integer or character scalar. Default is 5 and represents the number of significant digits to be displayed for the fit statistics. To apply rounding instead of significance use, e.g., |
tex |
Logical: whether the results should be a data.frame or a Latex table. By default, this argument is |
fitstat |
A character vector or a one sided formula (both with only lowercase letters). A vector listing which fit statistics to display. The valid types are 'n', 'll', 'aic', 'bic' and r2 types like 'r2', 'pr2', 'war2', etc (see all valid types in |
title |
(Tex only.) Character scalar. The title of the Latex table. |
coefstat |
One of |
ci |
Level of the confidence interval, defaults to |
se.row |
Logical scalar, default is |
se.below |
Logical or |
keep |
Character vector. This element is used to display only a subset of variables. This should be a vector of regular expressions (see |
drop |
Character vector. This element is used if some variables are not to be displayed. This should be a vector of regular expressions (see |
order |
Character vector. This element is used if the user wants the variables to be ordered in a certain way. This should be a vector of regular expressions (see |
dict |
A named character vector or a logical scalar. It changes the original variable names to the ones contained in the |
file |
A character scalar. If provided, the Latex (or data frame) table will be saved in a file whose path is |
replace |
Logical, default is |
convergence |
Logical, default is missing. Should the convergence state of the algorithm be displayed? By default, convergence information is displayed if at least one model did not converge. |
signifCode |
Named numeric vector, used to provide the significance codes with respect to the p-value of the coefficients. Default is |
label |
(Tex only.) Character scalar. The label of the Latex table. |
float |
(Tex only.) Logical. By default, if the argument |
headers |
Character vector or list. Adds one or more header lines in the table. A header line can be represented by a character vector or a named list of numbers where the names are the cell values and the numbers are the span. Example: |
fixef_sizes |
(Tex only.) Logical, default is |
fixef_sizes.simplify |
Logical, default is |
keepFactors |
Logical, default is |
family |
Logical, default is missing. Whether to display the families of the models. By default this line is displayed when at least two models are from different families. |
powerBelow |
(Tex only.) Integer, default is -5. A coefficient whose value is below |
interaction.combine |
Character scalar, defaults to |
interaction.order |
Character vector of regular expressions. Only affects variables that are interacted like x1 and x2 in |
i.equal |
Character scalar, defaults to |
depvar |
Logical, default is |
style.tex |
An object created by the function |
style.df |
An object created by the function |
notes |
(Tex only.) Character vector. If provided, a |
group |
A list. The list elements should be vectors of regular expressions. For each elements of this list: A new line in the table is created, all variables that are matched by the regular expressions are discarded (same effect as the argument |
extraline |
A vector, a list or a one sided formula. The list elements should be either a vector representing the value of each cell, a list of the form |
fixef.group |
Logical scalar or list (default is |
placement |
(Tex only.) Character string giving the position of the float in Latex. Default is "htbp". It must consist of only the characters 'h', 't', 'b', 'p', 'H' and '!'. Reminder: h: here; t: top; b: bottom; p: float page; H: definitely here; !: prevents Latex to look for other positions. Note that it can be equal to the empty string (and you'll get the default placement). |
drop.section |
Character vector which can be of length 0 (i.e. equal to |
poly_dict |
Character vector, default is |
postprocess.tex |
A function that will postprocess the character vector defining the latex table. Only when |
postprocess.df |
A function that will postprocess.tex the resulting data.frame. Only when |
fit_format |
Character scalar, default is |
coef.just |
(DF only.) Either |
meta |
(Tex only.) A one-sided formula that shall contain the following elements: date or time, sys, author, comment and call. Default is |
meta.time |
(Tex only.) Either a logical scalar (default is |
meta.author |
(Tex only.) A logical scalar (default is |
meta.sys |
(Tex only.) A logical scalar, default is |
meta.call |
(Tex only.) Logical scalar, default is |
meta.comment |
(Tex only.) A character vector containing free-form comments to be inserted right before the table. |
reset |
( |
save |
Either a logical or equal to |
The function esttex
is equivalent to the function etable
with argument tex = TRUE
.
The function esttable
is equivalent to the function etable
with argument tex = FALSE
.
To display the table, you will need the Latex package booktabs
which contains the \toprule
, \midrule
and \bottomrule
commands.
You can permanently change the way your table looks in Latex by using setFixest_etable
. The following vignette gives an example as well as illustrates how to use the style
and postprocessing functions: Exporting estimation tables.
When the argument postprocessing.tex
is not missing, two additional tags will be included in the character vector returned by etable
: "%start:tab\n"
and "%end:tab\n"
. These can be used to identify the start and end of the tabular and are useful to insert code within the table
environment.
If tex = TRUE
, the lines composing the Latex table are returned invisibly while the table is directly prompted on the console.
If tex = FALSE
, the data.frame is directly returned. If the argument file
is not missing, the data.frame
is printed and returned invisibly.
esttable
: Exports the results of multiple fixest
estimations in a Latex table.
esttex
: Exports the results of multiple fixest
estimations in a Latex table.
digits
handle the number of decimals displayed?The default display of decimals is the outcome of an algorithm. Let's take the example of digits = 3
which "kind of" requires 3 significant digits to be displayed.
For numbers greater than 1 (in absolute terms), their integral part is always displayed and the number of decimals shown is equal to digits
minus the number of digits in the integral part. This means that 12.345
will be displayed as 12.3
. If the number of decimals should be 0, then a single decimal is displayed to suggest that the number is not whole. This means that 1234.56
will be displayed as 1234.5
. Note that if the number is whole, no decimals are shown.
For numbers lower than 1 (in absolute terms), the number of decimals displayed is equal to digits
except if there are only 0s in which case the first significant digit is shown. This means that 0.01234
will be displayed as 0.012
(first rule), and that 0.000123 will be displayed as 0.0001
(second rule).
The arguments keep
, drop
and order
use regular expressions. If you are not aware of regular expressions, I urge you to learn it, since it is an extremely powerful way to manipulate character strings (and it exists across most programming languages).
For example drop = "Wind" would drop any variable whose name contains "Wind". Note that variables such as "Temp:Wind" or "StrongWind" do contain "Wind", so would be dropped. To drop only the variable named "Wind", you need to use drop = "^Wind$"
(with "^" meaning beginning, resp. "$" meaning end, of the string => this is the language of regular expressions).
Although you can combine several regular expressions in a single character string using pipes, drop
also accepts a vector of regular expressions.
You can use the special character "!" (exclamation mark) to reverse the effect of the regular expression (this feature is specific to this function). For example drop = "!Wind"
would drop any variable that does not contain "Wind".
You can use the special character "%" (percentage) to make reference to the original variable name instead of the aliased name. For example, you have a variable named "Month6"
, and use a dictionary dict = c(Month6="June")
. Thus the variable will be displayed as "June"
. If you want to delete that variable, you can use either drop="June"
, or drop="%Month6"
(which makes reference to its original name).
The argument order
takes in a vector of regular expressions, the order will follow the elements of this vector. The vector gives a list of priorities, on the left the elements with highest priority. For example, order = c("Wind", "!Inter", "!Temp") would give highest priorities to the variables containing "Wind" (which would then appear first), second highest priority is the variables not containing "Inter", last, with lowest priority, the variables not containing "Temp". If you had the following variables: (Intercept), Temp:Wind, Wind, Temp you would end up with the following order: Wind, Temp:Wind, Temp, (Intercept).
extraline
The argument extraline
adds well... extra lines to the table. It accepts either a list, or a one-sided formula.
For each line, you can define the values taken by each cell using 4 different ways: a) a vector, b) a list, c) a function, and d) a formula.
If a vector, it should represent the values taken by each cell. Note that if the length of the vector is smaller than the number of models, its values are recycled across models, but the length of the vector is required to be a divisor of the number of models.
If a list, it should be of the form list("item1" = #item1, "item2" = #item2, etc)
. For example list("A"=2, "B"=3)
leads to c("A", "A", "B", "B", "B")
. Note that if the number of items is 1, you don't need to add = 1
. For example list("A"=2, "B")
is valid and leads to c("A", "A", "B"
. As for the vector the values are recycled if necessary.
If a function, it will be applied to each model and should return a scalar (NA
values returned are accepted).
If a formula, it must be one-sided and the elements in the formula must represent either extraline
macros, either fit statistics (i.e. valid types of the function fitstat
). One new line will be added for each element of the formula. To register extraline
macros, you must first register them in extraline_register
.
Finally, you can combine as many lines as wished by nesting them in a list. The names of the nesting list are the row titles (values in the leftmost cell). For example extraline = list(~r2, Controls = TRUE, Group = list("A"=2, "B"))
will add three lines, the titles of which are "R2", "Controls" and "Group".
The arguments group
, extraline
and fixef.group
allow to add customized lines in the table. They can be defined via a list where the list name will be the row name. By default, the placement of the extra line is right after the coefficients (except for fixef.group
, covered in the last paragraph). For instance, group = list("Controls" = "x[[:digit:]]")
will create a line right after the coefficients telling which models contain the control variables.
But the placement can be customized. The previous example (of the controls) will be used for illustration (the mechanism for extraline
and fixef.group
is identical).
The row names accept 2 special characters at the very start. The first character tells in which section the line should appear: it can be equal to "^"
, "-"
, or "_"
, meaning respectively the coefficients, the fixed-effects and the statistics section (which typically appear at the top, mid and bottom of the table). The second one governs the placement of the new line within the section: it can be equal to "^"
, meaning first line, or "_"
, meaning last line.
Let's have some examples. Using the previous example, writing "_^Controls"
would place the new line at the top of the statistics section. Writing "-_Controls"
places it as the last row of the fixed-effects section; "^^Controls"
at the top row of the coefficients section; etc...
The second character is optional, the default placement being in the bottom. This means that "_Controls"
would place it at the bottom of the statistics section.
The placement in fixef.group
is defined similarly, only the default placement is different. Its default placement is at the top of the fixed-effects section.
By default on all instances (with the notable exception of the elements of style.tex
) special Latex characters are escaped. This means that title="Exports in million $."
will be exported as "Exports in million \$.": the dollar sign will be escaped. This is true for the following characters: &, $, %, _, ^ and #.
Note, importantly, that equations are NOT escaped. This means that title="Functional form $a_i \times x^b$, variation in %."
will be displayed as: "Functional form $a_i \times x^b$, variation in \%."
: only the last percentage will be escaped.
If for some reason you don't want the escaping to take place, the arguments headers
and extraline
are the only ones allowing that. To disable escaping, add the special token ":tex:" in the row names. Example: in headers=list(":tex:Row title"="weird & & %\n tex stuff\\")
, the elements will be displayed verbatim. Of course, since it can easily ruin your table, it is only recommended to super users.
Laurent Berge
See also the main estimation functions femlm
, feols
or feglm
. Use summary.fixest
to see the results with the appropriate standard-errors, fixef.fixest
to extract the fixed-effects coefficients.
aq = airquality est1 = feols(Ozone ~ i(Month) / Wind + Temp, data = aq) est2 = feols(Ozone ~ i(Month, Wind) + Temp | Month, data = aq) # Displaying the two results in a single table etable(est1, est2) # keep/drop: keeping only interactions etable(est1, est2, keep = " x ") # or using drop (see regexp help): etable(est1, est2, drop = "^(Month|Temp|\\()") # keep/drop: dropping interactions etable(est1, est2, drop = " x ") # or using keep ("!" reverses the effect): etable(est1, est2, keep = "! x ") # order: Wind variable first, intercept last (note the "!" to reverse the effect) etable(est1, est2, order = c("Wind", "!Inter")) # Month, then interactions, then the rest etable(est1, est2, order = c("^Month", " x ")) # # dict # # You can rename variables with dict = c(var1 = alias1, var2 = alias2, etc) # You can also rename values taken by factors. # Here's a full example: dict = c(Temp = "Temperature", "Month::5"="May", "6"="Jun") etable(est1, est2, dict = dict) # Note the difference of treatment between Jun and May # Assume the following dictionary: dict = c("Month::5"="May", "Month::6"="Jun", "Month::7"="Jul", "Month::8"="Aug", "Month::9"="Sep") # We would like to keep only the Months, but now the names are all changed... # How to do? # We can use the special character '%' to make reference to the original names. etable(est1, est2, dict = dict, keep = "%Month") # # signifCode # etable(est1, est2, signifCode = c(" A"=0.01, " B"=0.05, " C"=0.1, " D"=0.15, " F"=1)) # # Using the argument style to customize Latex exports # # If you don't like the default layout of the table, no worries! # You can modify many parameters with the argument style # To drop the headers before each section, use: # Note that a space adds an extra line style_noHeaders = style.tex(var.title = "", fixef.title = "", stats.title = " ") etable(est1, est2, dict = dict, tex = TRUE, style.tex = style_noHeaders) # To change the lines of the table + dropping the table footer style_lines = style.tex(line.top = "\\toprule", line.bottom = "\\bottomrule", tablefoot = FALSE) etable(est1, est2, dict = dict, tex = TRUE, style.tex = style_lines) # Or you have the predefined type "aer" etable(est1, est2, dict = dict, tex = TRUE, style.tex = style.tex("aer")) # # Group and extraline # # Sometimes it's useful to group control variables into a single line # You can achieve that with the group argument setFixest_fml(..ctrl = ~ poly(Wind, 2) + poly(Temp, 2)) est_c0 = feols(Ozone ~ Solar.R, data = aq) est_c1 = feols(Ozone ~ Solar.R + ..ctrl, data = aq) est_c2 = feols(Ozone ~ Solar.R + Solar.R^2 + ..ctrl, data = aq) etable(est_c0, est_c1, est_c2, group = list(Controls = "poly")) # 'group' here does the same as drop = "poly", but adds an extra line # with TRUE/FALSE where the variables were found # 'extraline' adds an extra line, where you can add the value for each model est_all = feols(Ozone ~ Solar.R + Temp + Wind, data = aq) est_sub1 = feols(Ozone ~ Solar.R + Temp + Wind, data = aq[aq$Month %in% 5:6, ]) est_sub2 = feols(Ozone ~ Solar.R + Temp + Wind, data = aq[aq$Month %in% 7:8, ]) est_sub3 = feols(Ozone ~ Solar.R + Temp + Wind, data = aq[aq$Month == 9, ]) etable(est_all, est_sub1, est_sub2, est_sub3, extraline = list("Sub-sample" = c("All", "May-June", "Jul.-Aug.", "Sept."))) # You can monitor the placement of the new lines with two special characters # at the beginning of the row name. # 1) "^", "-" or "_" which mean the coefficients, the fixed-effects or the # statistics section. # 2) "^" or "_" which mean first or last line of the section # # Ex: starting with "_^" will place the line at the top of the stat. section # starting with "-_" will place the line at the bottom of the FEs section # etc. # # You can use a single character which will represent the section, # the line would then appear at the bottom of the section. # Examples etable(est_c0, est_c1, est_c2, group = list("_Controls" = "poly")) etable(est_all, est_sub1, est_sub2, est_sub3, extraline = list("^^Sub-sample" = c("All", "May-June", "Jul.-Aug.", "Sept."))) # # headers # # You can add header lines with 'headers' # These lines will appear at the top of the table # first, 3 estimations est_header = feols(c(Ozone, Solar.R, Wind) ~ poly(Temp, 2), aq) # header => vector: adds a line w/t title etable(est_header, headers = c("A", "A", "B")) # header => list: identical way to do the previous header # The form is: list(item1 = #item1, item2 = #item2, etc) etable(est_header, headers = list("A" = 2, "B" = 1)) # Adding a title + # when an element is to be repeated only once, you can avoid the "= 1": etable(est_header, headers = list(Group = list("A" = 2, "B"))) # To change the placement, add as first character: # - "^" => top # - "-" => mid (default) # - "_" => bottom # Note that "mid" and "top" are only distinguished when tex = TRUE # Placing the new header line at the bottom etable(est_header, headers = list("_Group" = c("A", "A", "B"), "^Currency" = list("US $" = 2, "CA $" = 1))) # In Latex, you can add "grouped underlines" (cmidrule from the booktabs package) # by adding ":_:" in the title: etable(est_header, tex = TRUE, headers = list("^:_:Group" = c("A", "A", "B"))) # # fixef.group # # You can group the fixed-effects line with fixef.group est_0fe = feols(Ozone ~ Solar.R + Temp + Wind, aq) est_1fe = feols(Ozone ~ Solar.R + Temp + Wind | Month, aq) est_2fe = feols(Ozone ~ Solar.R + Temp + Wind | Month + Day, aq) # A) automatic way => simply use fixef.group = TRUE etable(est_0fe, est_2fe, fixef.group = TRUE) # Note that when grouping would lead to inconsistencies across models, # it is avoided etable(est_0fe, est_1fe, est_2fe, fixef.group = TRUE) # B) customized way => use a list etable(est_0fe, est_2fe, fixef.group = list("Dates" = "Month|Day")) # Note that when a user grouping would lead to inconsistencies, # the term partial replaces yes/no and the fixed-effects are not removed. etable(est_0fe, est_1fe, est_2fe, fixef.group = list("Dates" = "Month|Day")) # Using customized placement => as with 'group' and 'extraline', # the user can control the placement of the new line. # See the previous 'group' examples and the dedicated section in the help. # On top of the coefficients: etable(est_0fe, est_2fe, fixef.group = list("^^Dates" = "Month|Day")) # Last line of the statistics etable(est_0fe, est_2fe, fixef.group = list("_Dates" = "Month|Day")) # # Using custom functions to compute the standard errors # # You can use external functions to compute the VCOVs # by feeding functions in the 'vcov' argument. # Let's use some covariances from the sandwich package etable(est_c0, est_c1, est_c2, vcov = sandwich::vcovHC) # To add extra arguments to vcovHC, you need to write your wrapper: etable(est_c0, est_c1, est_c2, vcov = function(x) sandwich::vcovHC(x, type = "HC0")) # # Customize which fit statistic to display # # You can change the fit statistics with the argument fitstat # and you can rename them with the dictionary etable(est1, est2, fitstat = ~ r2 + n + G) # If you use a formula, '.' means the default: etable(est1, est2, fitstat = ~ ll + .) # # Computing a different SE for each model # est = feols(Ozone ~ Solar.R + Wind + Temp, data = aq) # # Method 1: use summary s1 = summary(est, "iid") s2 = summary(est, cluster = ~ Month) s3 = summary(est, cluster = ~ Day) s4 = summary(est, cluster = ~ Day + Month) etable(list(s1, s2, s3, s4)) # # Method 2: using a list in the argument 'vcov' est_bis = feols(Ozone ~ Solar.R + Wind + Temp | Month, data = aq) etable(est, est_bis, vcov = list("hetero", ~ Month)) # When you have only one model, this model is replicated # along the elements of the vcov list. etable(est, vcov = list("hetero", ~ Month)) # # Method 3: Using "each" or "times" in vcov # If the first element of the list in 'vcov' is "each" or "times", # then all models will be replicated and all the VCOVs will be # applied to each model. The order in which they are replicated # are governed by the each/times keywords. # each etable(est, est_bis, vcov = list("each", "iid", ~ Month, ~ Day)) # times etable(est, est_bis, vcov = list("times", "iid", ~ Month, ~ Day))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.