Skip to content

Commit

Permalink
Merge pull request #17 from kylebutts/main
Browse files Browse the repository at this point in the history
Update `fixest` usage in vignette
  • Loading branch information
s3alfisc committed Jun 8, 2023
2 parents cc7a795 + 1bd8a1a commit c452e34
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions vignettes/summclust.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ Note that you can also use CVR3 and CRV3J covariance matrices computed via `summ

```{r, warning = FALSE, message=FALSE}
library(lmtest)
library(fixest)
vcov3J <-
vcov_CR3J(
lm_fit,
cluster = ~ ind_code
)
vcov_CR3J(
lm_fit,
cluster = ~ ind_code
)
all.equal(
vcov3J,
Expand All @@ -81,26 +79,32 @@ all.equal(
df <- length(summclust_res$cluster) - 1
# with lmtest
CRV1 <- coeftest(lm_fit, sandwich::vcovCL(lm_fit, ~ind_code), df = df)
CRV3 <- coeftest(lm_fit, vcov3J, df = df)
CRV1 <- lmtest::coeftest(lm_fit, sandwich::vcovCL(lm_fit, ~ind_code), df = df)
CRV3 <- lmtest::coeftest(lm_fit, vcov3J, df = df)
CRV1[c("union", "race", "msp"),]
CRV3[c("union", "race", "msp"),]
confint(CRV1)[c("union", "race", "msp"),]
confint(CRV3)[c("union", "race", "msp"),]
lmtest::confint(CRV1)[c("union", "race", "msp"),]
lmtest::confint(CRV3)[c("union", "race", "msp"),]
```

```{r}
library(fixest)
# with fixest
feols_fit <- feols(
ln_wage ~ as.factor(grade) + as.factor(age) + as.factor(birth_yr) + union + race + msp,
data = nlswork)
ln_wage ~ i(grade) + i(age) + i(birth_yr) + union + race + msp,
data = nlswork
)
fixest::coeftable(
feols_fit,
vcov = summclust_res$vcov,
ssc = ssc(adj = FALSE, cluster.adj = FALSE)
)[c("msp", "union", "race"),]
# Store vcov into the fixest object
feols_fit <- summary(
feols_fit,
vcov = vcov_CR3J(feols_fit, cluster = ~ ind_code)
)
# Now it just works with fixest functions
fixest::coeftable(feols_fit, keep = c("msp", "union", "race"))
```

The p-value and confidence intervals for `fixest::coeftable()` differ from `lmtest::coeftest()` and `summclust::coeftable()`. This is due to the fact that `fixest::coeftable()` uses a different degree of freedom for the t-distribution used in these calculation (I believe it uses t(N-1)).
Expand Down

0 comments on commit c452e34

Please sign in to comment.