-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added basic tests * Fixed minor typo; fixed tests * Added pandoc to gh actions * Still trying pandoc * Still trying pandoc * Still trying pandoc (typo) * Added latex * Debugging missing extra packages * Moved lfe install to test script * Moved lfe install to test script (debugging) * Added testthat * Added haven for some reason * Gave up and added lfe to recomended packages (for test) * Set long examples to donotrun; saved pre-computed vignette data * Remove precompute from R build * Tests only run conditional on environment variable * Fix gh workflow typo * Added missing VignetteResults.rdafile * Fixed astray math in rd file * Run tests only on linux * Added MacOSX tests * Debugging OSX * Debugging OSX v2 * Debugging OSX v3 * Added title to sunab fun description
- Loading branch information
Showing
16 changed files
with
536 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ README | |
deltaSD.png | ||
^LICENSE\.md$ | ||
.github | ||
vignettes/precompute.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
#' @title sunab_beta_vcv | ||
#' | ||
#' @description | ||
#' This function takes a regression estimated using fixest with the sunab option | ||
#' and extracts the aggregated event-study coefficients and their variance-covariance matrix | ||
#' | ||
#' @param sunab_fixest The result of a fixest call using the sunab option | ||
#' | ||
#' @returns A list containing beta (the event-study coefficients), | ||
#' sigma (the variance-covariance matrix), and | ||
#' cohorts (the relative times corresponding to beta, sigma) | ||
|
||
sunab_beta_vcv <- | ||
function(sunab_fixest){ | ||
sunab_beta_vcv <- function(sunab_fixest) { | ||
|
||
## The following code block extracts the weights on individual coefs used in | ||
# the fixest aggregation ## | ||
sunab_agg <- sunab_fixest$model_matrix_info$sunab$agg_period | ||
sunab_names <- names(sunab_fixest$coefficients) | ||
sunab_sel <- grepl(sunab_agg, sunab_names, perl=TRUE) | ||
sunab_names <- base::names(sunab_fixest$coefficients) | ||
sunab_sel <- base::grepl(sunab_agg, sunab_names, perl=TRUE) | ||
sunab_names <- sunab_names[sunab_sel] | ||
if(!is.null(sunab_fixest$weights)){ | ||
sunab_wgt <- colSums(sunab_fixest$weights * sign(model.matrix(sunab_fixest)[, sunab_names, drop=FALSE])) | ||
if(!base::is.null(sunab_fixest$weights)){ | ||
sunab_wgt <- base::colSums(sunab_fixest$weights * base::sign(stats::model.matrix(sunab_fixest)[, sunab_names, drop=FALSE])) | ||
} else { | ||
sunab_wgt <- colSums(sign(model.matrix(sunab_fixest)[, sunab_names, drop=FALSE])) | ||
sunab_wgt <- base::colSums(base::sign(stats::model.matrix(sunab_fixest)[, sunab_names, drop=FALSE])) | ||
} | ||
|
||
#Construct matrix sunab_trans such that sunab_trans %*% non-aggregated coefs = aggregated coefs, | ||
sunab_cohorts <- as.numeric(gsub(paste0(".*", sunab_agg, ".*"), "\\2", sunab_names, perl=TRUE)) | ||
sunab_mat <- model.matrix(~ 0 + factor(sunab_cohorts)) | ||
sunab_trans <- solve(t(sunab_mat) %*% (sunab_wgt * sunab_mat)) %*% t(sunab_wgt * sunab_mat) | ||
sunab_cohorts <- base::as.numeric(base::gsub(base::paste0(".*", sunab_agg, ".*"), "\\2", sunab_names, perl=TRUE)) | ||
sunab_mat <- stats::model.matrix(~ 0 + base::factor(sunab_cohorts)) | ||
sunab_trans <- base::solve(base::t(sunab_mat) %*% (sunab_wgt * sunab_mat)) %*% base::t(sunab_wgt * sunab_mat) | ||
|
||
#Get the coefs and vcv | ||
sunab_coefs <- sunab_trans %*% cbind(sunab_fixest$coefficients[sunab_sel]) | ||
sunab_vcov <- sunab_trans %*% sunab_fixest$cov.scaled[sunab_sel, sunab_sel] %*% t(sunab_trans) | ||
sunab_coefs <- sunab_trans %*% base::cbind(sunab_fixest$coefficients[sunab_sel]) | ||
sunab_vcov <- sunab_trans %*% sunab_fixest$cov.scaled[sunab_sel, sunab_sel] %*% base::t(sunab_trans) | ||
|
||
return(list(beta = sunab_coefs, | ||
sigma = sunab_vcov, | ||
cohorts = sort(unique(sunab_cohorts)))) | ||
base::return(base::list(beta = sunab_coefs, | ||
sigma = sunab_vcov, | ||
cohorts = base::sort(base::unique(sunab_cohorts)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
\docType{data} | ||
\name{VignetteResults} | ||
\alias{VignetteResults} | ||
\title{ | ||
Pre-computed results to use in the Vignette. | ||
} | ||
\description{ | ||
This list contains pre-comuted time-intensite results used in the vignette. | ||
} | ||
\format{ | ||
\describe{A list, containing 5 results shown in the vignette; refer to the text for details. | ||
\item{BC_DeltaSDNB_RobustResults}{} | ||
\item{BC_DeltaSDRM_RobustResults}{} | ||
\item{BC_OriginalResults}{} | ||
\item{LW_DeltaSD_RobustResults}{} | ||
\item{LW_DeltaSDD_RobustResults}{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.