diff --git a/DESCRIPTION b/DESCRIPTION index f0b81ee..989e952 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: fect Type: Package Title: Fixed Effects Counterfactual Estimators -Version: 2.0.4 -Date: 2025-08-23 +Version: 2.0.5 +Date: 2025-08-25 Authors@R: c(person("Licheng", "Liu", , "lichengl@stanford.edu", role = c("aut")), person("Ziyi", "Liu", , "zyliu2023@berkeley.edu", role = c("aut")), @@ -12,7 +12,7 @@ Authors@R: person("Shiyun", "Hu", , "hushiyun@pku.edu.cn", role = c("aut")), person("Rivka", "Lipkovitz", , "rivkal@mit.edu", role = c("aut"))) Maintainer: Yiqing Xu -Description: Provides tools for estimating causal effects in panel data using counterfactual methods, as well as other modern DID estimators. It is designed for causal panel analysis with binary treatments under the parallel trends assumption. The package supports scenarios where treatments can switch on and off and allows for limited carryover effects. It includes several imputation estimators, such as Gsynth (Xu 2017), linear factor models, and the matrix completion method. Detailed methodology is described in Liu, Wang, and Xu (2024) and Chiu et al. (2025) . +Description: Provides tools for estimating causal effects in panel data using counterfactual methods, as well as other modern DID estimators. It is designed for causal panel analysis with binary treatments under the parallel trends assumption. The package supports scenarios where treatments can switch on and off and allows for limited carryover effects. It includes several imputation estimators, such as Gsynth (Xu 2017), linear factor models, and the matrix completion method. Detailed methodology is described in Liu, Wang, and Xu (2024) and Chiu et al. (2025) . Optionally integrates with the "HonestDiDFEct" package for sensitivity analyses compatible with imputation estimators. "HonestDiDFEct" is not on CRAN but can be obtained from . URL: https://yiqingxu.org/packages/fect/ NeedsCompilation: yes License: MIT + file LICENSE @@ -39,10 +39,10 @@ Suggests: panelView, testthat (>= 3.0.0), did, - DIDmultiplegtDYN, - HonestDiDFEct, - ggrepel -Depends: R (>= 3.5.0) + DIDmultiplegtDYN, + ggrepel, + HonestDiDFEct +Depends: R (>= 4.1.0) LinkingTo: Rcpp, RcppArmadillo RoxygenNote: 7.3.2 Packaged: 2024-01-26 03:25:56 UTC; ziyil diff --git a/R/fect_sens.R b/R/fect_sens.R index a7bf433..8c510b1 100644 --- a/R/fect_sens.R +++ b/R/fect_sens.R @@ -1,3 +1,15 @@ +.has_honest <- function() { + requireNamespace("HonestDiDFEct", quietly = TRUE) +} + +.honest <- function(fun) { + if (!.has_honest()) { + stop("Optional dependency ``HonestDiDFEct'' not available. Install from https://github.com/lzy318/HonestDiDFEct .", call. = FALSE) + } + getExportedValue("HonestDiDFEct", fun) +} + + fect_sens <- function( fect.out, post.periods = NA, # Post-treatment periods @@ -73,7 +85,7 @@ fect_sens <- function( # ------------------------------------------------------------------- if (!is.null(Mbarvec) && length(Mbarvec) > 0) { # 3a) Weighted-average, across the entire post-treatment window - rm_sens_results <- HonestDiDFEct::createSensitivityResults_relativeMagnitudes( + rm_sens_results <- .honest("createSensitivityResults_relativeMagnitudes")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, @@ -84,7 +96,7 @@ fect_sens <- function( ) - rm_original_cs <- HonestDiDFEct::constructOriginalCS( + rm_original_cs <- .honest("constructOriginalCS")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, @@ -106,7 +118,7 @@ fect_sens <- function( # For each t_i, we run createSensitivityResults_relativeMagnitudes # across all Mbar in Mbarvec - honest.dte <- HonestDiDFEct::createSensitivityResults_relativeMagnitudes( + honest.dte <- .honest("createSensitivityResults_relativeMagnitudes")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, @@ -141,7 +153,7 @@ fect_sens <- function( if (!is.null(Mvec) && length(Mvec) > 0) { # 4a) Weighted-average analysis - smooth_sens_results <- HonestDiDFEct::createSensitivityResults( + smooth_sens_results <- .honest("createSensitivityResults")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, @@ -152,7 +164,7 @@ fect_sens <- function( parallel = parallel ) - sm_original_cs <- HonestDiDFEct::constructOriginalCS( + sm_original_cs <- .honest("constructOriginalCS")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, @@ -169,7 +181,7 @@ fect_sens <- function( dte_l <- rep(0, numPostPeriods) dte_l[t_i] <- 1 - honest.dte <- HonestDiDFEct::createSensitivityResults( + honest.dte <- .honest("createSensitivityResults")( betahat = beta.hat, sigma = vcov.hat, numPrePeriods = numPrePeriods, diff --git a/man/esplot.Rd b/man/esplot.Rd index 733666e..1a75bb5 100644 --- a/man/esplot.Rd +++ b/man/esplot.Rd @@ -91,38 +91,38 @@ event_data$count[event_data$time == -5 | event_data$time == 5] <- 20 # for propo esplot(event_data, Period = "time", Estimate = "ATT", CI.lower = "CI.lower", CI.upper = "CI.upper") -# Connected plot with ribbon -esplot(event_data, Period = "time", Estimate = "ATT", - CI.lower = "CI.lower", CI.upper = "CI.upper", - connected = TRUE, show.points = TRUE) +# # Connected plot with ribbon +# esplot(event_data, Period = "time", Estimate = "ATT", +# CI.lower = "CI.lower", CI.upper = "CI.upper", +# connected = TRUE, show.points = TRUE) -# Connected plot using SE for CI calculation -event_data_no_ci <- event_data[, c("time", "ATT", "SE", "count")] -esplot(event_data_no_ci, Period = "time", Estimate = "ATT", SE = "SE", - connected = TRUE, ci.outline = TRUE, color = "blue") +# # Connected plot using SE for CI calculation +# event_data_no_ci <- event_data[, c("time", "ATT", "SE", "count")] +# esplot(event_data_no_ci, Period = "time", Estimate = "ATT", SE = "SE", +# connected = TRUE, ci.outline = TRUE, color = "blue") -# Show count bars and stats -esplot(event_data, Period = "time", Estimate = "ATT", - CI.lower = "CI.lower", CI.upper = "CI.upper", Count = "count", - show.count = TRUE, stats = c(0.03, 0.12), stats.labs = c("P-val Pre", "P-val Post"), - main = "Event Study with Counts and Stats", proportion = 0.2) +# # Show count bars and stats +# esplot(event_data, Period = "time", Estimate = "ATT", +# CI.lower = "CI.lower", CI.upper = "CI.upper", Count = "count", +# show.count = TRUE, stats = c(0.03, 0.12), stats.labs = c("P-val Pre", "P-val Post"), +# main = "Event Study with Counts and Stats", proportion = 0.2) -# Highlight specific periods (connected) -esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", - connected = TRUE, highlight.periods = c(-1, 2), - highlight.colors = c("orange", "green"), - main = "Highlighted Periods (Connected)") +# # Highlight specific periods (connected) +# esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", +# connected = TRUE, highlight.periods = c(-1, 2), +# highlight.colors = c("orange", "green"), +# main = "Highlighted Periods (Connected)") -# Highlight specific periods (point-range) -esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", - connected = FALSE, highlight.periods = c(-1, 2), - highlight.colors = c("orange", "green"), - main = "Highlighted Periods (Point-Range)") +# # Highlight specific periods (point-range) +# esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", +# connected = FALSE, highlight.periods = c(-1, 2), +# highlight.colors = c("orange", "green"), +# main = "Highlighted Periods (Point-Range)") -# Only post-treatment period, custom labels -esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", - only.post = TRUE, xlab = "Years Post-Intervention", ylab = "Impact Metric", - start0 = TRUE, color = "darkred", est.lwidth = 1.5) +# # Only post-treatment period, custom labels +# esplot(event_data, Period = "time", Estimate = "ATT", SE = "SE", +# only.post = TRUE, xlab = "Years Post-Intervention", ylab = "Impact Metric", +# start0 = TRUE, color = "darkred", est.lwidth = 1.5) # Using did_wrapper object (conceptual example, requires `did` package and setup) # if (requireNamespace("did", quietly = TRUE)) { diff --git a/pkgdown/build.R b/pkgdown/build.R index 0d4cc48..e52f516 100644 --- a/pkgdown/build.R +++ b/pkgdown/build.R @@ -5,6 +5,7 @@ setwd("~/github/fect") library(usethis) library(sinew) library(pkgdown) +library(quarto) usethis::use_readme_rmd() usethis::use_pkgdown() usethis::use_news_md() # update logs diff --git a/vignettes/01-start.Rmd b/vignettes/01-start.Rmd index f948483..cc88824 100644 --- a/vignettes/01-start.Rmd +++ b/vignettes/01-start.Rmd @@ -14,12 +14,17 @@ To install **fect** from CRAN, run the code chunk below: install.packages("fect") ``` -We recommend users to install the most up-to-date version of **fect** from Github using: - +We recommend users to install the most up-to-date, stable version of **fect** from Github using: ```{r eval = FALSE, message = FALSE, warning = FALSE, cache = FALSE,} devtools::install_github("xuyiqing/fect") ``` +We fix bugs in the `dev` branch before merging into the main branch; therefore, it is often more up to date. +```{r eval = FALSE, message = FALSE, warning = FALSE, cache = FALSE,} +devtools::install_github("xuyiqing/fect@dev") +``` + + After installation, check **fect** version to make sure the package is up-to-date. ```{r} diff --git a/vignettes/05-panel.Rmd b/vignettes/05-panel.Rmd index e40e5ee..bffa996 100644 --- a/vignettes/05-panel.Rmd +++ b/vignettes/05-panel.Rmd @@ -30,7 +30,7 @@ To begin, you will need to install the necessary packages from CRAN and GitHub. # install packages from CRAN packages <- c("dplyr", "fixest", "did", "didimputation", "panelView", "ggplot2", "bacondecomp", "HonestDiD", - "DIDmultiplegtDYN", "PanelMatch") + "DIDmultiplegtDYN", "PanelMatch", "readstata13") install.packages(setdiff(packages, rownames(installed.packages()))) # install most up-to-date "fect" from Github diff --git a/vignettes/index.qmd b/vignettes/index.qmd index 8855691..09be328 100644 --- a/vignettes/index.qmd +++ b/vignettes/index.qmd @@ -87,14 +87,52 @@ The following individuals have contributed to **gsynth** and **fect**, listed in Special thanks to Ziyi, Tianzhu, and Rivka for their tireless efforts in improving this package. Thanks to Jinwen for setting up and maintaining this User Manual. -## Report bugs +## Update Log -Please report any bugs to me (yiqingxu \[at\] stanford.edu) or submit an issue on [GitHub](https://github.com/xuyiqing/fect/issues). Please include your minimally replicable code & data file and a **panelView** treatment status plot. Your feedback is highly valued! +### v2.0.5 +(2025-08-25) CRAN release. + +- Fixed various bugs due to changes in dependencies +- Added limit to `cores` by default in parallel computing \ +- Add new plot `type = "hte"` +- Added R-CMD-check for merging + +### v2.0.2 +(2025-05-07) + +- Fixed various bugs +- Updated counterfactual plot +- Added sensitivity analysis +- Added `did_wrapper()` and `esplot()` +- Added various plotting options +- Improved documentation + +### v2.0.0 +(2025-01-17) CRAN release. + +- Changed to new syntax +- Fixed various bugs +- Added `get_cohort()` +- Merged in **gsynth** + + +## Report Bugs + +Please report any bugs by submitting an issue on [GitHub](https://github.com/xuyiqing/fect/issues) or emailing me (yiqingxu \[at\] stanford.edu). We'd really appreciate it if you can include your minimally replicable code & data file and a **panelView** treatment status plot. Your feedback is highly valued! -fect: [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [downloads: CRAN](https://cran.r-project.org/web/packages/fect/index.html) +**fect**: [![Lifecycle: stable](https://lifecycle.r-lib.org/articles/figures/lifecycle-stable.svg)](https://www.tidyverse.org/lifecycle/#stable) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[CRAN status](https://CRAN.R-project.org/package=fect) +[CRAN downloads](https://cran.r-project.org/web/packages/fect/index.html) + + -gsynth: [downloads: CRAN](https://cran.r-project.org/web/packages/gsynth/index.html) (retiring) +**gsynth** (retiring): [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[CRAN status](https://CRAN.R-project.org/package=gsynth) +[downloads: CRAN](https://cran.r-project.org/web/packages/gsynth/index.html)