install.packages(“WDI”)
install.packages(“plm”)
install.packages(“dplyr”)
install.packages(“Hmisc”)
install.packages(“psych”)
install.packages(“stargazer”)
install.packages(“ggplot2”)
library(WDI)
library(plm)
library(dplyr)
library(Hmisc)
library(psych)
library(stargazer)
library(ggplot2)
install.packages(“WDI”)
library(WDI)
Sheet=WDI(country = c(“ITA”,“FRA”,“DEU”,“HUN”,“DNK”,“ROU”,“NOR”,“EGY”,“USA”,“JPN”) ,indicator =c(“NE.GDI.TOTL.ZS”,“NY.GDP.TOTL.RT.ZS”,“GC.XPN.TOTL.GD.ZS”,“NE.EXP.GNFS.ZS”,“NY.GDS.TOTL.ZS”) ,start = 2005, end = 2022, extra = “false”)
colnames(Sheet)=c(“country”,“Abb1”,“Abb2”,“year”, “GCF”, “TNRR”, “Expense”, “Exports”, “GDS”)
install.packages(“plm”)
library(plm)
Sheet.p=pdata.frame(Sheet,index=9) # creating new object (Sheet.p) as panel data
install.packages(“dplyer”)
library(dplyr)
average_by_country=Sheet.p %>% group_by(country) %>%
summarise_all(mean,na.rm=TRUE)
average_by_country
average_by_year=Sheet.p %>% group_by(year) %>%
summarise_all(mean,na.rm=TRUE)
average_by_year
install.packages(“Hmisc”)
library(Hmisc)
Package1=describe(Sheet)
Package1
install.packages(“psych”)
library(psych)
Package2= describe(Sheet)
Package2
library(stargazer)
Res <- stargazer(data.frame(Package1), data.frame(Package2), type=“text”)
install.packages(“ggplot2”)
library(ggplot2)
ggplot(average_by_year, aes(x=Expense, y=Exports)) + geom_point(size=2, shape=23)+ # for size and shape of points geom_smooth(method = lm)+ # for the line shape geom_label(aes(label = year), # naming the points size = 2, fill =“pink”, color =“black”)
ggplot(average_by_country, aes(x=Expense, y=Exports))+ geom_point(size=2, shape=23)+ # for size and shape of points geom_smooth(method=lm)+ # for the line shape geom_label(aes(label = country), # naming the points size = 3, fill = “pink”, color = “black”)
hist(average_by_country)
hist(average_by_year)
library(ggplot2)
ggplot(Sheet.p, aes(x = year, y = Expense, color = country, group =
country)) + geom_line(size = 1) +
geom_point(size = 2, alpha = .8) + scale_color_discrete(name =
“Country”) + theme_minimal(base_size = 10) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title =
“Expense (%GDP) Over Time by Country”, x = “Year”, y = “Expense”)
ggplot(Sheet.p, aes(x = year, y = GCF, color = country, group = country)) + geom_line(size = 1) + geom_point(size = 2, alpha = 0.8) + scale_color_discrete(name = “Country”) + theme_minimal(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = “Groos capital formation (%GDP) Over Time by Country”, x = “Year”, y = “GCF”)
ggplot(Sheet.p, aes(x = year, y = TNRR, color = country, group = country)) + geom_line(size = 1) + geom_point(size = 2, alpha = 0.8) + scale_color_discrete(name = “Country”) + theme_minimal(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = “Total natural resources rent (%GDP) Over Time by Country”, x = “Year”, y = “TNRR”)
ggplot(Sheet.p, aes(x = year, y = Exports, color = country, group = country)) + geom_line(size = 1) + geom_point(size = 2, alpha = 0.8) + scale_color_discrete(name = “Country”) + theme_minimal(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = “Exports and imports (%GDP) Over Time by Country”, x = “Year”, y = “Exports”)
ggplot(Sheet.p, aes(x = year, y = GDS, color = country, group = country)) + geom_line(size = 1) + geom_point(size = 2, alpha = 0.8) + scale_color_discrete(name = “Country”) + theme_minimal(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(title = “Gross domestic saving (%GDP) Over Time by Country”, x = “Year”, y = “GDS”)
library(dplyr)
str(Sheet.p)
Sheet.p = Sheet.p[!is.na(Sheet.p$Exports), ]
Sheet.p = Sheet.p %>% group_by(country) %>% mutate(Exports = as.numeric(Exports)) #changes the Exports column to numeric type
ggplot(data = Sheet.p, aes(x = country, y = Exports, fill = country)) + geom_boxplot() + labs(title = “Exports and imports”, x = “Country”, y = “Exports and Imports (% of GDP)”) + theme_minimal() + theme( strip.background = element_rect(fill = “grey”, color = NA), #gives grey background to strip labels strip.text = element_text(face = “bold”), #bold text axis.text.x = element_text(angle = 45, hjust = 1), #x axis text angel panel.grid.minor = element_blank())