require(dplyr)
require(knitr)
require(ggplot2)
require(plotly)

Read data

wb <- read.csv("PanelDataProject.csv")

Whole world temp plot

w <- wb %>% 
        filter(Year %in% 1990 : 2012)

ggplot( w ,aes(x=Year, y=meantemp, color=region)) + geom_point()

IN different Plots

ggplot( w ,aes(x=Year, y=meantemp, group = Country)) + 
  geom_line(size = 0.1) + 
  theme_minimal() + 
  facet_grid( .~ region )

Bangladesh data

bd <- w %>% 
      filter(Country == "Bangladesh") 

Dotplot BD

ggplot( bd ,aes(x=Year, y=meantemp)) + 
  geom_point() + 
  geom_smooth(method = "lm", se = F)
## `geom_smooth()` using formula 'y ~ x'

Lineplot / timeseries BD

ggplot( bd ,aes(x=Year, y=meantemp)) + 
  geom_line(size=2) + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() 
## `geom_smooth()` using formula 'y ~ x'

Asian Countries

asia <- wb %>% 
        filter(region == "ASIA")


ggplot( asia ,aes(x=Year, y=meantemp, color=Country,)) + 
  geom_line(size=0.2) + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() 
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 35 rows containing non-finite values (stat_smooth).
## Warning: Removed 35 row(s) containing missing values (geom_path).

Asian Warm Countries

asiaselected <- wb %>% 
  filter(region == "ASIA", Country %in% c("Bangladesh",
                                          "India",
                                          "Indonesia", 
                                          "Singapore",
                                          "Sri Lanka",
                                          "Maynmar",
                                          "Philippines",
                                          "Thailand"
  ), Year %in% 1990 : 2012 )


ggplot( asiaselected ,aes(x=Year, y=meantemp, color=Country)) + 
  geom_line() +
  labs(title = "Asian Warm Countries Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")

List of Countries

wb[wb$country == ""]
w <- wb %>% 
  select(country, region) %>%
  group_by(country, region) %>%
  summarise(n()) %>% 
  arrange(region, country) %>%
  select(country, region)
