1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tool_ranfixef.R
\name{fixef.plm}
\alias{fixef.plm}
\alias{fixef}
\alias{print.fixef}
\alias{summary.fixef}
\alias{print.summary.fixef}
\alias{fixef.pggls}
\title{Extract the Fixed Effects}
\usage{
\method{fixef}{plm}(
object,
effect = NULL,
type = c("level", "dfirst", "dmean"),
vcov = NULL,
...
)
\method{print}{fixef}(
x,
digits = max(3, getOption("digits") - 2),
width = getOption("width"),
...
)
\method{summary}{fixef}(object, ...)
\method{print}{summary.fixef}(
x,
digits = max(3, getOption("digits") - 2),
width = getOption("width"),
...
)
\method{fixef}{pggls}(
object,
effect = NULL,
type = c("level", "dfirst", "dmean"),
vcov = NULL,
...
)
}
\arguments{
\item{effect}{one of \code{"individual"}, \code{"time"}, or \code{"twoways"}, only relevant in
case of two--ways effects models (where it defaults to \code{"individual"}),}
\item{type}{one of \code{"level"}, \code{"dfirst"}, or \code{"dmean"},}
\item{vcov}{a variance--covariance matrix furnished by the user or
a function to calculate one (see \strong{Examples}),}
\item{\dots}{further arguments.}
\item{x, object}{an object of class \code{"plm"}, an object of class
\code{"fixef"} for the \code{print} and the \code{summary} method,}
\item{digits}{digits,}
\item{width}{the maximum length of the lines in the print output,}
}
\value{
For function \code{fixef}, an object of class \code{c("fixef", "numeric")}
is returned: It is a numeric vector containing
the fixed effects with attribute \code{se} which contains the
standard errors. There are two further attributes: attribute
\code{type} contains the chosen type (the value of argument \code{type}
as a character); attribute \code{df.residual} holds the residual
degrees of freedom (integer) from the fixed effects model (plm
object) on which \code{fixef} was run. For the two-way unbalanced case, only
attribute \code{type} is added.
For function \code{summary.fixef}, an object of class
\code{c("summary.fixef", "matrix")} is returned: It is a matrix with four
columns in this order: the estimated fixed effects, their standard
errors and associated t--values and p--values.
For the two-ways unbalanced case, the matrix contains only the estimates.
The type of the fixed effects and the standard errors in the
summary.fixef object correspond to was requested in the \code{fixef}
function by arguments \code{type} and \code{vcov}, respectively.
}
\description{
Function to extract the fixed effects from a \code{plm} object and
associated summary method.
}
\details{
Function \code{fixef} calculates the fixed effects and returns an object
of class \code{c("fixef", "numeric")}. By setting the \code{type} argument,
the fixed effects may be returned in levels (\code{"level"}), as
deviations from the first value of the index (\code{"dfirst"}), or as
deviations from the overall mean (\code{"dmean"}). If the argument
\code{vcov} was specified, the standard errors (stored as attribute "se"
in the return value) are the respective robust standard errors.
For two-way fixed-effect models, argument \code{effect} controls which
of the fixed effects are to be extracted: \code{"individual"}, \code{"time"}, or
the sum of individual and time effects (\code{"twoways"}).
NB: See \strong{Examples} for how the sum of effects can be split in an individual
and a time component.
For one-way models, the effects of the model are extracted and the
argument \code{effect} is disrespected.
The associated \code{summary} method returns an extended object of class
\code{c("summary.fixef", "matrix")} with more information (see sections
\strong{Value} and \strong{Examples}).
References with formulae (except for the two-ways unbalanced case)
are, e.g., \insertCite{GREE:12;textual}{plm}, Ch. 11.4.4, p. 364,
formulae (11-25); \insertCite{WOOL:10;textual}{plm}, Ch. 10.5.3,
pp. 308-309, formula (10.58).
}
\examples{
data("Grunfeld", package = "plm")
gi <- plm(inv ~ value + capital, data = Grunfeld, model = "within")
fixef(gi)
summary(fixef(gi))
summary(fixef(gi))[ , c("Estimate", "Pr(>|t|)")] # only estimates and p-values
# relationship of type = "dmean" and "level" and overall intercept
fx_level <- fixef(gi, type = "level")
fx_dmean <- fixef(gi, type = "dmean")
overallint <- within_intercept(gi)
all.equal(overallint + fx_dmean, fx_level, check.attributes = FALSE) # TRUE
# extract time effects in a twoways effects model
gi_tw <- plm(inv ~ value + capital, data = Grunfeld,
model = "within", effect = "twoways")
fixef(gi_tw, effect = "time")
# with supplied variance-covariance matrix as matrix, function,
# and function with additional arguments
fx_level_robust1 <- fixef(gi, vcov = vcovHC(gi))
fx_level_robust2 <- fixef(gi, vcov = vcovHC)
fx_level_robust3 <- fixef(gi, vcov = function(x) vcovHC(x, method = "white2"))
summary(fx_level_robust1) # gives fixed effects, robust SEs, t- and p-values
# calc. fitted values of oneway within model:
fixefs <- fixef(gi)[index(gi, which = "id")]
fitted_by_hand <- fixefs + gi$coefficients["value"] * gi$model$value +
gi$coefficients["capital"] * gi$model$capital
# calc. fittes values of twoway unbalanced within model via effects:
gtw_u <- plm(inv ~ value + capital, data = Grunfeld[-200, ], effect = "twoways")
yhat <- as.numeric(gtw_u$model[ , 1] - gtw_u$residuals) # reference
pred_beta <- as.numeric(tcrossprod(coef(gtw_u), as.matrix(gtw_u$model[ , -1])))
pred_effs <- as.numeric(fixef(gtw_u, "twoways")) # sum of ind and time effects
all.equal(pred_effs + pred_beta, yhat) # TRUE
# Splits of summed up individual and time effects:
# use one "level" and one "dfirst"
ii <- index(gtw_u)[[1L]]; it <- index(gtw_u)[[2L]]
eff_id_dfirst <- c(0, as.numeric(fixef(gtw_u, "individual", "dfirst")))[ii]
eff_ti_dfirst <- c(0, as.numeric(fixef(gtw_u, "time", "dfirst")))[it]
eff_id_level <- as.numeric(fixef(gtw_u, "individual"))[ii]
eff_ti_level <- as.numeric(fixef(gtw_u, "time"))[it]
all.equal(pred_effs, eff_id_level + eff_ti_dfirst) # TRUE
all.equal(pred_effs, eff_id_dfirst + eff_ti_level) # TRUE
}
\references{
\insertAllCited{}
}
\seealso{
\code{\link[=within_intercept]{within_intercept()}} for the overall intercept of fixed
effect models along its standard error, \code{\link[=plm]{plm()}} for plm objects
and within models (= fixed effects models) in general. See
\code{\link[=ranef]{ranef()}} to extract the random effects from a random effects
model.
}
\author{
Yves Croissant
}
\keyword{regression}
|