panel_dummify {panelWranglR} | R Documentation |
Tidy time/variable dummies for panel data
Description
A simple function to dummify cross sections or time variables in panel data.
Usage
panel_dummify(data, cross.section = NULL, time.variable = NULL)
Arguments
data |
The panel to dummify |
cross.section |
The cross section variable in the panel. Defaults to NULL. |
time.variable |
The variable to indicate time in your panel. Defaults to NULL. |
Details
The encoding is binary, whether this is more appropriate than using a factor variable is up to the user.
Value
A new data.table, with the original variables to dummify removed, and new dummy columns included.
Examples
x_1 <- rnorm( 10 )
cross_levels <- c( "AT", "DE" )
time <- seq(1:5)
time <- rep(time, 2)
geo_list <- list()
for(i in 1:length(cross_levels))
{
geo <- rep( cross_levels[i],
100 )
geo_list[[i]] <- geo
}
geo <- unlist(geo_list)
geo <- as.data.frame(geo)
example_data <- cbind( time,
x_1 )
example_data <- as.data.frame(example_data)
example_data <- cbind( geo,
example_data)
names(example_data) <- c("geo", "time", "x_1")
test_dummies <- panel_dummify( data = example_data,
cross.section = "geo",
time.variable = "time")
[Package panelWranglR version 1.2.13 Index]