-
Notifications
You must be signed in to change notification settings - Fork 28
/
r_test_comparisons.R
56 lines (46 loc) · 1.55 KB
/
r_test_comparisons.R
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Load necessary libraries
library(fixest)
library(ritest)
library(reticulate)
set.seed(1232)
# Import the pyfixest package
pyfixest <- import("pyfixest")
data <- pyfixest$get_data(N = as.integer(1000), seed = as.integer(2999))
# Define the function to run the tests
run_tests_ritest <- function(data) {
# Print the column names of the data
print(names(data))
# Define the formulas, resampling variables, and clusters
formulas <- c("Y~X1+f3", "Y~X1+f3|f1", "Y~X1+f3|f1+f2")
resampvars <- c("X1", "f3", "X1=-0.75", "f3>0.05")
clusters <- c(NA, "group_id")
reps <- 10000
seed <- 123
# Initialize an empty data frame to store results
results <- data.frame()
# Loop through each combination of formula, resampvar, and cluster
for (fml in formulas) {
for (resampvar in resampvars) {
for (cluster in clusters) {
fit <- feols(as.formula(fml), data = data)
if (!is.na(cluster)) {
res_r <- ritest(object = fit, resampvar = resampvar, cluster = cluster, reps = reps, seed = seed)
} else {
res_r <- ritest(object = fit, resampvar = resampvar, reps = reps, seed = seed)
}
results <- rbind(results, data.frame(
formula = fml,
resampvar = resampvar,
cluster = ifelse(is.na(cluster), "none", cluster),
pval = res_r$pval,
se = res_r$se,
ci_lower = res_r$ci[1]
))
}
}
}
# Save the results to a CSV file
write.csv(results, "tests/data/ritest_results.csv", row.names = FALSE)
}
# Run the tests
run_tests_ritest(data)