detrend {feisr} | R Documentation |
Detrend data by individual slopes
Description
Detrends the input data by the predicted values based on the slope parameters within each group
specified by id. The result is equal to the transformed data used for estimation in
feis
.
Usage
detrend(
data,
slopes,
id = NULL,
intercept = TRUE,
na.action = c("na.exlude", "na.omit"),
tol = .Machine$double.eps,
predicted = FALSE,
...
)
Arguments
data |
a |
slopes |
a |
id |
a |
intercept |
logical. If |
na.action |
character, either |
tol |
the tolerance for detecting linear dependencies in the residual maker transformation
(see |
predicted |
logical. If |
... |
further arguments. |
Details
detrend
performs within-group "residual maker" transformation on the origin data.
Within each group, the predicted values of the columns in data are computed based on the
slope columns plus an individual intercept if intercept = TRUE
(the default).
Subsequently the predicted values are subtracted from the origin data. The transformed
data can, for instance, be used to obtain coefficients of a fixed effects individual slopes
estimator via lm
(Bruederl and Ludwig 2015; Ruettenauer and Ludwig 2020; Wooldridge 2010).
Estimation requires at least q+1
observations per unit, where q
is the number of slope
parameters (including a constant).
detrend
automatically selects only those groups from the current data set which have
at least q+1
observations, and returns NA for all groups with n_i
< q+1
.
NA
values in the input data are handled by list-wise deletion based on the data to be
detrended and the slopes.
Value
An object of class "data.frame
" or "numeric
(if only one data column),
containing the detrended data with row.names
equal
to the row.names
of the origin data. If input is an unnamed vector, names are 1:length.
References
Bruederl J, Ludwig V (2015).
“Fixed-Effects Panel Regression.”
In Best H, Wolf C (eds.), The Sage Handbook of Regression Analysis and Causal Inference, 327–357.
Sage, Los Angeles.
ISBN 1446252442.
Ruettenauer T, Ludwig V (2020).
“Fixed Effects Individual Slopes: Accounting and Testing for Heterogeneous Effects in Panel Data or Other Multilevel Models.”
Sociological Methods and Research, OnlineFirst.
ISSN 0049-1241, doi: 10.1177/0049124120926211.
Wooldridge JM (2010).
Econometric Analysis of Cross Section and Panel Data.
MIT Press, Cambridge, Mass.
ISBN 0262294354.
See Also
Examples
data("mwp", package = "feisr")
# Detrend entire data.frame
mwp_det <- detrend(data = mwp, slopes = c("exp", "expq"), id = "id")
# Detrend single variable
lnw_det <- detrend(data = mwp$lnw, slopes = mwp[, c("exp", "expq")], id = mwp$id)