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

# 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,

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.

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., Greene (2012) , Ch. 11.4.4, p. 364, formulae (11-25); Wooldridge (2010) , Ch. 10.5.3, pp. 308-309, formula (10.58).

References

Greene WH (2012). Econometric Analysis, 7th edition. Prentice Hall.

Wooldridge JM (2010). Econometric Analysis of Cross–Section and Panel Data, 2nd edition. MIT Press.

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.

Author

Yves Croissant

Examples


data("Grunfeld", package = "plm")
gi <- plm(inv ~ value + capital, data = Grunfeld, model = "within")
fixef(gi)
#>         1         2         3         4         5         6         7         8 
#>  -70.2967  101.9058 -235.5718  -27.8093 -114.6168  -23.1613  -66.5535  -57.5457 
#>         9        10 
#>  -87.2223   -6.5678 
summary(fixef(gi))
#>     Estimate Std. Error t-value  Pr(>|t|)    
#> 1   -70.2967    49.7080 -1.4142   0.15896    
#> 2   101.9058    24.9383  4.0863 6.485e-05 ***
#> 3  -235.5718    24.4316 -9.6421 < 2.2e-16 ***
#> 4   -27.8093    14.0778 -1.9754   0.04969 *  
#> 5  -114.6168    14.1654 -8.0913 7.141e-14 ***
#> 6   -23.1613    12.6687 -1.8282   0.06910 .  
#> 7   -66.5535    12.8430 -5.1821 5.629e-07 ***
#> 8   -57.5457    13.9931 -4.1124 5.848e-05 ***
#> 9   -87.2223    12.8919 -6.7657 1.635e-10 ***
#> 10   -6.5678    11.8269 -0.5553   0.57933    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(fixef(gi))[ , c("Estimate", "Pr(>|t|)")] # only estimates and p-values
#>       Estimate     Pr(>|t|)
#> 1   -70.296717 1.589588e-01
#> 2   101.905814 6.485244e-05
#> 3  -235.571841 3.951420e-18
#> 4   -27.809295 4.968535e-02
#> 5  -114.616813 7.141096e-14
#> 6   -23.161295 6.910077e-02
#> 7   -66.553474 5.629040e-07
#> 8   -57.545657 5.847710e-05
#> 9   -87.222272 1.634506e-10
#> 10   -6.567844 5.793282e-01

# 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
#> [1] 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")
#>    1935    1936    1937    1938    1939    1940    1941    1942    1943    1944 
#>  -86.90 -106.10 -127.59 -126.13 -156.37 -131.14 -105.70 -108.04 -129.88 -130.00 
#>    1945    1946    1947    1948    1949    1950    1951    1952    1953    1954 
#> -142.58 -118.07 -126.29 -130.62 -160.40 -162.80 -149.38 -151.53 -154.62 -180.43 

# 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
#>     Estimate Std. Error t-value  Pr(>|t|)    
#> 1   -70.2967    85.9735 -0.8177 0.4145887    
#> 2   101.9058    40.4965  2.5164 0.0126921 *  
#> 3  -235.5718    44.2724 -5.3210 2.917e-07 ***
#> 4   -27.8093    18.5658 -1.4979 0.1358420    
#> 5  -114.6168    28.8403 -3.9742 0.0001006 ***
#> 6   -23.1613    15.4598 -1.4982 0.1357680    
#> 7   -66.5535    20.7159 -3.2127 0.0015474 ** 
#> 8   -57.5457    17.2617 -3.3337 0.0010321 ** 
#> 9   -87.2223    21.5669 -4.0443 7.654e-05 ***
#> 10   -6.5678    11.8616 -0.5537 0.5804368    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# 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
#> [1] 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
#> [1] TRUE
all.equal(pred_effs, eff_id_dfirst + eff_ti_level)  # TRUE
#> [1] TRUE