powered by
This function takes a time-invariant variable and repeats it for each period in a panel data set.
time_invariant_to_panel(x, df, idname, balanced_panel = TRUE)
a vector of length equal to the number of rows in df.
a vector of length equal to the number of unique ids in df.
the data.frame used in the function
name of column that holds the unit id
a logical indicating whether the panel is balanced. If TRUE, the function will optimize the repetition process. Default is TRUE.
n <- 50 id <- rep(seq_len(n), each = 4) t <- rep(1:4, n) dta <- data.frame(id = id, t = t) x_unit <- rnorm(n) x_panel <- time_invariant_to_panel(x_unit, dta, idname = "id") length(x_panel) ## n * 4
Run the code above in your browser using DataLab