0

I want to recode a set of GDP data, but I can't find a command that gets it into a format that I could merge into my other data sets.

The data currently looks like

Country Name 1960 1961
Aruba 5,000,000 5,400,000

And so on for each year, but I need it to look like

Country name Year Amount
Aruba 1960 5,000,000
Aruba 1961 5,400,000

I've been screwing with the data with r, excel, and SPSS, and I don't know how to do this in any of them. Any advice would be appreciated.

some dude
  • 3
  • 1
  • `tidyr::pivot_longer(df, cols = -Country_Name)` – Ronak Shah May 02 '21 at 01:28
  • Okay, I did that, now I just have one minor hiccup. It put an x in front of the year names when I imported the data for some reason. Instead of saying 1996 it says X1996 and so on. – some dude May 02 '21 at 01:47
  • The obvious fix would recoding the import to not add the X. If you cannot do that R "coerces" types silently. Thus, with X+number you created now a character variable (or strings). You can manipulate characters/strings with multiple approaches. Here a simple "replace with empty" like `gsub(x = "Year", pattern = "X", replacement = "") will help. – Ray May 02 '21 at 09:50
  • In SPSS you can use the `varstocases` command. Like this: `varstocases /make year from var1 to varn /index=ivar(year).` – pm-b May 02 '21 at 20:01

0 Answers0