panel_dummify: Tidy time/variable dummies for panel data

Description Usage Arguments Details Value Examples

View source: R/dummify_panel.R

Description

A simple function to dummify cross sections or time variables in panel data.

Usage

1
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

 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
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")

panelWranglR documentation built on Oct. 3, 2019, 9:03 a.m.