Dataset and R script
#Written by Rohan Byanjankar
#Convert pooled data to panel data
#www.rohanbyanjankar.com.np
#Install and import packages
library(readxl)
library(ggplot2)
library(dplyr)
library(tidyverse)
library(writexl)
library(reshape)
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`))
#Main command begins
attach(pooled1)
panel_melt <- melt(pooled1,`Country Name`=c("Country Name"))
#Main command ends
#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())
Post a Comment