panelData_Trans: Panel Dataset Transformation, Using Individual (and Time)...

Description Usage Arguments Value Examples

View source: R/DatKeepClass.R

Description

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.

Usage

1
2
panelData_Trans(data, yvar, xvar, effect = "individual",
  model = "within", index = NULL, transY = TRUE)

Arguments

data

A data frame (will be automatically transferred to panel data frame) or a panel data frame

yvar

Column name in data of outcome variable (Currently only support univariate).

xvar

Column names in data of explanatory variables (Including (A, W, E)).

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 model = "random", "swar" is chosen as the method of estimation for the variance components

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 TRUE, indicate the outcome variable yvar will also be tranformed. Default to TRUE.

Value

newdata

Transformed panel data

Examples

 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)

chizhangucb/tmleCommunity documentation built on May 20, 2019, 3:34 p.m.