R: Computes the variance/covariance of a 'fixest' object

vcov.fixest {fixest} | R Documentation

## Computes the variance/covariance of a `fixest` object

### Description

This function extracts the variance-covariance of estimated parameters from a model estimated with `femlm`, `feols` or `feglm`.

### Usage

    ## S3 method for class 'fixest'
    vcov(
      object,
      se,
      cluster,
      dof = NULL,
      attr = FALSE,
      forceCovariance = FALSE,
      keepBounded = FALSE,
      nthreads = getFixest_nthreads(),
      ...
    )

### Arguments

`object` | A `fixest` object. Obtained using the functions `femlm`, `feols` or `feglm`.
`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: `se = "cluster"`, otherwise `se = "standard"`. Note that this argument can be implicitly deduced from the argument `cluster`.
`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` and `var2` contained in the data.frame `base` used for the estimation. All the following `cluster` 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 use `cluster = 1:2` or leave it blank with `se = "twoway"` (assuming `var1` [resp. `var2`] was the 1st [res. 2nd] cluster). You can interact two variables using `^` with the following syntax: `cluster = ~var1^var2` or `cluster = "var1^var2"`.
`dof` | An object of class `dof.type` obtained with the function `dof`. Represents how the degree of freedom correction should be done.You must use the function `dof` for this argument. The arguments and defaults of the function `dof` are: `adj = TRUE`, `fixef.K="nested"`, `cluster.adj = TRUE`, `cluster.df = "conventional"`, `t.df = "conventional"`, `fixef.force_exact=FALSE)`. See the help of the function `dof` for details.
`attr` | Logical, defaults to `FALSE`. Whether to include the attributes describing how the VCOV was computed.
`forceCovariance` | (Advanced users.) Logical, default is `FALSE`. In the peculiar case where the obtained Hessian is not invertible (usually because of collinearity of some variables), use this option to force the covariance matrix, by using a generalized inverse of the Hessian. This can be useful to spot where possible problems come from.
`keepBounded` | (Advanced users – `feNmlm` with non-linear part and bounded coefficients only.) Logical, default is `FALSE`. If `TRUE`, then the bounded coefficients (if any) are treated as unrestricted coefficients and their S.E. is computed (otherwise it is not).
`nthreads` | The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 50% of all threads. You can set permanently the number of threads used within this package using the function `setFixest_nthreads`.
`...` | Other arguments to be passed to `summary.fixest`. The computation of the VCOV matrix is first done in `summary.fixest`.

### Details

For an explanation on how the standard-errors are computed and what is the exact meaning of the arguments, please have a look at the dedicated vignette: On standard-errors.

### Value

It returns a N\times N square matrix where N is the number of variables of the fitted model. This matrix has an attribute “type” specifying how this variance/covariance matrix has been computed (i.e. if it was created using a heteroskedascity-robust correction, or if it was clustered along a specific factor, etc).

### Author(s)

Laurent Berge

### See Also

See also the main estimation functions `femlm`, `feols` or `feglm`. `summary.fixest`, `confint.fixest`, `resid.fixest`, `predict.fixest`, `fixef.fixest`.

### Examples

    # Load trade data
    data(trade)

    # We estimate the effect of distance on trade (with 3 fixed-effects)
    est_pois = femlm(Euros ~ log(dist_km) + log(Year) | Origin + Destination +
                     Product, trade)

    # By default, in the presence of FEs
    # the VCOV is clustered along the first FE
    vcov(est_pois)

    # Heteroskedasticity-robust VCOV
    vcov(est_pois, se = "hetero")

    # "clustered" VCOV (with respect to the Product factor)
    vcov(est_pois, se = "cluster", cluster = trade$Product)
    # another way to make the same request:
    # note that previously arg. se was optional since deduced from arg. cluster
    vcov(est_pois, cluster = "Product")
    # yet another way:
    vcov(est_pois, cluster = ~Product)

    # Another estimation without fixed-effects:
    est_pois_simple = femlm(Euros ~ log(dist_km) + log(Year), trade)

    # We can still get the clustered VCOV,
    # but we need to give the argument cluster:
    vcov(est_pois_simple, cluster = ~Product)

[Package fixest version 0.8.4 Index]