2

I have several datasets which look roughly like this ones. I would like to transform into a proper panel dataset to run regressions and random forests.

However, I am struggling to put the years into a column. Thank you very much in advance

First column: Country Second column: Year Third: consumption expenditure Fourth: Household consumption

Picture of one of my datasets

1 Answers1

2

tidyr's pivot_ functions should do the trick

library(tidyverse)

data_raw <- ... # import data

panel <- data_raw %>%
  pivot_longer(1970:1984, names_to = 'year')

Pedro Cavalcante
  • 414
  • 4
  • 14