Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion R/utils-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test_is_fixest_iv_second_stage.R
Original file line number Diff line number Diff line change
@@ -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))
})
})
Loading