With a model like y = Xβ + Dθ + Fψ + ε, where
D and F are matrices with dummy encoded factors, one application
of lfe is to study the variances var(Dθ), var(Fψ)
and covariances cov(Dθ, Fψ). However, if we use estimates for
θ and ψ, the resulting variances are biased. The
fevcov computes a bias corrected covariance matrix as
described in Gaure (2014).
1 2 3 4 5 6 7 8
an object of class '"felm"', the result of a call to
a data frame, the result of a call to
numeric. The absolute tolerance for the bias-corrected correlation.
logical. Should robust (heteroskedastic or cluster) residuals be used, rather than i.i.d.
integer. Maximum number of samples for expectation estimates.
character. Name of left hand side if multiple left hand sides.
tol argument specifies the tolerance. The tolerance is relative
for the variances, i.e. the diagonal of the output. For the covariances,
the tolerance is relative to the square root of the product of the
variances, i.e. an absolute tolerance for the correlation. If a numeric of
tol specifies the same tolerance for all
variances/covariances. If it is of length 2,
tol specifies the
variance tolerance, and
tol the covariance tolerance.
can also be a square matrix of size
length(est$fe), in which case the
tolerance for each variance and covariance is specified individually.
The function performs no checks for estimability. If the fixed effects are
not estimable, the result of a call to
fevcov is not useable.
Moreover, there should be just a single connected component among the fixed
alpha must contain a full set of coefficients, and contain columns
'effect' like the default estimable functions from
In the case that the
felm-estimation has weights, it is the
weighted variances and covariance which are bias corrected.
fevcov returns a square matrix with the bias corrected
covariances. An attribute
'bias' contains the biases. The bias
corrections have been subtracted from the bias estimates. I.e. vc = vc' -
b, where vc' is the biased variance and b is the bias.
Bias correction for IV-estimates are not supported as of now.
Note that if
est is the result of a call to
keepX=FALSE (the default), the biases will be computed as if the
covariates X are independent of the factors. This will be faster (typically
by a factor of approx. 4), and possibly wronger. Note also that the
computations performed by this function are non-trivial, they may take quite
some time. It would be wise to start out with quite liberal tolerances,
e.g. tol=0.1, to get an idea of the time requirements.
If there are only two fixed effects,
fevcov returns the same
bccorr, though in a slightly different format.
Gaure, S. (2014), Correlation bias correction in two-way fixed-effects linear regression, Stat 3(1):379-390, 2014. http://dx.doi.org/10.1002/sta4.68
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
x <- rnorm(5000) x2 <- rnorm(length(x)) ## create individual and firm id <- factor(sample(40,length(x),replace=TRUE)) firm <- factor(sample(30,length(x),replace=TRUE,prob=c(2,rep(1,29)))) foo <- factor(sample(20,length(x),replace=TRUE)) ## effects id.eff <- rnorm(nlevels(id)) firm.eff <- runif(nlevels(firm)) foo.eff <- rchisq(nlevels(foo),df=1) ## left hand side id.m <- id.eff[id] firm.m <- firm.eff[firm] foo.m <- foo.eff[foo] # normalize them id.m <- id.m/sd(id.m) firm.m <- firm.m/sd(firm.m) foo.m <- foo.m/sd(foo.m) y <- x + 0.25*x2 + id.m + firm.m + foo.m + rnorm(length(x),sd=2) z <- x + 0.5*x2 + 0.7*id.m + 0.5*firm.m + 0.3*foo.m + rnorm(length(x),sd=2) # make a data frame fr <- data.frame(y,z,x,x2,id,firm,foo) ## estimate and print result est <- felm(y|z ~ x+x2|id+firm+foo, data=fr, keepX=TRUE) # find bias corrections, there's little bias in this example print(yv <- fevcov(est, lhs='y')) ## Here's how to compute the unbiased correlation matrix: cm <- cov2cor(yv) structure(cm,bias=NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.