fixef.plm: Extract the Fixed Effects

View source: R/tool_ranfixef.R

fixef.plmR Documentation

Extract the Fixed Effects

Description

Function to extract the fixed effects from a plm object and associated summary method.

Usage

## S3 method for class 'plm'
fixef(
  object,
  effect = NULL,
  type = c("level", "dfirst", "dmean"),
  vcov = NULL,
  ...
)

## S3 method for class 'fixef'
print(
  x,
  digits = max(3, getOption("digits") - 2),
  width = getOption("width"),
  ...
)

## S3 method for class 'fixef'
summary(object, ...)

## S3 method for class 'summary.fixef'
print(
  x,
  digits = max(3, getOption("digits") - 2),
  width = getOption("width"),
  ...
)

## S3 method for class 'pggls'
fixef(
  object,
  effect = NULL,
  type = c("level", "dfirst", "dmean"),
  vcov = NULL,
  ...
)

Arguments

effect

one of "individual", "time", or "twoways", only relevant in case of two–ways effects models (where it defaults to "individual"),

type

one of "level", "dfirst", or "dmean",

vcov

a variance–covariance matrix furnished by the user or a function to calculate one (see Examples),

...

further arguments.

x, object

an object of class "plm", an object of class "fixef" for the print and the summary method,

digits

digits,

width

the maximum length of the lines in the print output,

Details

Function fixef calculates the fixed effects and returns an object of class c("fixef", "numeric"). By setting the type argument, the fixed effects may be returned in levels ("level"), as deviations from the first value of the index ("dfirst"), or as deviations from the overall mean ("dmean"). If the argument 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 effect controls which of the fixed effects are to be extracted: "individual", "time", or the sum of individual and time effects ("twoways"). NB: See 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 effect is disrespected.

The associated summary method returns an extended object of class c("summary.fixef", "matrix") with more information (see sections Value and Examples).

References with formulae (except for the two-ways unbalanced case) are, e.g., \insertCiteGREE:12;textualplm, Ch. 11.4.4, p. 364, formulae (11-25); \insertCiteWOOL:10;textualplm, Ch. 10.5.3, pp. 308-309, formula (10.58).

Value

For function fixef, an object of class c("fixef", "numeric") is returned: It is a numeric vector containing the fixed effects with attribute se which contains the standard errors. There are two further attributes: attribute type contains the chosen type (the value of argument type as a character); attribute df.residual holds the residual degrees of freedom (integer) from the fixed effects model (plm object) on which fixef was run. For the two-way unbalanced case, only attribute type is added.

For function summary.fixef, an object of class 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 fixef function by arguments type and vcov, respectively.

Author(s)

Yves Croissant

References

\insertAllCited

See Also

within_intercept() for the overall intercept of fixed effect models along its standard error, plm() for plm objects and within models (= fixed effects models) in general. See ranef() to extract the random effects from a random effects model.

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


plm documentation built on June 22, 2024, 6:54 p.m.