-
Notifications
You must be signed in to change notification settings - Fork 130
v2.3.1.904: time-varying weights fix, fix_weights param, namespace cleanup #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: Bump dev version on PR merge | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [master, main] | ||
|
|
||
| jobs: | ||
| bump-version: | ||
| if: github.event.pull_request.merged == true | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Bump dev version in DESCRIPTION | ||
| run: | | ||
| # Extract current version | ||
| current=$(grep '^Version:' DESCRIPTION | sed 's/Version: //') | ||
| echo "Current version: $current" | ||
|
|
||
| # Split into parts | ||
| IFS='.' read -ra parts <<< "$current" | ||
| major="${parts[0]}" | ||
| minor="${parts[1]}" | ||
| patch="${parts[2]}" | ||
| dev="${parts[3]:-0}" | ||
|
|
||
| # Increment dev version | ||
| new_dev=$((dev + 1)) | ||
| new_version="${major}.${minor}.${patch}.${new_dev}" | ||
| echo "New version: $new_version" | ||
|
|
||
| # Update DESCRIPTION | ||
| sed -i "s/^Version: .*/Version: ${new_version}/" DESCRIPTION | ||
|
|
||
| # Configure git | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| # Commit and push | ||
| git add DESCRIPTION | ||
| git diff --cached --quiet || git commit -m "Bump version to ${new_version}" | ||
| git push | ||
|
Comment on lines
+16
to
+50
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,50 @@ | |||||||||||||||||||||
| #' It defines which "group" a unit belongs to. It should be 0 for units | ||||||||||||||||||||||
| #' in the untreated group. | ||||||||||||||||||||||
| #' @param weightsname The name of the column containing the sampling weights. | ||||||||||||||||||||||
| #' If not set, all observations have same weight. | ||||||||||||||||||||||
| #' If not set, all observations have same weight. When weights are | ||||||||||||||||||||||
| #' time-invariant (constant within each unit across periods), all | ||||||||||||||||||||||
| #' \code{fix_weights} options produce identical results and no special | ||||||||||||||||||||||
| #' handling is needed. | ||||||||||||||||||||||
| #' | ||||||||||||||||||||||
| #' When weights vary across time (e.g., time-varying population sizes), | ||||||||||||||||||||||
| #' the default behavior differs by panel type: | ||||||||||||||||||||||
| #' \describe{ | ||||||||||||||||||||||
| #' \item{Balanced panel}{Each 2x2 DiD comparison uses the weight from the | ||||||||||||||||||||||
| #' earlier of the two time periods involved. For post-treatment cells, | ||||||||||||||||||||||
| #' this is the base period (g-1). For pre-treatment cells with | ||||||||||||||||||||||
| #' \code{base_period="varying"}, this is the pre-treatment period itself. | ||||||||||||||||||||||
| #' The panel DRDID estimators are used.} | ||||||||||||||||||||||
| #' \item{Repeated cross sections and unbalanced panels}{Both periods' | ||||||||||||||||||||||
| #' per-observation weights are passed directly to the RC DRDID estimators, | ||||||||||||||||||||||
| #' so each observation carries its own period-specific weight.} | ||||||||||||||||||||||
| #' } | ||||||||||||||||||||||
| #' Use the \code{fix_weights} argument to override the default behavior. | ||||||||||||||||||||||
| #' @param fix_weights Controls how time-varying sampling weights are resolved. | ||||||||||||||||||||||
| #' Only relevant when weights vary across time; with time-invariant weights, | ||||||||||||||||||||||
| #' all options produce identical results. Options: | ||||||||||||||||||||||
| #' \describe{ | ||||||||||||||||||||||
| #' \item{\code{NULL} (default)}{For balanced panel: uses the weight from | ||||||||||||||||||||||
| #' the earlier of the two time periods in each 2x2 comparison. For | ||||||||||||||||||||||
| #' post-treatment cells, this is the base period (g-1). For | ||||||||||||||||||||||
| #' pre-treatment cells, this depends on the \code{base_period} setting. | ||||||||||||||||||||||
| #' For RC/unbalanced panel: uses per-observation weights from both | ||||||||||||||||||||||
| #' periods.} | ||||||||||||||||||||||
| #' \item{\code{"varying"}}{Uses per-observation, period-specific weights | ||||||||||||||||||||||
| #' for all panel types. For balanced panel data, this switches to the | ||||||||||||||||||||||
| #' repeated cross-section DRDID estimators so that pre-period and | ||||||||||||||||||||||
| #' post-period observations each carry their own weight. This is the | ||||||||||||||||||||||
| #' most flexible option but sacrifices the efficiency of the panel | ||||||||||||||||||||||
| #' estimator. For RC/unbalanced panel, this is identical to the | ||||||||||||||||||||||
| #' default.} | ||||||||||||||||||||||
| #' \item{\code{"base_period"}}{Fixes weights at the base period (g-1) for | ||||||||||||||||||||||
| #' all (g,t) cells within a group, for both pre-treatment and | ||||||||||||||||||||||
| #' post-treatment comparisons. Ensures all cells within a group use the | ||||||||||||||||||||||
| #' same weights. For RC/unbalanced panel, units not observed in the base | ||||||||||||||||||||||
| #' period are dropped with a warning.} | ||||||||||||||||||||||
| #' \item{\code{"first_period"}}{Fixes weights at the first time period in | ||||||||||||||||||||||
| #' the dataset for all (g,t) cells. For RC/unbalanced panel, units not | ||||||||||||||||||||||
| #' observed in the first period are dropped with a warning.} | ||||||||||||||||||||||
| #' } | ||||||||||||||||||||||
| #' @param alp the significance level, default is 0.05 | ||||||||||||||||||||||
| #' @param bstrap Boolean for whether or not to compute standard errors using | ||||||||||||||||||||||
| #' the multiplier bootstrap. If standard errors are clustered, then one | ||||||||||||||||||||||
|
|
@@ -195,6 +238,7 @@ att_gt <- function(yname, | |||||||||||||||||||||
| control_group = c("nevertreated", "notyettreated"), | ||||||||||||||||||||||
| anticipation = 0, | ||||||||||||||||||||||
| weightsname = NULL, | ||||||||||||||||||||||
| fix_weights = NULL, | ||||||||||||||||||||||
| alp = 0.05, | ||||||||||||||||||||||
| bstrap = TRUE, | ||||||||||||||||||||||
| cband = TRUE, | ||||||||||||||||||||||
|
|
@@ -217,6 +261,14 @@ att_gt <- function(yname, | |||||||||||||||||||||
| "\". Extra arguments are only passed to custom est_method functions.") | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Validate fix_weights | ||||||||||||||||||||||
| if (!is.null(fix_weights)) { | ||||||||||||||||||||||
| if (!is.character(fix_weights) || length(fix_weights) != 1 || | ||||||||||||||||||||||
| !(fix_weights %in% c("varying", "base_period", "first_period"))) { | ||||||||||||||||||||||
| stop("fix_weights must be NULL or one of \"varying\", \"base_period\", or \"first_period\".") | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
||||||||||||||||||||||
| } | |
| } | |
| if (!panel && !is.null(fix_weights) && | |
| fix_weights %in% c("base_period", "first_period")) { | |
| stop(paste0( | |
| "fix_weights = \"", fix_weights, "\" is not supported when panel = FALSE ", | |
| "(true repeated cross-sections). Use fix_weights = \"varying\" or NULL ", | |
| "for repeated cross-section data." | |
| )) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow attempts to push a commit back to the base branch on the
pull_requestevent. For PRs from forks,GITHUB_TOKENis typically read-only onpull_requestworkflows, sogit pushwill fail. Consider triggering onpushto the default branch (after merge) or usingpull_request_targetwith appropriate hardening, so the workflow can reliably bump the version without permission issues.