## `summarise()` has grouped output by 'country'. You can override using the `.groups` argument.
kable(w, col.names = c("Country", "Continent"))
Country Continent
Algeria AFRICA
Angola AFRICA
Botswana AFRICA
Burundi AFRICA
Cameroon AFRICA
Chad AFRICA
Congo AFRICA
Cote d’Ivoire AFRICA
Egypt AFRICA
Ethiopia AFRICA
Gambia, The AFRICA
Ghana AFRICA
Guinea AFRICA
Kenya AFRICA
Liberia AFRICA
Libya AFRICA
Madagascar AFRICA
Mali AFRICA
Mauritius AFRICA
Morocco AFRICA
Mozambique AFRICA
Namibia AFRICA
Niger AFRICA
Nigeria AFRICA
Rwanda AFRICA
Senegal AFRICA
Sierra Leone AFRICA
Somalia AFRICA
South Africa AFRICA
Sudan AFRICA
Tanzania AFRICA
Tunisia AFRICA
Uganda AFRICA
Zambia AFRICA
Zimbabwe AFRICA
Afghanistan ASIA
Bahrain ASIA
Bangladesh ASIA
Bhutan ASIA
Burma ASIA
Cambodia ASIA
China ASIA
India ASIA
Indonesia ASIA
Iran ASIA
Iraq ASIA
Israel ASIA
Japan ASIA
Jordan ASIA
Kuwait ASIA
Lebanon ASIA
Macau ASIA
Malaysia ASIA
Mongolia ASIA
Nepal ASIA
North Korea ASIA
Oman ASIA
Pakistan ASIA
Philippines ASIA
Qatar ASIA
Saudi Arabia ASIA
Singapore ASIA
South Korea ASIA
Sri Lanka ASIA
Syria ASIA
Thailand ASIA
Turkey ASIA
United Arab Emirates ASIA
Vietnam ASIA
Yemen ASIA
Albania EUROPE
Armenia EUROPE
Austria EUROPE
Azerbaijan EUROPE
Belarus EUROPE
Belgium EUROPE
Bosnia & Herzegovina EUROPE
Bulgaria EUROPE
Croatia EUROPE
Czech Republic EUROPE
Denmark EUROPE
Estonia EUROPE
Faroe Islands EUROPE
Finland EUROPE
France EUROPE
Georgia EUROPE
Germany EUROPE
Greece EUROPE
Hungary EUROPE
Iceland EUROPE
Ireland EUROPE
Italy EUROPE
Kazakhstan EUROPE
Kyrgyzstan EUROPE
Latvia EUROPE
Liechtenstein EUROPE
Lithuania EUROPE
Luxembourg EUROPE
Macedonia EUROPE
Malta EUROPE
Moldova EUROPE
Monaco EUROPE
Netherlands EUROPE
Norway EUROPE
Poland EUROPE
Portugal EUROPE
Romania EUROPE
Russia EUROPE
Serbia EUROPE
Slovakia EUROPE
Slovenia EUROPE
Spain EUROPE
Sweden EUROPE
Switzerland EUROPE
Ukraine EUROPE
United Kingdom EUROPE
Uzbekistan EUROPE
Canada NORTH AMERICA
Greenland NORTH AMERICA
United States NORTH AMERICA
American Samoa OCEANIA
Australia OCEANIA
Fiji OCEANIA
French Polynesia OCEANIA
Guam OCEANIA
New Zealand OCEANIA
Palau OCEANIA
Papua New Guinea OCEANIA
Solomon Islands OCEANIA
Tonga OCEANIA
Argentina SOUTH AMERICA
Bahamas SOUTH AMERICA
Barbados SOUTH AMERICA
Belize SOUTH AMERICA
Bolivia SOUTH AMERICA
Brazil SOUTH AMERICA
Chile SOUTH AMERICA
Colombia SOUTH AMERICA
Costa Rica SOUTH AMERICA
Cuba SOUTH AMERICA
Dominican Republic SOUTH AMERICA
Ecuador SOUTH AMERICA
El Salvador SOUTH AMERICA
Guatemala SOUTH AMERICA
Haiti SOUTH AMERICA
Honduras SOUTH AMERICA
Jamaica SOUTH AMERICA
Mexico SOUTH AMERICA
Nicaragua SOUTH AMERICA
Panama SOUTH AMERICA
Paraguay SOUTH AMERICA
Peru SOUTH AMERICA
Puerto Rico SOUTH AMERICA
Trinidad and Tobago SOUTH AMERICA
Uruguay SOUTH AMERICA
Venezuela SOUTH AMERICA

Selected Variables

sv <- wb%>% 
      select(country, 
             Year, 
             region, 
             meantemp,
             
             Agricultural.land..sq..km. , 
             CO2.emissions..metric.tons.per.capita. , 
             CO2.emissions..kt. , 
              
             
             Forest.area..sq..km., 
             GDP..constant.2010.US.. , 
             
             Land.area..sq..km.  , 
             Methane.emissions..kt.of.CO2.equivalent. , 
             Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent. , 
             Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent., 
              
             Total.greenhouse.gas.emissions..kt.of.CO2.equivalent. , 
             
             Urban.population....of.total. ) %>% 
  filter(Year %in% 1990:2012 )
            
write.csv(sv, "Selectedvariables.csv")

Selected Countries

