-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correct bug with fixed effects extraction
- Loading branch information
1 parent
bc9d596
commit f7e4d24
Showing
4 changed files
with
81 additions
and
9 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
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,46 @@ | ||
load_all() | ||
|
||
object <- fepoisson(cyl ~ mpg | am, data = mtcars) | ||
|
||
alpha.tol <- 1.0e-08 | ||
|
||
if (is.null(object)) { | ||
stop("'object' has to be specified.", call. = FALSE) | ||
} else if (isFALSE(inherits(object, "felm")) && | ||
isFALSE(inherits(object, "feglm"))) { | ||
stop( | ||
"'fixed_effects' called on a non-'felm' or non-'feglm' object.", | ||
call. = FALSE | ||
) | ||
} | ||
|
||
# Extract required quantities from result list | ||
beta <- object[["coefficients"]] | ||
data <- object[["data"]] | ||
formula <- object[["formula"]] | ||
lvls.k <- object[["lvls.k"]] | ||
nms.fe <- object[["nms.fe"]] | ||
k.vars <- names(lvls.k) | ||
k <- length(lvls.k) | ||
eta <- object[["eta"]] | ||
|
||
# Extract regressor matrix | ||
X <- model.matrix(formula, data, rhs = 1L)[, -1L, drop = FALSE] | ||
nms.sp <- attr(X, "dimnames")[[2L]] | ||
attr(X, "dimnames") <- NULL | ||
|
||
# Generate auxiliary list of indexes for different sub panels | ||
k.list <- get_index_list_(k.vars, data) | ||
|
||
# Recover fixed effects by alternating the solutions of normal equations | ||
pie <- eta - solve_y_(X, beta) | ||
|
||
fe.list <- as.list(get_alpha_(pie, k.list, alpha.tol)) | ||
|
||
for (i in seq.int(k)) { | ||
fe.list[[i]] <- as.vector(fe.list[[i]]) | ||
names(fe.list[[i]]) <- nms.fe[[i]] | ||
} | ||
names(fe.list) <- k.vars | ||
|
||
fe.list |
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