From b808c5521599710b608bf91917c030023b4e402c Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 00:49:19 -0500 Subject: [PATCH 01/14] Added basic tests --- .github/workflows/tests.yml | 41 ++++++++++ tests/test_base.R | 155 ++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 tests/test_base.R diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7b4e700 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,41 @@ +name: Unit and build tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: + branches: [ master ] + +jobs: + tests: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + strategy: + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: ubuntu-latest, r: 'release'} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + use-public-rspm: true + + - name: Install dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::devtools, any::lfe + needs: devtools, lfe + + - name: Check build + run: | + devtools::document() + devtools::check() + shell: Rscript {0} diff --git a/tests/test_base.R b/tests/test_base.R new file mode 100644 index 0000000..503277e --- /dev/null +++ b/tests/test_base.R @@ -0,0 +1,155 @@ +# remove.packages("HonestDiD") +# install.packages(".", repos=NULL, type="source") +# testthat::test_dir("tests") + +library(lfe) +library(HonestDiD) +data(BCdata_EventStudy) +data(LWdata_EventStudy) + +BC_numPrePeriods <- length(BCdata_EventStudy$prePeriodIndices) +BC_numPostPeriods <- length(BCdata_EventStudy$postPeriodIndices) +BC_l_vec <- basisVector(index = 1, size = BC_numPostPeriods) +BC_l_vec <- cbind(c(1, 0, 0, 0)) + +test_that("HonestDiD base run with no errors", { + BC_DeltaSDNB_RobustResults <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "FLCI", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsConditional <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "Conditional", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsCF <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "C-F", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsCLF <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "C-LF", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_OriginalResults <- + constructOriginalCS(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec) + + BC_DeltaSDNB_SensitivityPlot <- + createSensitivityPlot(robustResults = BC_DeltaSDNB_RobustResults, + originalResults = BC_OriginalResults) + + expect_silent(BC_DeltaSDNB_RobustResults) + expect_silent(BC_DeltaSDNB_RobustResultsConditional) + expect_silent(BC_DeltaSDNB_RobustResultsCF) + expect_silent(BC_DeltaSDNB_RobustResultsCLF) + expect_silent(BC_DriginalResults) + expect_silent(BC_DeltaSDNB_SensitivityPlot) +}) + +test_that("HonestDiD options run with no errors", { + LWdata_RawData = haven::read_dta(system.file("extdata", "LWdata_RawData.dta", package = "HonestDiD")) + sum(LWdata_RawData$nobs) + + # Estimate event study using lfe package + EmpFemale.EventStudy = lfe::felm(emp ~ + rtESV13 + rtESV14 + rtESV15 + + rtESV16 + rtESV17 + rtESV18 + + rtESV19 + rtESV110 + rtESV111 + # End Pre-periods + rtESV113 + rtESV114 + rtESV115 + + rtESV116 + rtESV117 + rtESV118 + + rtESV119 + rtESV120 + rtESV121 + + rtESV122 + rtESV123 + rtESV124 + + rtESV125 + rtESV126 + rtESV127 + + rtESV128 + rtESV129 + rtESV130 + + rtESV131 + rtESV132 + rtESV133 + + rtESV134 + rtESV135 + # End post-periods + yearsfcor + yearsflr + aveitc + fscontrol + + asian + black + hispanic + other | + factor(PUS_SURVEY_YEAR)*factor(BIRTHYEAR) + + factor(PUS_SURVEY_YEAR) + factor(BIRTHSTATE) | + 0 | BIRTHSTATE, + data = LWdata_RawData, + weights = LWdata_RawData$nobs) + summary(EmpFemale.EventStudy) + + coefIndex = which(grepl(x = dimnames(EmpFemale.EventStudy$coefficients)[[1]], pattern = "rtESV")) + betahat = EmpFemale.EventStudy$beta[coefIndex, ] + + # Extract estimated variance-covariance matrix of event study coefficients + sigma = EmpFemale.EventStudy$clustervcv[coefIndex, coefIndex] + + # Construct vector of event times and the scalar reference period + timeVec = c(seq(from = -11, to = -3, by = 1), seq(from = -1, to = 21, by = 1)) + referencePeriod <- -2 + postPeriodIndices <- which(timeVec > -2) + prePeriodIndices <- which(timeVec < -2) + LW_numPrePeriods <- length(prePeriodIndices) + LW_numPostPeriods <- length(postPeriodIndices) + LW_l_vec <- basisVector(index = 1, size = LW_numPostPeriods) + + for( method in c("C-F", "C-LF", "Conditional", "FLCI") ) { + for( monotonicityDirection in c("increasing", "decreasing") ) { + for ( biasDirection in c("positive", "negative") ) { + LW_DeltaSDNB_RobustResultsCLF <- + createSensitivityResults(betahat = betahat, + sigma = sigma, + numPrePeriods = LW_numPrePeriods, + numPostPeriods = LW_numPostPeriods, + l_vec = LW_l_vec, + method = method, + monotonicityDirection = monotonicityDirection, + biasDirection = biasDirection, + Mvec = seq(from=0, to=0.3, by=0.1)) + print(LW_DeltaSDNB_RobustResults) + expect_silent(LW_DeltaSDNB_RobustResults) + } + } + } + + for ( method in c("C-F", "C-LF", "Conditional") ) { + for ( monotonicityDirection in c("increasing", "decreasing") ) { + for ( biasDirection in c("positive", "negative") ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + monotonicityDirection = monotonicityDirection, + biasDirection = biasDirection, + Mbarvec = seq(from=0, to=2, by=0.5)) + print(BC_DeltaRM_RobustResults) + expect_silent(BC_DeltaRM_RobustResults) + } + } + } + } +}) From bec685fbce3f1dd3b2a31aa31bc7fa0d3d969868 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 01:03:31 -0500 Subject: [PATCH 02/14] Fixed minor typo; fixed tests --- R/deltarmm.R | 2 +- tests/test_base.R | 65 ++++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/R/deltarmm.R b/R/deltarmm.R index c95cacb..932a235 100644 --- a/R/deltarmm.R +++ b/R/deltarmm.R @@ -301,7 +301,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, postPeriodMomentsOnly = postPeriodMomentsOnly, monotonicityDirection = monotonicityDirection, gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) - CIs_RM_plus_allS[,s_i] = CI_s_plus$accept + CIs_RMM_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) CI_s_minus = .computeConditionalCS_DeltaRMM_fixedS(s = s_indices[s_i], max_positive = FALSE, Mbar = Mbar, diff --git a/tests/test_base.R b/tests/test_base.R index 503277e..a5efbca 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -112,7 +112,7 @@ test_that("HonestDiD options run with no errors", { for( method in c("C-F", "C-LF", "Conditional", "FLCI") ) { for( monotonicityDirection in c("increasing", "decreasing") ) { for ( biasDirection in c("positive", "negative") ) { - LW_DeltaSDNB_RobustResultsCLF <- + LW_DeltaSDNB_RobustResults <- createSensitivityResults(betahat = betahat, sigma = sigma, numPrePeriods = LW_numPrePeriods, @@ -122,33 +122,52 @@ test_that("HonestDiD options run with no errors", { monotonicityDirection = monotonicityDirection, biasDirection = biasDirection, Mvec = seq(from=0, to=0.3, by=0.1)) - print(LW_DeltaSDNB_RobustResults) + print(c(method, monotonicityDirection, biasDirection, LW_DeltaSDNB_RobustResults)) expect_silent(LW_DeltaSDNB_RobustResults) } } } - for ( method in c("C-F", "C-LF", "Conditional") ) { - for ( monotonicityDirection in c("increasing", "decreasing") ) { - for ( biasDirection in c("positive", "negative") ) { - for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { - BC_DeltaRM_RobustResults <- - createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, - sigma = BCdata_EventStudy$sigma, - numPrePeriods = BC_numPrePeriods, - numPostPeriods = BC_numPostPeriods, - l_vec = BC_l_vec, - gridPoints = 100, - grid.ub = 1, - grid.lb = -1, - bound = bound, - method = method, - monotonicityDirection = monotonicityDirection, - biasDirection = biasDirection, - Mbarvec = seq(from=0, to=2, by=0.5)) - print(BC_DeltaRM_RobustResults) - expect_silent(BC_DeltaRM_RobustResults) - } + for ( method in c(NULL, "C-LF", "Conditional") ) { + for ( monotonicityDirection in c("increasing", "decreasing", NULL) ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + monotonicityDirection = monotonicityDirection, + Mbarvec = seq(from=0, to=1, by=0.5)) + print(c(method, monotonicityDirection, biasDirection, bound, BC_DeltaRM_RobustResults)) + expect_silent(BC_DeltaRM_RobustResults) + } + } + } + + for ( method in c(NULL, "C-LF", "Conditional") ) { + for ( biasDirection in c("positive", "negative", NULL) ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + biasDirection = biasDirection, + Mbarvec = seq(from=0, to=1, by=0.5)) + print(c(method, monotonicityDirection, biasDirection, bound, BC_DeltaRM_RobustResults)) + expect_silent(BC_DeltaRM_RobustResults) } } } From 75bad16aa0287a69037489213d4e920721583844 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 01:12:07 -0500 Subject: [PATCH 03/14] Added pandoc to gh actions --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b4e700..c9c96a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,9 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Setup pandoc + uses: docker://pandoc/core:2.9 + - name: Set up R uses: r-lib/actions/setup-r@v2 with: From 5edb20d46c7473fcc177ad06d57081789a8f8365 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:26:49 -0500 Subject: [PATCH 04/14] Still trying pandoc --- .github/workflows/tests.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c9c96a1..85c348c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,9 +22,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Setup pandoc - uses: docker://pandoc/core:2.9 - - name: Set up R uses: r-lib/actions/setup-r@v2 with: @@ -34,10 +31,11 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe - needs: devtools, lfe + extra-packages: any::devtools, any::lfe, any::knitr + needs: devtools, lfe, knitr - name: Check build + uses: docker://pandoc/core:2.9 run: | devtools::document() devtools::check() From a661e06a0f0ec04fbe3dd67897365594e2f8bfe6 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:37:04 -0500 Subject: [PATCH 05/14] Still trying pandoc --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 85c348c..1657c19 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,8 +34,10 @@ jobs: extra-packages: any::devtools, any::lfe, any::knitr needs: devtools, lfe, knitr + - name: Setup pandoc + uses: r-lib/actions/setup-padoc@v2 + - name: Check build - uses: docker://pandoc/core:2.9 run: | devtools::document() devtools::check() From 0ac3cc1ee8f62b9485090a5d9cb806120558e4d2 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:43:54 -0500 Subject: [PATCH 06/14] Still trying pandoc (typo) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1657c19..422b381 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: needs: devtools, lfe, knitr - name: Setup pandoc - uses: r-lib/actions/setup-padoc@v2 + uses: r-lib/actions/setup-pandoc@v2 - name: Check build run: | From 38d1a4e1315669bc9a9a47f92516076fae1c6a6f Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 07:00:17 -0500 Subject: [PATCH 07/14] Added latex --- .github/workflows/tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 422b381..0650505 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,12 +31,15 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe, any::knitr - needs: devtools, lfe, knitr + extra-packages: any::devtools, any::lfe, any::knitr, any::formatR + needs: devtools, lfe, knitr, formatR - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 + - name: Setup LaTeX + uses: r-lib/actions/setup-tinytex@v2 + - name: Check build run: | devtools::document() From a96bb36043d150459e1c2dc3a5ca0298f53a55bf Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 07:38:30 -0500 Subject: [PATCH 08/14] Debugging missing extra packages --- .github/workflows/tests.yml | 12 ++++++++++-- R/honest_did.R | 4 ++++ R/sensitivityresults.R | 2 +- man/createEventStudyPlot.Rd | 2 +- tests/test_base.R | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0650505..a6a0e5d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,8 +31,16 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe, any::knitr, any::formatR - needs: devtools, lfe, knitr, formatR + extra-packages: | + any::devtools + any::lfe + any::knitr + any::formatR + any::haven + needs: | + devtools + knitr + rmarkdown - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/R/honest_did.R b/R/honest_did.R index cf72ec4..0741b79 100644 --- a/R/honest_did.R +++ b/R/honest_did.R @@ -10,6 +10,7 @@ honest_did <- function(...) UseMethod("honest_did") #' using the approach of Rambachan and Roth (2021) when #' the event study is estimating using the `did` package #' +#' @param es Result from aggte (object of class AGGTEobj). #' @param e event time to compute the sensitivity analysis for. #' The default value is `e=0` corresponding to the "on impact" #' effect of participating in the treatment. @@ -18,6 +19,9 @@ honest_did <- function(...) UseMethod("honest_did") #' in pre-treatment periods) or "relative_magnitude" (which #' conducts a sensitivity analysis based on the relative magnitudes #' of deviations from parallel trends in pre-treatment periods). +#' @param gridPoints Number of grid points used for the underlying test +#' inversion. Default equals 100. User may wish to change the number of grid +#' points for computational reasons. #' @inheritParams HonestDiD::createSensitivityResults #' @inheritParams HonestDid::createSensitivityResults_relativeMagnitudes honest_did.AGGTEobj <- function(es, diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index bbe6888..e6cb97b 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -732,7 +732,7 @@ constructOriginalCS <- function(betahat, sigma, createEventStudyPlot <- function(betahat, stdErrors = NULL, sigma = NULL, numPrePeriods, numPostPeriods, alpha = 0.05, timeVec, referencePeriod, - useRelativeEventTime = F) { + useRelativeEventTime = FALSE) { if (base::is.null(stdErrors) & base::is.null(sigma)) { base::stop("User must specify either vector of standard errors or vcv matrix!") } else if (base::is.null(stdErrors) & !is.null(sigma)) { diff --git a/man/createEventStudyPlot.Rd b/man/createEventStudyPlot.Rd index fa8a7ca..24f864d 100644 --- a/man/createEventStudyPlot.Rd +++ b/man/createEventStudyPlot.Rd @@ -9,7 +9,7 @@ Constructs event study plot using the estimated event study coefficients and sta } \usage{ createEventStudyPlot(betahat, stdErrors = NULL, sigma = NULL, - numPrePeriods, numPostPeriods, alpha, timeVec, + numPrePeriods, numPostPeriods, alpha = 0.05, timeVec, referencePeriod, useRelativeEventTime = FALSE) } %- maybe also 'usage' for other objects documented here. diff --git a/tests/test_base.R b/tests/test_base.R index a5efbca..cb58118 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -64,7 +64,7 @@ test_that("HonestDiD base run with no errors", { expect_silent(BC_DeltaSDNB_RobustResultsConditional) expect_silent(BC_DeltaSDNB_RobustResultsCF) expect_silent(BC_DeltaSDNB_RobustResultsCLF) - expect_silent(BC_DriginalResults) + expect_silent(BC_OriginalResults) expect_silent(BC_DeltaSDNB_SensitivityPlot) }) From 0bdc444e76ad7d46c14e139c1cc1707a1084e459 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 08:19:08 -0500 Subject: [PATCH 09/14] Moved lfe install to test script --- .github/workflows/tests.yml | 1 - tests/test_base.R | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a6a0e5d..f793a54 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,7 +33,6 @@ jobs: with: extra-packages: | any::devtools - any::lfe any::knitr any::formatR any::haven diff --git a/tests/test_base.R b/tests/test_base.R index cb58118..67d604d 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,6 +2,7 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") +install.packages("lfe") library(lfe) library(HonestDiD) data(BCdata_EventStudy) From 34fcca81bb730f950f023f9559661b1f7fb741d2 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:01:51 -0500 Subject: [PATCH 10/14] Moved lfe install to test script (debugging) --- tests/test_base.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_base.R b/tests/test_base.R index 67d604d..41c14ff 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,7 +2,7 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") -install.packages("lfe") +install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) library(HonestDiD) data(BCdata_EventStudy) From 038800ca0db7b67e73aeb2b32d7fff93245b7f66 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:27:47 -0500 Subject: [PATCH 11/14] Added testthat --- .github/workflows/tests.yml | 2 ++ DESCRIPTION | 1 + tests/test_base.R | 1 + 3 files changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f793a54..2fb1edf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,10 +36,12 @@ jobs: any::knitr any::formatR any::haven + any::testthat needs: | devtools knitr rmarkdown + testthat - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index 3891189..c0d34c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,6 +23,7 @@ Imports: TruncatedNormal (>= 1.0) Suggests: knitr, + testthat, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/tests/test_base.R b/tests/test_base.R index 41c14ff..981c66d 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -4,6 +4,7 @@ install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) +library(testthat) library(HonestDiD) data(BCdata_EventStudy) data(LWdata_EventStudy) From ab47038c3261226bddeb67b70d59a5047e9af357 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:55:06 -0500 Subject: [PATCH 12/14] Added haven for some reason --- .github/workflows/tests.yml | 1 + DESCRIPTION | 1 + tests/test_base.R | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2fb1edf..b17b422 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,6 +42,7 @@ jobs: knitr rmarkdown testthat + haven - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index c0d34c7..6bd9c4b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,6 +24,7 @@ Imports: Suggests: knitr, testthat, + haven, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/tests/test_base.R b/tests/test_base.R index 981c66d..1a06d1a 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -4,6 +4,7 @@ install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) +library(haven) library(testthat) library(HonestDiD) data(BCdata_EventStudy) From 1c9d5e4841b3ca2082a4a7f02de027a1999e41e5 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 16:21:03 -0500 Subject: [PATCH 13/14] Gave up and added lfe to recomended packages (for test) --- .github/workflows/tests.yml | 4 +++- DESCRIPTION | 1 + R/honest_did.R | 8 ++++++-- tests/test_base.R | 1 - 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b17b422..428757c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,14 +35,16 @@ jobs: any::devtools any::knitr any::formatR - any::haven any::testthat + any::haven + any::lfe needs: | devtools knitr rmarkdown testthat haven + lfe - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index 6bd9c4b..4bf4de7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Suggests: knitr, testthat, haven, + lfe, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/R/honest_did.R b/R/honest_did.R index 0741b79..81dcc62 100644 --- a/R/honest_did.R +++ b/R/honest_did.R @@ -2,6 +2,8 @@ #' #' @description a function to compute a sensitivity analysis #' using the approach of Rambachan and Roth (2021) +#' +#' @param ... Parameters to pass to the relevant method. honest_did <- function(...) UseMethod("honest_did") #' @title honest_did.AGGTEobj @@ -20,8 +22,10 @@ honest_did <- function(...) UseMethod("honest_did") #' conducts a sensitivity analysis based on the relative magnitudes #' of deviations from parallel trends in pre-treatment periods). #' @param gridPoints Number of grid points used for the underlying test -#' inversion. Default equals 100. User may wish to change the number of grid -#' points for computational reasons. +#' inversion. Default equals 100. User may wish to change the number of grid +#' points for computational reasons. +#' @param ... Parameters to pass to `createSensitivityResults` or +#' `createSensitivityResults_relativeMagnitudes`. #' @inheritParams HonestDiD::createSensitivityResults #' @inheritParams HonestDid::createSensitivityResults_relativeMagnitudes honest_did.AGGTEobj <- function(es, diff --git a/tests/test_base.R b/tests/test_base.R index 1a06d1a..a9b68b4 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,7 +2,6 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") -install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) library(haven) library(testthat) From 7f45766fdfb39dd59d48aa93d836abd46a279db4 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 11 Jun 2024 13:51:59 -0400 Subject: [PATCH 14/14] Formatted citation -> added DOI; dontrun -> donttest --- DESCRIPTION | 2 +- man/createEventStudyPlot.Rd | 2 +- man/createSensitivityPlot.Rd | 2 +- man/createSensitivityPlot_relativeMagnitudes.Rd | 2 +- man/createSensitivityResults.Rd | 2 +- man/createSensitivityResults_relativeMagnitudes.Rd | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5129d2a..bded60e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,7 @@ Authors@R: role = c("aut", "cph"), email = "jonathan_roth@brown.edu")) Description: - Provides functions to conduct robust inference in difference-in-differences and event study designs by implementing the methods developed in Rambachan & Roth (2023, RESTUD), "A More Credible Approach to Parallel Trends" [Previously titled "An Honest Approach..."]. Inference is conducted under a weaker version of the parallel trends assumption. Uniformly valid confidence sets are constructed based upon conditional confidence sets, fixed-length confidence sets and hybridized confidence sets. + Provides functions to conduct robust inference in difference-in-differences and event study designs by implementing the methods developed in Rambachan & Roth (2023) , "A More Credible Approach to Parallel Trends" [Previously titled "An Honest Approach..."]. Inference is conducted under a weaker version of the parallel trends assumption. Uniformly valid confidence sets are constructed based upon conditional confidence sets, fixed-length confidence sets and hybridized confidence sets. Encoding: UTF-8 LazyData: true License: MIT + file LICENSE diff --git a/man/createEventStudyPlot.Rd b/man/createEventStudyPlot.Rd index 8b472cf..9022c61 100644 --- a/man/createEventStudyPlot.Rd +++ b/man/createEventStudyPlot.Rd @@ -52,7 +52,7 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 Ashesh Rambachan } \examples{ -\dontrun{ +\donttest{ # Simple use case; for more detailed examples, # see createEventStudyPlot(betahat = BCdata_EventStudy$betahat, diff --git a/man/createSensitivityPlot.Rd b/man/createSensitivityPlot.Rd index 4e5b50b..d36996a 100644 --- a/man/createSensitivityPlot.Rd +++ b/man/createSensitivityPlot.Rd @@ -39,7 +39,7 @@ Returns ggplot object of the sensitivity plot. Ashesh Rambachan } \examples{ -\dontrun{ +\donttest{ # Simple use case; for more detailed examples, # see robustResults <- diff --git a/man/createSensitivityPlot_relativeMagnitudes.Rd b/man/createSensitivityPlot_relativeMagnitudes.Rd index f3c2c3c..4012e7b 100644 --- a/man/createSensitivityPlot_relativeMagnitudes.Rd +++ b/man/createSensitivityPlot_relativeMagnitudes.Rd @@ -40,7 +40,7 @@ Returns ggplot object of the sensitivity plot. Ashesh Rambachan } \examples{ -\dontrun{ +\donttest{ # Simple use case. For more detailed examples, # see kwargs <- list(betahat = BCdata_EventStudy$betahat, diff --git a/man/createSensitivityResults.Rd b/man/createSensitivityResults.Rd index 47a3769..427fc32 100644 --- a/man/createSensitivityResults.Rd +++ b/man/createSensitivityResults.Rd @@ -75,7 +75,7 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 Ashesh Rambachan } \examples{ -\dontrun{ +\donttest{ # Simple use case; for more detailed examples, # see createSensitivityResults(betahat = BCdata_EventStudy$betahat, diff --git a/man/createSensitivityResults_relativeMagnitudes.Rd b/man/createSensitivityResults_relativeMagnitudes.Rd index d251697..238451b 100644 --- a/man/createSensitivityResults_relativeMagnitudes.Rd +++ b/man/createSensitivityResults_relativeMagnitudes.Rd @@ -99,7 +99,7 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 Ashesh Rambachan } \examples{ -\dontrun{ +\donttest{ # Simple use case. For more detailed examples, # see kwargs <- list(betahat = BCdata_EventStudy$betahat,