Set of functions to directly extract some commonly used statistics, like the p-value or
the table of coefficients, from estimations. This was first implemented for
fixest
estimations, but has some support for other models.
Usage
# S3 method for class 'fixest'
coeftable(
object,
vcov = NULL,
ssc = NULL,
cluster = NULL,
keep = NULL,
drop = NULL,
order = NULL,
list = FALSE,
...
)
# S3 method for class 'fixest'
se(
object,
vcov = NULL,
ssc = NULL,
cluster = NULL,
keep = NULL,
drop = NULL,
order = NULL,
...
)
# S3 method for class 'fixest'
tstat(
object,
vcov = NULL,
ssc = NULL,
cluster = NULL,
keep = NULL,
drop = NULL,
order = NULL,
...
)
# S3 method for class 'fixest'
pvalue(
object,
vcov = NULL,
ssc = NULL,
cluster = NULL,
keep = NULL,
drop = NULL,
order = NULL,
...
)
Arguments
- object
A
fixest
object. For example an estimation obtained fromfeols
.- 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: vcov_type ~ variables. The VCOV types implemented are: "iid", "hetero" (or "HC1"), "cluster", "twoway", "NW" (or "newey_west"), "DK" (or "driscoll_kraay"), and "conley". It also accepts object from vcov_cluster, vcov_NW, NW, vcov_DK, DK, vcov_conley and conley. It also accepts covariance matrices computed externally. Finally it accepts functions to compute the covariances. See the vcov documentation in the vignette. You can pass several VCOVs (as above) if you nest them into a list. If the number of VCOVs equals the number of models, eahc VCOV is mapped to the appropriate model. If there is one model and several VCOVs, or if the first element of the list is equal to
"each"
or"times"
, then the estimations will be replicated and the results for each estimation and each VCOV will be reported.- ssc
An object of class
ssc.type
obtained with the functionssc
. Represents how the degree of freedom correction should be done.You must use the functionssc
for this argument. The arguments and defaults of the functionssc
are:K.adj = TRUE
,K.fixef = "nonnested"
,G.adj = TRUE
,G.df = "min"
,t.df = "min"
,K.exact = FALSE)
. See the help of the functionssc
for details.- 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
var1
andvar2
contained in the data.framebase
used for the estimation. All the followingcluster
arguments are valid and do the same thing:cluster = base[, c("var1, "var2")]
,cluster = c("var1, "var2")
,cluster = ~var1+var2
. If the two variables were used as clusters in the estimation, you could further usecluster = 1:2
or leave it blank withse = "twoway"
(assumingvar1
[resp.var2
] was the 1st [resp. 2nd] cluster).- keep
Character vector. This element is used to display only a subset of variables. This should be a vector of regular expressions (see
base::regex
help for more info). Each variable satisfying any of the regular expressions will be kept. This argument is applied post aliasing (see argumentdict
). Example: you have the variablex1
tox55
and want to display onlyx1
tox9
, then you could usekeep = "x[[:digit:]]$"
. If the first character is an exclamation mark, the effect is reversed (e.g. keep = "!Intercept" means: every variable that does not contain “Intercept” is kept). See details.- drop
Character vector. This element is used if some variables are not to be displayed. This should be a vector of regular expressions (see
base::regex
help for more info). Each variable satisfying any of the regular expressions will be discarded. This argument is applied post aliasing (see argumentdict
). Example: you have the variablex1
tox55
and want to display onlyx1
tox9
, then you could usedrop = "x[[:digit:]]{2}
". If the first character is an exclamation mark, the effect is reversed (e.g. drop = "!Intercept" means: every variable that does not contain “Intercept” is dropped). See details.- 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
base::regex
help for more info). The variables satisfying the first regular expression will be placed first, then the order follows the sequence of regular expressions. This argument is applied post aliasing (see argumentdict
). Example: you have the following variables:month1
tomonth6
, thenx1
tox5
, thenyear1
toyear6
. If you want to display first the x's, then the years, then the months you could use:order = c("x", "year")
. If the first character is an exclamation mark, the effect is reversed (e.g. order = "!Intercept" means: every variable that does not contain “Intercept” goes first). See details.- list
Logical, default is
FALSE
. IfTRUE
, then a nested list is returned, the first layer is accessed with the coefficients names; the second layer with the following values:coef
,se
,tstat
,pvalue
. Note that the variable"(Intercept)"
is renamed into"constant"
.- ...
Other arguments to be passed to
summary.fixest
.
Value
Returns a table of coefficients, with in rows the variables and four columns: the estimate, the standard-error, the t-statistic and the p-value.
If list = TRUE
then a nested list is returned, the first layer is accessed with
the coefficients names; the second layer with the following values:
coef
, se
, tstat
, pvalue
. For example, with res = coeftable(est, list = TRUE)
you can access the SE of the coefficient x1
with res$x1$se
; and its
coefficient with res$x1$coef
, etc.
Functions
se(fixest)
: Extracts the standard-error of an estimationtstat(fixest)
: Extracts the t-statistics of an estimationpvalue(fixest)
: Extracts the p-value of an estimation
Examples
# Some data and estimation
data(trade)
est = fepois(Euros ~ log(dist_km) | Origin^Product + Year, trade)
#
# Coeftable/se/tstat/pvalue
#
coeftable(est)
#> Estimate Std. Error z value Pr(>|z|)
#> log(dist_km) -1.023957 1.186755e-06 -862821.1 0
#> attr(,"type")
#> [1] "IID"
se(est)
#> log(dist_km)
#> 1.186755e-06
tstat(est)
#> log(dist_km)
#> -862821.1
pvalue(est)
#> log(dist_km)
#> 0
# Now with two-way clustered standard-errors
# and using coeftable()
coeftable(est, cluster = ~Origin + Product)
#> Estimate Std. Error z value Pr(>|z|)
#> log(dist_km) -1.023957 0.0906375 -11.29728 1.35342e-29
#> attr(,"type")
#> [1] "Clustered (Origin & Product)"
se(est, cluster = ~Origin + Product)
#> log(dist_km)
#> 0.0906375
pvalue(est, cluster = ~Origin + Product)
#> log(dist_km)
#> 1.35342e-29
tstat(est, cluster = ~Origin + Product)
#> log(dist_km)
#> -11.29728
# Or you can cluster only once using summary:
est_sum = summary(est, cluster = ~Origin + Product)
coeftable(est_sum)
#> Estimate Std. Error z value Pr(>|z|)
#> log(dist_km) -1.023957 0.0906375 -11.29728 1.35342e-29
#> attr(,"type")
#> [1] "Clustered (Origin & Product)"
se(est_sum)
#> log(dist_km)
#> 0.0906375
tstat(est_sum)
#> log(dist_km)
#> -11.29728
pvalue(est_sum)
#> log(dist_km)
#> 1.35342e-29
# You can use the arguments keep, drop, order
# to rearrange the results
base = iris
names(base) = c("y", "x1", "x2", "x3", "species")
est_iv = feols(y ~ x1 | x2 ~ x3, base)
tstat(est_iv, keep = "x1")
#> x1
#> 5.911718
coeftable(est_iv, keep = "x1|Int")
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 2.438955 0.34136243 7.144766 3.882920e-11
#> x1 0.559183 0.09458892 5.911718 2.269464e-08
coeftable(est_iv, order = "!Int")
#> Estimate Std. Error t value Pr(>|t|)
#> fit_x2 0.4509765 0.02416890 18.659374 1.336716e-40
#> x1 0.5591830 0.09458892 5.911718 2.269464e-08
#> (Intercept) 2.4389548 0.34136243 7.144766 3.882920e-11
#
# Using lists
#
# Returning the coefficients table as a list can be useful for quick
# reference in markdown documents.
# Note that the "(Intercept)" is renamed into "constant"
res = coeftable(est_iv, list = TRUE)
# coefficient of the constant:
res$constant$coef
#> Estimate
#> 2.438955
# pvalue of x1
res$x1$pvalue
#> Pr(>|t|)
#> 2.269464e-08