Skip to content

Add support for plm #106

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method(boottest,felm)
S3method(boottest,fixest)
S3method(boottest,ivreg)
S3method(boottest,lm)
S3method(boottest,plm)
S3method(confint,boottest)
S3method(glance,boottest)
S3method(glance,mboottest)
Expand Down
24 changes: 24 additions & 0 deletions R/arg_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ check_boottest_args_plus <- function(
}
}


if(inherits(object, "plm")){

if (!is.null(fe)) {
if (fe %in% param) {
rlang::abort(paste("The function argument fe =", fe, "is included in the
hypothesis (via the `param` argument). This is not allowed.
Please set fe to another factor variable or NULL."),
call. = FALSE
)
}
if (!(fe %in% names(index(object)))) {
rlang::abort(paste(
"The fixed effect to be projected out in the bootstrap,",
fe, "is not included as a dedicated fixed effect
in the estimated model."
))
}
}


}


if (((1 - sign_level) * (B + 1)) %% 1 != 0) {
rlang::inform(
paste("Note: The bootstrap usually performs best when the confidence",
Expand Down
1 change: 1 addition & 0 deletions R/boottest_fixest.R
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ boottest.fixest <- function(object,
type = type,
engine = engine
)

full_enumeration <- enumerate$full_enumeration
B <- enumerate$B

Expand Down
641 changes: 641 additions & 0 deletions R/boottest_plm.r

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions R/model_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,54 @@ model_matrix <- function(object, ...) {
UseMethod("model_matrix")
}

model_matrix.plm <- function(object, type, collin.rm = TRUE, ...) {
#' Enhanced model.matrix for objects of type plm
#' @method model_matrix plm
#' @param object An object of class plm
#' @param collin.rm Should collinear variables be dropped?
#' @param type 'rhs' for right-hand side variables, 'fixef' for fixed effects
#' @param ... Other arguments
#' @noRd

dreamerr::check_arg(type, "charin(rhs, fixef)")

if (type == "rhs") {
mm <- model.matrix(object)
if (collin.rm == TRUE) {
bn <- names(na.omit(coef(object)))
mm <- mm[, colnames(mm) %in% bn]
}

} else if (type == "fixef") {

mm <- index(object)
model <- object$args$model
effect <- object$args$effect


if(model == "within"){
if(effect == "individual"){
mm <- mm[,1, drop = FALSE]
} else if(effect == "time"){
mm <- mm[,2, drop = FALSE]
}
} else if (model == "between"){
mm <- mm[,2, drop = FALSE]
} else{
stop("The plm object needs to be estimated via 'within' or between
for use with fixed effects. ")
}

# make sure all fixed effect variables are factors
i <- seq_along(mm)
mm[, i] <- lapply(i, function(x) {
factor(mm[, x])
})
}

mm
}


model_matrix.lm <- function(object, collin.rm = TRUE, ...) {
#' Enhanced model.matrix for objects of type lm
Expand Down
Loading