Description Usage Arguments Value Examples
panelData_Trans
provides a wide variety of ways of data transformation for panel datasets, such as fixid
effect and pooling model. It allows users to only apply transformation on regressors of interests, instead of
on the entire dataset. See details in https://CRAN.R-project.org/package=plm.
1 2 | panelData_Trans(data, yvar, xvar, effect = "individual",
model = "within", index = NULL, transY = TRUE)
|
data |
A data frame (will be automatically transferred to panel data frame) or a panel data frame |
yvar |
Column name in |
xvar |
Column names in |
effect |
The effects introduced in the model, one of "individual", "time", "twoways" and "nested". Default to "individual". |
model |
Model of estimation, one of "pooling" (pooled OLS), "within" (fixed effect), "between" (group mean),
"random"(random effect), "fd" (first differences) and "ht" (Hausman-Taylor estimator). Default to "within". Notice that when
|
index |
A vector of two character strings which contains the names of the individual and of the time indices, sequentially. If only individual index is given, treat each observation within a unit as a time point. If no index is given, the first two columns will be automatically treated as individual and time indices, sequentially. |
transY |
Logical. If |
|
Transformed panel data |
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 | ## Not run:
#***************************************************************************************
# Examples of Panel Data Transformation
data(Grunfeld, package = "plm")
data(comSample.wmT.bA.bY_list)
pData <- comSample.wmT.bA.bY_list$comSample.wmT.bA.bY
#***************************************************************************************
# 1. Fixed effect transformation ("within") where individual effect is introduced
pData.FE <- panelData_Trans(data = pData, xvar = c("E1", "E2", "W1", "W2", "W3", "A"),
yvar = "Y", index = "id", effect = "individual",
model = "within", transY = TRUE)
# "E1", E2" and "A" are removed since they are constant in community level
names(pData.FE) # "Y" "W1" "W2" "W3"
head(pData.FE)
# 2. Same as example 1 but not transforming the outcome variable
pData.FE.fixY <- panelData_Trans(data = pData, xvar = c("E1", "E2", "W1", "W2", "W3", "A"),
yvar = "Y", index = "id", effect = "individual",
model = "within", transY = FALSE)
all.equal(pData.FE.fixY$Y, pData$Y) # TRUE
# 3. Same as example 2 but different yvar and xvar
pData.FE.fixY.2 <- panelData_Trans(data = pData, xvar = c("E1", "E2", "W1", "W2", "W3"),
yvar = "A", index = "id", transY = FALSE)
# 4. Pooled OLS transformation ("pooling") where individual effect is introduced
pData.pool <- panelData_Trans(data = pData, xvar = c("E1", "E2", "W1", "W2", "W3", "A"),
yvar = "Y", index = "id", effect = "individual",
model = "pooling", transY = TRUE)
names(pData.pool) # Y" "(Intercept)" "E1" "E2" "W1" "W2" "W3" "A"
# 5. Random effect transformation ("random") where time effect is introduced
Grunfeld.RE <- panelData_Trans(yvar = "inv", xvar = c("value", "capital"), data = Grunfeld,
effect = "time", model = "random", index = "year")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.