sc <- sv %>% 
       filter(country %in% c(
"Algeria",
# "Botswana",
"Cameroon",
"Congo",
"Egypt",
"Ghana",
"Kenya",
"Nigeria",
# "South Africa",
# "Zimbabwe",

"Bangladesh",
"Bhutan",
"Burma",
"China",
"India",
"Indonesia",
"Japan",
"Malaysia",
"Nepal",
"Phillipines",
# "Singapore",
"Sri Lanka",
"Thailand",
"Vietnam",

"Austria",
# "Azerbaijan",
# "Belgium",
# "Czech Republic",
"Denmark",
"France",
# "Germany",
"Italy",
# "Luxembourg",
"Netherlands",
"Spain",
"Sweden",
"Switzerland",
"United Kingdom",

"Canada",
# "Greenland",
"United States",

"Australia",
"New Zealand",
"Papua New Guinea",
"Fiji",

"Argentina",
"Bolivia",
"Brazil",
"Chile",
"Colombia",
"Costa Rica",
# "Haiti",
"Mexico",
"Paraguay",
# "Puerto Rico",
"Uruguay",
"Venezuela"

))


write.csv(sc, "Selectedvariables.csv")

IN different Plots

ggplot( sc ,aes(x=Year, y=meantemp, group = country)) + 
  geom_line(size = 0.1) + 
  theme_minimal() + 
  facet_grid( .~ region )

asia <- sc %>% 
        filter(region == "ASIA" , meantemp > 20)


africa <- sc %>% 
        filter(region == "AFRICA")

europe <- sc %>% 
        filter(region == "EUROPE", meantemp > -10)


ggplot( asia ,aes(x=Year, y=meantemp, color=country)) + 
  geom_line() +
  labs(title = "Asian Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")
## `geom_smooth()` using formula 'y ~ x'

ggplot( africa ,aes(x=Year, y=meantemp, color=country)) + 
  geom_line() +
  labs(title = "African Countries Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")
## `geom_smooth()` using formula 'y ~ x'

ggplot( europe ,aes(x=Year, y=meantemp, color=country)) + 
  geom_line() +
  labs(title = "Europian Countries Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")
## `geom_smooth()` using formula 'y ~ x'

northamerica <- sc %>% 
        filter(region == "NORTH AMERICA")


ggplot( northamerica ,aes(x=Year, y=meantemp, color=country)) + 
  geom_line() +
  labs(title = "North American Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")
## `geom_smooth()` using formula 'y ~ x'

southamerica <- sc %>% 
        filter(region == "SOUTH AMERICA")


ggplot( southamerica ,aes(x=Year, y=meantemp, color=country)) + 
  geom_line() +
  labs(title = "South American Temparature over Years") + 
  geom_smooth(method = "lm", se = F) + 
  theme_minimal() + 
  theme(legend.position="bottom")
## `geom_smooth()` using formula 'y ~ x'

Least Squares Dummy Variable Fixed Effect Model

dat <- read.csv("Selectedvariables.csv")

require(dplyr)
require()

asia <- dat %>% 
        filter(region == "ASIA")

names(asia)
##  [1] "X"                                                                                        
##  [2] "country"                                                                                  
##  [3] "Year"                                                                                     
##  [4] "region"                                                                                   
##  [5] "meantemp"                                                                                 
##  [6] "Agricultural.land..sq..km."                                                               
##  [7] "CO2.emissions..metric.tons.per.capita."                                                   
##  [8] "CO2.emissions..kt."                                                                       
##  [9] "Forest.area..sq..km."                                                                     
## [10] "GDP..constant.2010.US.."                                                                  
## [11] "Land.area..sq..km."                                                                       
## [12] "Methane.emissions..kt.of.CO2.equivalent."                                                 
## [13] "Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent."                         
## [14] "Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent."
## [15] "Total.greenhouse.gas.emissions..kt.of.CO2.equivalent."                                    
## [16] "Urban.population....of.total."
lsdv <- lm( meantemp ~ 
              Agricultural.land..sq..km. + 
              CO2.emissions..kt. + 
              Forest.area..sq..km. + 
              GDP..constant.2010.US.. + 
              #Land.area..sq..km. + 
              #Methane.emissions..kt.of.CO2.equivalent. + 
              #Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent. + 
              # Removed due to multicliinearity
              Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent. + 
              Total.greenhouse.gas.emissions..kt.of.CO2.equivalent. + 
              Urban.population....of.total.  + 
              country,
              data = asia )
