R/tool_ranfixef.R
within_intercept.RdThis function gives an overall intercept for within models and its accompanying standard error or a within model with the overall intercept
within_intercept(object, ...)
# S3 method for class 'plm'
within_intercept(object, vcov = NULL, return.model = FALSE, ...)object of class plm which must be a within
model (fixed effects model),
further arguments (currently none).
if not NULL (default), a function to calculate a
user defined variance–covariance matrix (function for robust
vcov), only used if return.model = FALSE,
a logical to indicate whether only the overall intercept
(FALSE is default) or a full model object (TRUE) is to be returned,
Depending on argument return.model: If FALSE (default), a named
numeric of length one: The overall intercept for the estimated within model
along attribute "se" which contains the standard error for the intercept.
If return.model = TRUE, the full model object, a within model with the
overall intercept (NB: the model identifies itself as a pooling model, e.g.,
in summary()).
The (somewhat artificial) intercept for within models (fixed effects models) was made popular by Stata of StataCorp (see Gould 2013) , EViews of IHS, and gretl (see Cottrell and Lucchetti 2021, p. 200-201, listing 23.1) , see for treatment in the literature, e.g., Greene (2012) , Ch. 11.4.4, p. 364. It can be considered an overall intercept in the within model framework and is the weighted mean of fixed effects (see Examples for the relationship).
within_intercept estimates a new model which is
computationally more demanding than just taking the weighted
mean. However, with within_intercept one also gets the
associated standard error and it is possible to get an overall
intercept for two-way fixed effect models.
Users can set argument vcov to a function to calculate a
specific (robust) variance–covariance matrix and get the
respective (robust) standard error for the overall intercept,
e.g., the function vcovHC(), see examples for
usage. Note: The argument vcov must be a function, not a
matrix, because the model to calculate the overall intercept for
the within model is different from the within model itself.
If argument return.model = TRUE is set, the full model object is returned,
while in the default case only the intercept is returned.
Cottrell A, Lucchetti R (2021).
“Gretl User’s Guide.”
https://gretl.sourceforge.net/.
Gould W (2013).
“How can there be an intercept in the fixed-effects model estimated by xtreg, fe?”
https://www.stata.com/support/faqs/statistics/intercept-in-fixed-effects-model/.
Greene WH (2012).
Econometric Analysis, 7th edition.
Prentice Hall.
fixef() to extract the fixed effects of a within model.
data("Hedonic", package = "plm")
mod_fe <- plm(mv ~ age + crim, data = Hedonic, index = "townid")
overallint <- within_intercept(mod_fe)
attr(overallint, "se") # standard error
#> [1] 0.04853606
# overall intercept is the weighted mean of fixed effects in the
# one-way case
weighted.mean(fixef(mod_fe), pdim(mod_fe)$Tint$Ti)
#> [1] 10.25964
### relationship of type="dmean", "level" and within_intercept
## one-way balanced case
data("Grunfeld", package = "plm")
gi <- plm(inv ~ value + capital, data = Grunfeld, model = "within")
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
## two-ways unbalanced case
gtw_u <- plm(inv ~ value + capital, data = Grunfeld[-200, ], effect = "twoways")
int_tw_u <- within_intercept(gtw_u)
fx_dmean_tw_i_u <- fixef(gtw_u, type = "dmean", effect = "individual")[index(gtw_u)[[1L]]]
fx_dmean_tw_t_u <- fixef(gtw_u, type = "dmean", effect = "time")[index(gtw_u)[[2L]]]
fx_level_tw_u <- as.numeric(fixef(gtw_u, "twoways", "level"))
fx_level_tw_u2 <- int_tw_u + fx_dmean_tw_i_u + fx_dmean_tw_t_u
all.equal(fx_level_tw_u, fx_level_tw_u2, check.attributes = FALSE) # TRUE
#> [1] TRUE
## overall intercept with robust standard error
within_intercept(gi, vcov = function(x) vcovHC(x, method="arellano", type="HC0"))
#> (overall_intercept)
#> -58.74394
#> attr(,"se")
#> [1] 26.05445
## have a model returned
mod_fe_int <- within_intercept(gi, return.model = TRUE)
summary(mod_fe_int)
#> Pooling Model
#>
#> Call:
#> plm(formula = form, data = data, model = "pooling")
#>
#> Balanced Panel: n = 10, T = 20, N = 200
#>
#> Residuals:
#> Min. 1st Qu. Median 3rd Qu. Max.
#> -184.00857 -17.64316 0.56337 19.19222 250.70974
#>
#> Coefficients:
#> Estimate Std. Error t-value Pr(>|t|)
#> (Intercept) -58.743939 12.453692 -4.7170 4.527e-06 ***
#> value 0.110124 0.011857 9.2879 < 2.2e-16 ***
#> capital 0.310065 0.017355 17.8666 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Total Sum of Squares: 2244400
#> Residual Sum of Squares: 523480
#> R-Squared: 0.76676
#> Adj. R-Squared: 0.76439
#> F-statistic: 309.014 on 2 and 197 DF, p-value: < 2.22e-16
# replicates Stata's robust standard errors exactly as model is with intercept
summary(mod_fe_int, vcov = function(x) vcovHC(x, type = "sss"))
#> Pooling Model
#>
#> Note: Coefficient variance-covariance matrix supplied: function(x) vcovHC(x, type = "sss")
#>
#> Call:
#> plm(formula = form, data = data, model = "pooling")
#>
#> Balanced Panel: n = 10, T = 20, N = 200
#>
#> Residuals:
#> Min. 1st Qu. Median 3rd Qu. Max.
#> -184.00857 -17.64316 0.56337 19.19222 250.70974
#>
#> Coefficients:
#> Estimate Std. Error t-value Pr(>|t|)
#> (Intercept) -58.743939 27.602865 -2.1282 0.03456 *
#> value 0.110124 0.015194 7.2476 9.405e-12 ***
#> capital 0.310065 0.052752 5.8778 1.751e-08 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Total Sum of Squares: 2244400
#> Residual Sum of Squares: 523480
#> R-Squared: 0.76676
#> Adj. R-Squared: 0.76439
#> F-statistic: 28.3096 on 2 and 9 DF, p-value: 0.00013105