-1

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?

part of data

2
  • 2
    Hi, welcome to stack overflow! The expectation here is that you should have attempted some research, tried some code, and provided some data as text. As is, your question is not very specific ("make a panel out of it") and you have only provided a screenshot from excel, and you are asking for someone to write a detailed custom tutorial for you. stackoverflow.com/collectives/r-language/articles/76995406/…
    – Jon Spring
    Commented Jun 24 at 23:18
  • Load the datasets into a list, then pivot_longer each to a data.frame denoted by wave (e.g. 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.
    – Jon Spring
    Commented Jun 25 at 0:04

0

Browse other questions tagged or ask your own question.