require(broom)
require(knitr)

out <- tidy(lsdv)

out$term[6] <- "Other sg6, hfc, pfc"
out$term[7] <- "Total Greenhouse gas emmission"

Asia

kable(out)
term estimate std.error statistic p.value
(Intercept) 24.7143583 0.1483413 166.6047460 0.0000000
Agricultural.land..sq..km. -0.0000011 0.0000010 -1.0350050 0.3016395
CO2.emissions..kt. -0.0000010 0.0000004 -2.5054464 0.0128489
Forest.area..sq..km. 0.0000014 0.0000007 2.0761153 0.0388775
GDP..constant.2010.US.. 0.0000000 0.0000000 -0.3724937 0.7098323
Other sg6, hfc, pfc -0.0000011 0.0000004 -2.4960995 0.0131840
Total Greenhouse gas emmission 0.0000008 0.0000003 2.4514371 0.0148951
Urban.population….of.total. 0.0269897 0.0047553 5.6757533 0.0000000
countryBhutan -13.0948741 0.1237151 -105.8470557 0.0000000
countryBurma -1.5786176 0.2457833 -6.4228028 0.0000000
countryChina -15.6664150 5.5649472 -2.8151956 0.0052523
countryIndia -0.3564716 1.8797925 -0.1896335 0.8497460
countryIndonesia -0.5674967 0.8652084 -0.6559076 0.5124703
countryJapan -14.0219217 0.6297860 -22.2645810 0.0000000
countryMalaysia -0.1202816 0.2532131 -0.4750214 0.6351752
countryNepal -9.6091573 0.1046111 -91.8560225 0.0000000
countrySri Lanka 2.3895085 0.1091157 21.8988472 0.0000000
countryThailand 0.9220283 0.1875329 4.9166219 0.0000016
countryVietnam -1.3221613 0.1100774 -12.0111922 0.0000000
plot(asia[, -c(1:4)])

Europe

europe <- dat %>% 
        filter(region == "EUROPE")

names(europe)
##  [1] "X"                                                                                        
##  [2] "country"                                                                                  
##  [3] "Year"                                                                                     
##  [4] "region"                                                                                   
##  [5] "meantemp"                                                                                 
##  [6] "Agricultural.land..sq..km."                                                               
##  [7] "CO2.emissions..metric.tons.per.capita."                                                   
##  [8] "CO2.emissions..kt."                                                                       
##  [9] "Forest.area..sq..km."                                                                     
## [10] "GDP..constant.2010.US.."                                                                  
## [11] "Land.area..sq..km."                                                                       
## [12] "Methane.emissions..kt.of.CO2.equivalent."                                                 
## [13] "Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent."                         
## [14] "Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent."
## [15] "Total.greenhouse.gas.emissions..kt.of.CO2.equivalent."                                    
## [16] "Urban.population....of.total."
lsdv <- lm( meantemp ~ 
              Agricultural.land..sq..km. + 
              CO2.emissions..kt. + 
              Forest.area..sq..km. + 
              GDP..constant.2010.US.. + 
              #Land.area..sq..km. + 
              #Methane.emissions..kt.of.CO2.equivalent. + 
              #Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent. + 
              # Removed due to multicliinearity
              Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent. + 
              Total.greenhouse.gas.emissions..kt.of.CO2.equivalent. + 
              Urban.population....of.total.  + 
              country,
              data = europe )
require(broom)
require(knitr)

out <- tidy(lsdv)

out$term[6] <- "Other sg6, hfc, pfc"
out$term[7] <- "Total Greenhouse gas emmission"

Europe

