### Load etwfe Package and Data in R Source: https://github.com/grantmcdermott/etwfe/blob/main/README.md Loads the 'etwfe' R package into the current session, making its functions available for use. It also loads some example data, likely for demonstration or testing purposes. ```r library(etwfe) ``` -------------------------------- ### Install etwfe Package from CRAN Source: https://github.com/grantmcdermott/etwfe/blob/main/README.md Installs the 'etwfe' R package from the Comprehensive R Archive Network (CRAN). This is the standard method for obtaining stable releases of R packages. ```r install.packages("etwfe") ``` -------------------------------- ### Install etwfe Development Version from R-universe Source: https://github.com/grantmcdermott/etwfe/blob/main/README.md Installs the development version of the 'etwfe' R package from the R-universe repository. This allows users to access the latest features and bug fixes, though it may be less stable than the CRAN version. ```r install.packages("etwfe", repos = "https://grantmcdermott.r-universe.dev") ``` -------------------------------- ### Lighten emfx() Return Object with lean Argument Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `emfx` function now has a `lean` argument (logical). When set to `TRUE`, it returns a lighter object by stripping away data-heavy attributes like copies of the original model. This can be beneficial for memory management, especially in workflows where these attributes are not strictly necessary. The default is `FALSE`, but it may change in future versions. ```r emfx(..., lean = ) ``` -------------------------------- ### Plotting emfx() Objects with tinyplot Backend Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md Version 0.5.0 introduces a native `plot.emfx()` method that uses a `tinyplot` backend for visualizing `emfx` objects. This provides a streamlined way to generate plots directly from the results of `emfx` analyses. ```r plot(emfx_object) ``` -------------------------------- ### Estimate Heterogeneous Treatment Effects with etwfe Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md This functionality allows for the estimation of heterogeneous treatment effects by specifying a covariate via the `xvar` argument in the `etwfe` function. It also extends to the `emfx` function through the `by_xvar` argument. The output provides detailed information on these effects, with dedicated sections in the vignette and help documentation for further guidance. ```r etwfe(y ~ x, xvar = "covariate_name", data = your_data) emfx(..., by_xvar = "covariate_name") ``` -------------------------------- ### Compress Data in emfx() with compress Argument Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `emfx` function utilizes a `compress` argument (defaulting to `TRUE`) to optimize the return object by compressing data. This feature addresses a bug where superfluous factor or character columns could cause failure in the compression step. The `compress` argument replaces the older `collapse` argument for consistency with literature on within-group compression and weighting. ```r emfx(..., compress = TRUE) ``` -------------------------------- ### Update emfx Output Formatting Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md Following updates to the 'marginaleffects' package (version 0.9.0), the 'emfx' objects no longer require `summary()` for pretty printing. The former 'dydx' column is now named 'estimate', simplifying the interpretation of results. ```r # Previous versions might have required: # summary(emfx_object) # With updated marginaleffects, pretty printing is automatic: emfx_object # The output column previously named 'dydx' is now 'estimate' ``` -------------------------------- ### Restrict Temporal Window with emfx() argument Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `emfx` function now includes a `window` argument allowing users to specify a numeric value to restrict the temporal window around a treatment event. This is useful for narrowing the consideration horizon, especially when dealing with a large number of pre- or post-treatment periods. It helps in focusing the analysis on a specific timeframe relevant to the treatment effect. ```r emfx(..., window = ) ``` -------------------------------- ### Adjust etwfe Argument Order for Shorter Notation Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The position of the optional `ivar` argument in the `etwfe()` function has been moved to the fifth argument, after `data`. This change allows for a more compact, unnamed notation for the four required arguments, enabling calls like `etwfe(y ~ x, year, cohort, dat)`. ```r # Previous order might have been: etwfe(y ~ x, ivar = "iv", data = dat, ...) # New order allows for shorter notation: etwfe(y ~ x, year_var, cohort_var, data = dat, ivar = "iv") # Or even shorter when ivar is not used: etwfe(y ~ x, year_var, cohort_var, dat) ``` -------------------------------- ### Reduce Estimation Time with etwfe and emfx collapse argument Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `collapse = TRUE` argument in the `emfx` function can significantly decrease estimation times for large datasets. While this may lead to a minor trade-off in accuracy, it is generally negligible for typical use cases. For even greater speed improvements, consider combining this with `vcov = FALSE`, though this will omit standard errors. ```r emfx(..., collapse = TRUE) emfx(..., collapse = TRUE, vcov = FALSE) ``` -------------------------------- ### Handle Model Offsets with etwfe Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md This fix addresses an internal and upstream bug that caused model offsets to error. The fix requires a specific version of the 'insight' package (>= 0.19.1.8, development version at the time of writing). More details can be found in the linked 'insight' package pull request. ```r # Ensure insight package is updated to version >= 0.19.1.8 # install.packages("remotes") # remotes::install_github("easystats/insight") etwfe(y ~ x, data = your_data, offset = your_offset_variable) ``` -------------------------------- ### Estimate Two-Way Fixed Effects Model with Saturated Interactions (R) Source: https://github.com/grantmcdermott/etwfe/blob/main/README.md This code snippet demonstrates how to estimate a two-way fixed effects model using the `etwfe` function from the 'did' package in R. It specifies the outcome variable, control variables, time variable, group variable, dataset, and a clustering adjustment for standard errors. The output includes model coefficients, standard errors, and significance codes. ```r library(did) data("mpdta", package = "did") mod = etwfe( fml = lemp ~ lpop, # outcome ~ controls tvar = year, # time variable gvar = first.treat, # group variable data = mpdta, # dataset vcov = ~countyreal # vcov adjustment (here: clustered) ) mod ``` -------------------------------- ### Indicate No Control Variables in etwfe Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `etwfe` function now accepts a '1' on the right-hand side of the formula to indicate the absence of control variables, providing an alternative to the existing '0' option. This simplifies model specification when no controls are needed. ```r etwfe(y ~ 1, data = your_data) etwfe(y ~ 0, data = your_data) ``` -------------------------------- ### Control Prediction Type in emfx() Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `emfx` function in version 0.5.0 introduces the `predict` argument, which can be set to either "response" or "link". Setting `predict` to "link" allows for obtaining the linear prediction for non-linear models. This functionality is passed internally to `marginaleffects::slopes()` and helps avoid conflicts with the `emfx(..., type = )` argument. ```r emfx(..., predict = c("response", "link")) ``` -------------------------------- ### Default Fixed-Effect Behavior in etwfe() Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The default behavior of the `etwfe(..., fe = )` argument has been updated based on the model family. For Gaussian models, it defaults to "vs" (varying slopes). For non-linear families like Poisson, it now defaults to "none" to ensure correct VCOV behavior when passed to `emfx()`, aligning with upstream `marginaleffects` logic. This change primarily affects standard error calculations for non-linear models. ```r etwfe(..., fe = ) ``` -------------------------------- ### Recover Event Study Effects from Fixed Effects Model (R) Source: https://github.com/grantmcdermott/etwfe/blob/main/README.md This code snippet shows how to use the `emfx` function to recover event study effects from a previously estimated two-way fixed effects model object (`mod`). The `type = "event"` argument specifies that event study effects should be calculated. The output table displays the estimated effects, standard errors, p-values, and confidence intervals for different event periods. ```r emfx(mod, type = "event") ``` -------------------------------- ### Modify .Dtreat Indicator Variable in etwfe Source: https://github.com/grantmcdermott/etwfe/blob/main/NEWS.md The `.Dtreat` indicator variable generated during the `etwfe` call has been changed from integer to logical. This modification may result in slightly different effect sizes for `emfx` output, particularly with non-linear model families like 'poisson', due to the internal use of `marginaleffects::comparisons` instead of `marginaleffects::marginaleffects`. ```r # The .Dtreat variable is now logical. # Example usage of etwfe: etwfe(y ~ x, data = your_data, family = "poisson") # Applying emfx to the result: emfx(etwfe_result) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.