diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 4bc8b51..877d0ee 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -33,8 +33,7 @@ jobs: "ref": "main", "inputs": { "source_repo": "spatial-spur/scpcR", - "source_ref": "${RELEASE_TAG}", - "source_slug": "scpcR" + "source_ref": "${RELEASE_TAG}" } } EOF diff --git a/DESCRIPTION b/DESCRIPTION index 0534755..f336241 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: scpcR Type: Package Title: Spatial Correlation-Robust Inference for Regression Coefficients -Version: 0.1.1 +Version: 0.1.2 Authors@R: c( person("David", "Boll", email = "david.boll@warwick.ac.uk", role = c("aut", "cre")), person("Daniel", "Goettlich", email = "daniel.goettlich@econ.uzh.ch", role = "aut") @@ -17,10 +17,10 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.2 Imports: + fixest (>= 0.14.0), gaussquad, sandwich Suggests: - fixest, geodist, RSpectra, testthat (>= 3.0.0) diff --git a/R/utils-data.R b/R/utils-data.R index 9800087..d03dcb3 100644 --- a/R/utils-data.R +++ b/R/utils-data.R @@ -37,7 +37,8 @@ } .is_fixest_iv_second_stage <- function(model) { - if (!inherits(model, "fixest") || !isTRUE(model$iv)) { + # fix: current fixest marks iv models with is_iv, so use that flag here. + if (!inherits(model, "fixest") || !isTRUE(model$is_iv)) { return(FALSE) } stage <- tryCatch(as.integer(model$iv_stage[[1L]]), error = function(e) NA_integer_) diff --git a/tests/testthat/test_is_fixest_iv_second_stage.R b/tests/testthat/test_is_fixest_iv_second_stage.R new file mode 100644 index 0000000..db9c918 --- /dev/null +++ b/tests/testthat/test_is_fixest_iv_second_stage.R @@ -0,0 +1,24 @@ +test_that("is_fixest_iv_second_stage recognizes second-stage fixest iv fits", { + dat <- data.frame( + y = c(1.0, 2.1, 2.8, 4.2, 5.1, 6.0), + x = c(0.2, 0.7, 1.0, 1.5, 1.8, 2.2), + w = c(-0.4, 0.1, 0.6, -0.2, 0.5, 0.9), + z = c(0.1, 0.5, 0.8, 1.0, 1.3, 1.7), + fe = c(1, 1, 2, 2, 3, 3) + ) + + with_fixest_single_thread({ + fit_ols <- fixest::feols(y ~ w, data = dat) + fit_iv <- fixest::feols(y ~ w | x ~ z, data = dat) + fit_fe_iv <- fixest::feols(y ~ w | fe | x ~ z, data = dat) + + # fix: first-stage fits are iv-related, but they are not the main stage + # that scpc should treat as the final coefficient problem. + first_stage <- fit_iv$iv_first_stage[[1L]] + + expect_false(.is_fixest_iv_second_stage(fit_ols)) + expect_true(.is_fixest_iv_second_stage(fit_iv)) + expect_true(.is_fixest_iv_second_stage(fit_fe_iv)) + expect_false(.is_fixest_iv_second_stage(first_stage)) + }) +})