-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#14 boottest() now throws an error whenever variables used as fixed e…
…ffects in either `felm()` or `feols()` are not factor variables in the original data. associated tests in inst/tinytest/tests_numeric_fe_clusters.R
- Loading branch information
Showing
3 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# test issue https://github.com/s3alfisc/fwildclusterboot/issues/14 | ||
# raised by Timoth?e | ||
# Test 1: one cluster variable is numeric | ||
# Test 2: one fixed effect is numeric | ||
# Test 3: both fixed effect and cluster variables are numeric | ||
|
||
data(voters) | ||
|
||
to_char <- c("Q1_immigration", "Q2_defense", "group_id1") | ||
sapply(voters[, to_char], class) | ||
|
||
|
||
# Test 1: one cluster variable is numeric | ||
voters_1 <- voters | ||
voters_1$Q2_defense <- as.numeric(voters_1$Q2_defense) | ||
sapply(voters_1[, to_char], class) | ||
|
||
feols_fit <- feols(proposition_vote ~ treatment + log_income | Q2_defense , data = voters) | ||
feols_fit_2 <- feols(proposition_vote ~ treatment + log_income | Q2_defense, data = voters_1) | ||
lfe_fit <- lfe::felm(proposition_vote ~ treatment + log_income | Q2_defense, data = voters_1) | ||
|
||
# bootstrap inference via boottest() | ||
# expect_no_error | ||
boottest(feols_fit, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min') | ||
|
||
expect_error(boottest(feols_fit_2, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min')) | ||
|
||
expect_error(boottest(lfe_fit, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min')) | ||
|
||
|
||
|
||
# are results the same no matter the type of the clustering variable? | ||
|
||
run <- FALSE | ||
if(run){ | ||
voters_2 <- voters | ||
voters_2$group_id1 <- as.numeric(voters_2$group_id1) | ||
|
||
feols_fit <- feols(proposition_vote ~ treatment + log_income , data = voters) | ||
feols_fit_2 <- feols(proposition_vote ~ treatment + log_income , data = voters_2) | ||
lfe_fit <- lfe::felm(proposition_vote ~ treatment + log_income , data = voters) | ||
lfe_fit_2 <- lfe::felm(proposition_vote ~ treatment + log_income , data = voters_2) | ||
|
||
feols_boot <- | ||
boottest(feols_fit, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min') | ||
feols_boot_2 <- | ||
boottest(feols_fit_2, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min') | ||
lfe_boot <- | ||
boottest(lfe_fit, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min') | ||
lfe_boot_2 <- | ||
boottest(lfe_fit_2, | ||
clustid = c("Q1_immigration","Q2_defense"), | ||
B = 9999, | ||
param = "treatment", | ||
bootcluster='min') | ||
expect_equal(feols_boot$p_val, feols_boot_2$p_val) | ||
expect_equal(feols_boot$p_val, lfe_boot$p_val) | ||
expect_equal(lfe_boot$p_val, lfe_boot_2$p_val) | ||
|
||
|
||
} |