-
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.
Pull Request: Add Sun and Abraham Example (#55)
* 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) * Added sunab example to README * Swapped sunab data to be the same as rest of README * Deleted internal sanity check from README
- Loading branch information
Showing
43 changed files
with
212 additions
and
50 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' @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){ | ||
|
||
## 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 <- 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])) | ||
} else { | ||
sunab_wgt <- colSums(sign(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) | ||
|
||
#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) | ||
|
||
return(list(beta = sunab_coefs, | ||
sigma = sunab_vcov, | ||
cohorts = sort(unique(sunab_cohorts)))) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -21,4 +21,3 @@ forcats | |
TruncatedNormal | ||
HonestDiD | ||
fixest | ||
base |
Binary file added
BIN
+3.22 KB
README_cache/gfm/unnamed-chunk-10_1f3c743ec6ce57aeac2e128cd86dc961.RData
Binary file not shown.
Binary file added
BIN
+123 KB
README_cache/gfm/unnamed-chunk-10_1f3c743ec6ce57aeac2e128cd86dc961.rdb
Binary file not shown.
Binary file added
BIN
+295 Bytes
README_cache/gfm/unnamed-chunk-10_1f3c743ec6ce57aeac2e128cd86dc961.rdx
Binary file not shown.
Binary file removed
BIN
-3.19 KB
README_cache/gfm/unnamed-chunk-10_ecab2df8a730e51bf3ade706308e54c6.RData
Binary file not shown.
Binary file removed
BIN
-45.8 KB
README_cache/gfm/unnamed-chunk-10_ecab2df8a730e51bf3ade706308e54c6.rdb
Binary file not shown.
Binary file removed
BIN
-203 Bytes
README_cache/gfm/unnamed-chunk-10_ecab2df8a730e51bf3ade706308e54c6.rdx
Binary file not shown.
Binary file added
BIN
+3.19 KB
README_cache/gfm/unnamed-chunk-12_72f0b4e078ccf5be9960c1babb518ff3.RData
Binary file not shown.
Binary file added
BIN
+45.8 KB
README_cache/gfm/unnamed-chunk-12_72f0b4e078ccf5be9960c1babb518ff3.rdb
Binary file not shown.
Binary file added
BIN
+204 Bytes
README_cache/gfm/unnamed-chunk-12_72f0b4e078ccf5be9960c1babb518ff3.rdx
Binary file not shown.
Binary file removed
BIN
-3.04 KB
README_cache/gfm/unnamed-chunk-4_787f5d4d7640d5f64b3f8c7dba3b50b2.RData
Binary file not shown.
Binary file removed
BIN
-255 Bytes
README_cache/gfm/unnamed-chunk-4_787f5d4d7640d5f64b3f8c7dba3b50b2.rdb
Binary file not shown.
Binary file removed
BIN
-152 Bytes
README_cache/gfm/unnamed-chunk-4_787f5d4d7640d5f64b3f8c7dba3b50b2.rdx
Binary file not shown.
Binary file added
BIN
+3.05 KB
README_cache/gfm/unnamed-chunk-4_d08e39374736e71fa1379f8379b56bb5.RData
Binary file not shown.
Binary file added
BIN
+255 Bytes
README_cache/gfm/unnamed-chunk-4_d08e39374736e71fa1379f8379b56bb5.rdb
Binary file not shown.
Binary file added
BIN
+151 Bytes
README_cache/gfm/unnamed-chunk-4_d08e39374736e71fa1379f8379b56bb5.rdx
Binary file not shown.
Binary file removed
BIN
-3.06 KB
README_cache/gfm/unnamed-chunk-6_4277bfb509c005afc3529900c5e17d65.RData
Binary file not shown.
Binary file removed
BIN
-308 Bytes
README_cache/gfm/unnamed-chunk-6_4277bfb509c005afc3529900c5e17d65.rdb
Binary file not shown.
Binary file removed
BIN
-154 Bytes
README_cache/gfm/unnamed-chunk-6_4277bfb509c005afc3529900c5e17d65.rdx
Binary file not shown.
Binary file added
BIN
+3.06 KB
README_cache/gfm/unnamed-chunk-6_6a1a19c1b25737f3167f0bb30e5b250d.RData
Binary file not shown.
Binary file added
BIN
+309 Bytes
README_cache/gfm/unnamed-chunk-6_6a1a19c1b25737f3167f0bb30e5b250d.rdb
Binary file not shown.
Binary file added
BIN
+152 Bytes
README_cache/gfm/unnamed-chunk-6_6a1a19c1b25737f3167f0bb30e5b250d.rdx
Binary file not shown.
Binary file added
BIN
+2.95 KB
README_cache/gfm/unnamed-chunk-7_40d31aed1b8b0bc2d595204b6c288837.RData
Binary file not shown.
Binary file added
BIN
+474 Bytes
README_cache/gfm/unnamed-chunk-7_40d31aed1b8b0bc2d595204b6c288837.rdb
Binary file not shown.
Binary file added
BIN
+176 Bytes
README_cache/gfm/unnamed-chunk-7_40d31aed1b8b0bc2d595204b6c288837.rdx
Binary file not shown.
Binary file removed
BIN
-2.95 KB
README_cache/gfm/unnamed-chunk-7_482ac7c83370220ab9608c6870f2083e.RData
Binary file not shown.
Binary file removed
BIN
-471 Bytes
README_cache/gfm/unnamed-chunk-7_482ac7c83370220ab9608c6870f2083e.rdb
Binary file not shown.
Binary file removed
BIN
-175 Bytes
README_cache/gfm/unnamed-chunk-7_482ac7c83370220ab9608c6870f2083e.rdx
Binary file not shown.
Binary file removed
BIN
-3.38 KB
README_cache/gfm/unnamed-chunk-8_661915be3d155615d33e8d437bf2a797.RData
Binary file not shown.
Binary file removed
BIN
-234 Bytes
README_cache/gfm/unnamed-chunk-8_661915be3d155615d33e8d437bf2a797.rdx
Binary file not shown.
Binary file added
BIN
+3.38 KB
README_cache/gfm/unnamed-chunk-8_f68e98bbac13a1932bc9db93b38f3a59.RData
Binary file not shown.
Binary file renamed
BIN
+29.7 KB
...nk-8_661915be3d155615d33e8d437bf2a797.rdb → ...nk-8_f68e98bbac13a1932bc9db93b38f3a59.rdb
Binary file not shown.
Binary file added
BIN
+236 Bytes
README_cache/gfm/unnamed-chunk-8_f68e98bbac13a1932bc9db93b38f3a59.rdx
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.