I have 13 waves of dataset. I standardised the col names so that all matches. Currently, I try to make a panel dataset having the col of pidp as the identifier col and also I added wave col to indicate year of each dataset.
# List of datasets
datasets <- list(c_merged, e_merged, g_merged)
# Combine the datasets into one panel dataset
panel_data <- bind_rows(datasets)
# View the combined panel dataset
print(panel_data)
when I used the code above, it only combines the datasets but doesnt match based on pidp identifier.
I also tried a chatgpt pivot longer code given below:
long_data <- combined_data %>%
pivot_longer(
cols = -c(pidp, wave), # Exclude pidp and wave from pivoting
names_to = "variable", # New column to hold the variable names
values_to = "value" # New column to hold the values of the variables
)
however, this also doesnt work. can you help me?
df |> pivot_longer(-pidp, names_to = c("col", "wave"), names_sep = "_")
), and then bind rows. The specifics will depend on how you want to load the data and what output format you want.