kable(out)
term estimate std.error statistic p.value
(Intercept) 7.9208343 1.8129826 4.3689522 0.0000205
Agricultural.land..sq..km. 0.0000006 0.0000159 0.0406336 0.9676304
CO2.emissions..kt. -0.0000191 0.0000070 -2.7261404 0.0070042
Forest.area..sq..km. 0.0000060 0.0000183 0.3288206 0.7426516
GDP..constant.2010.US.. 0.0000000 0.0000000 2.9377532 0.0037130
Other sg6, hfc, pfc -0.0000690 0.0000228 -3.0214238 0.0028606
Total Greenhouse gas emmission 0.0000142 0.0000059 2.4109702 0.0168575
Urban.population….of.total. -0.0204455 0.0240203 -0.8511760 0.3957375
countryDenmark -23.6019416 0.8060315 -29.2816624 0.0000000
countryFrance 2.4438547 5.7128487 0.4277821 0.6692917
countryItaly 4.6264101 2.5736468 1.7976088 0.0738186
countryNetherlands 3.7735804 1.0899064 3.4622976 0.0006609
countrySpain 5.8462371 5.6955067 1.0264648 0.3059708
countrySweden -5.0583021 4.4474605 -1.1373462 0.2568184
countrySwitzerland 0.8389772 0.6768291 1.2395703 0.2166553
countryUnited Kingdom 0.4132159 2.8639836 0.1442801 0.8854314
plot(europe[, -c(1:4)])

Africa

africa <- dat %>% 
        filter(region == "AFRICA")

names(europe)
##  [1] "X"                                                                                        
##  [2] "country"                                                                                  
##  [3] "Year"                                                                                     
##  [4] "region"                                                                                   
##  [5] "meantemp"                                                                                 
##  [6] "Agricultural.land..sq..km."                                                               
##  [7] "CO2.emissions..metric.tons.per.capita."                                                   
##  [8] "CO2.emissions..kt."                                                                       
##  [9] "Forest.area..sq..km."                                                                     
## [10] "GDP..constant.2010.US.."                                                                  
## [11] "Land.area..sq..km."                                                                       
## [12] "Methane.emissions..kt.of.CO2.equivalent."                                                 
## [13] "Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent."                         
## [14] "Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent."
## [15] "Total.greenhouse.gas.emissions..kt.of.CO2.equivalent."                                    
## [16] "Urban.population....of.total."
lsdv <- lm( meantemp ~ 
              Agricultural.land..sq..km. + 
              CO2.emissions..kt. + 
              Forest.area..sq..km. + 
              GDP..constant.2010.US.. + 
              #Land.area..sq..km. + 
              #Methane.emissions..kt.of.CO2.equivalent. + 
              #Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent. + 
              # Removed due to multicliinearity
              Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent. + 
              Total.greenhouse.gas.emissions..kt.of.CO2.equivalent. + 
              Urban.population....of.total.  + 
              country,
              data = africa )
require(broom)
require(knitr)

out <- tidy(lsdv)

out$term[6] <- "Other sg6, hfc, pfc"
out$term[7] <- "Total Greenhouse gas emmission"

Africa

kable(out)
term estimate std.error statistic p.value
(Intercept) 22.1701565 1.1054202 20.0558628 0.0000000
Agricultural.land..sq..km. -0.0000044 0.0000030 -1.4805619 0.1408635
CO2.emissions..kt. 0.0000021 0.0000031 0.6721722 0.5025292
Forest.area..sq..km. 0.0000017 0.0000035 0.4764779 0.6344414
GDP..constant.2010.US.. 0.0000000 0.0000000 0.3442886 0.7311213
Other sg6, hfc, pfc -0.0000008 0.0000029 -0.2830001 0.7775749
Total Greenhouse gas emmission 0.0000027 0.0000029 0.9295207 0.3541432
Urban.population….of.total. 0.0483792 0.0090386 5.3525268 0.0000003
countryCameroon 0.3078050 1.0144552 0.3034190 0.7619995
countryCongo -0.0370429 1.0164680 -0.0364428 0.9709788
countryEgypt -1.5298607 1.1036468 -1.3861869 0.1677889
countryGhana 3.3027204 0.7222997 4.5725071 0.0000102
countryKenya 2.4788033 0.4005675 6.1882280 0.0000000
countryNigeria 5.3700959 1.1168383 4.8083020 0.0000037
plot(africa[, -c(1:4)])

