Copy and paste this code in Rstudio
#Written by Rohan Byanjankar
#Convert pooled data to panel data
#www.rohanbyanjankar.com.np
#Install and import packages
library(readxl)
library(reshape2)
setwd("D:/~Drive Share (Rohan)/01 Shared Access/~R program/Converting to Panel/")
Pooled <- read_excel(file.choose())
pooled1 <- subset(Pooled,select = -c(`Country Code`,`Indicator Code`,`Indicator Name`))
attach(pooled1)
panel_melt <- melt(pooled1,`Country Name`=c("Country Name"))
#using rename command to change the name of variable
#syntax: rename(new variable name = old variable name)
panel_melt <- panel_melt %>%rename(Year=variable,GDP=value)
write_xlsx(panel_melt,"melt_panel.xlsx")
remove(panel_melt,pooled1)
Pooled_melt <- read_excel(file.choose())
OR
Doing it manually
Post a Comment