R: Register custom fit statistics

fitstat_register {fixest} | R Documentation

## Register custom fit statistics

### Description

Enables the registration of custom fi statistics that can be easily summoned with the function `fitstat`.

### Usage

    fitstat_register(type, fun, alias)

### Arguments

`type` | A character scalar giving the type-name.
`fun` | A function to be applied to a `fixest` estimation. It must return either a scalar, either a list. Note that for the print method to work correctly, the names of the items of the list must be one of: `stat`, `p`, `df`, `df1`, `df2`, `vcov`. Only the print method is affected by this.
`alias` | An alias to be used in lieu of the type name in the display methods (ie when used in the function `print.fixest_fitstat` or `etable`).

### Examples

    data(trade)
    gravity = feols(log(Euros) ~ log(dist_km) | Destination + Origin, trade)

    # Extracting the 'working' number of observations used to compute the pvalues
    fitstat(gravity, "g", simplify = TRUE)

    # Some fit statistics
    fitstat(gravity, ~ rmse + r2 + wald + wf)

    # You can use them in etable
    etable(gravity, fitstat = ~ rmse + r2 + wald + wf)

    # For wald and wf, you could show the pvalue instead:
    etable(gravity, fitstat = ~ rmse + r2 + wald.p + wf.p)

    # Now let's display some statistics that are not built-in
    # => we use fitstat_register to create them

    # We need: a) type name, b) the function to be applied
    #          c) (optional) an alias

    fitstat_register("tstand", function(x) tstat(x, se = "stand")[1], "t-stat (regular)")
    fitstat_register("thc", function(x) tstat(x, se = "heter")[1], "t-stat (HC1)")
    fitstat_register("t1w", function(x) tstat(x, se = "clus")[1], "t-stat (clustered)")
    fitstat_register("t2w", function(x) tstat(x, se = "twow")[1], "t-stat (2-way)")

    # Now we can use these keywords in fitstat:
    etable(gravity, fitstat = ~ . + tstand + thc + t1w + t2w)

    # Note that the custom stats we created are can easily lead
    # to errors, but that's another story!

[Package fixest version 0.8.4 Index]