South America

southamerica <- dat %>% 
        filter(region == "SOUTH AMERICA")

names(southamerica)
##  [1] "X"                                                                                        
##  [2] "country"                                                                                  
##  [3] "Year"                                                                                     
##  [4] "region"                                                                                   
##  [5] "meantemp"                                                                                 
##  [6] "Agricultural.land..sq..km."                                                               
##  [7] "CO2.emissions..metric.tons.per.capita."                                                   
##  [8] "CO2.emissions..kt."                                                                       
##  [9] "Forest.area..sq..km."                                                                     
## [10] "GDP..constant.2010.US.."                                                                  
## [11] "Land.area..sq..km."                                                                       
## [12] "Methane.emissions..kt.of.CO2.equivalent."                                                 
## [13] "Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent."                         
## [14] "Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent."
## [15] "Total.greenhouse.gas.emissions..kt.of.CO2.equivalent."                                    
## [16] "Urban.population....of.total."
lsdv <- lm( meantemp ~ 
              Agricultural.land..sq..km. + 
              CO2.emissions..kt. + 
              Forest.area..sq..km. + 
              GDP..constant.2010.US.. + 
              #Land.area..sq..km. + 
              #Methane.emissions..kt.of.CO2.equivalent. + 
              #Nitrous.oxide.emissions..thousand.metric.tons.of.CO2.equivalent. + 
              # Removed due to multicliinearity
              Other.greenhouse.gas.emissions..HFC..PFC.and.SF6..thousand.metric.tons.of.CO2.equivalent. + 
              Total.greenhouse.gas.emissions..kt.of.CO2.equivalent. + 
              Urban.population....of.total.  + 
              country,
              data = southamerica )
require(broom)
require(knitr)

out <- tidy(lsdv)

out$term[6] <- "Other sg6, hfc, pfc"
out$term[7] <- "Total Greenhouse gas emmission"

South America

kable(out)
term estimate std.error statistic p.value
(Intercept) 14.4856992 1.4035342 10.3208737 0.0000000
Agricultural.land..sq..km. -0.0000003 0.0000008 -0.3960393 0.6924725
CO2.emissions..kt. 0.0000020 0.0000017 1.2029631 0.2303260
Forest.area..sq..km. 0.0000001 0.0000010 0.0527474 0.9579826
GDP..constant.2010.US.. 0.0000000 0.0000000 -1.1466896 0.2527964
Other sg6, hfc, pfc -0.0000013 0.0000014 -0.9686108 0.3338379
Total Greenhouse gas emmission 0.0000014 0.0000013 1.0784067 0.2820720
Urban.population….of.total. 0.0069490 0.0062878 1.1051508 0.2703410
countryBolivia 6.4813238 0.6220244 10.4197256 0.0000000
countryBrazil 9.9350924 6.0035690 1.6548644 0.0994247
countryChile -5.2583489 1.0001588 -5.2575141 0.0000004
countryColombia 10.3160438 0.5761799 17.9042075 0.0000000
countryCosta Rica 11.4167526 1.2314841 9.2707266 0.0000000
countryMexico 5.3849921 0.4781983 11.2610026 0.0000000
countryParaguay 9.0782544 0.9910279 9.1604426 0.0000000
countryUruguay 2.8090079 1.1140701 2.5213925 0.0124212
countryVenezuela 10.2594934 0.7801806 13.1501522 0.0000000
plot(southamerica[, -c(1:4)])