-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolicy_Brief_Trowbridge.R
50 lines (40 loc) · 1.36 KB
/
Policy_Brief_Trowbridge.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(tidyverse)
library(WDI) # A package that uses the World Bank's data API
library(plm)
library(stargazer)
# Electric Power Consumption (kWh per capita)
df_elec <- WDI(
indicator = "EG.USE.ELEC.KH.PC",
country = c('HN','GT','SV','NI','CR'),
start = 1980, end=2014) %>%
select(-iso2c) %>%
rename(kwh_per_cap = EG.USE.ELEC.KH.PC)
# Primary School Completion Rate
df_edu <- WDI(
indicator = "SE.PRM.CMPT.ZS",
country = c('HN','GT','SV','NI','CR'),
start = 1980, end=2014) %>%
select(-iso2c) %>%
rename(edu_comp = SE.PRM.CMPT.ZS)
df_all <- full_join(df_elec, df_edu, by = c("country", "year"))
df_all %>%
ggplot(aes(x = kwh_per_cap, y = edu_comp, col = country)) +
geom_point() +
facet_wrap(vars(country)) +
stat_smooth(method = "lm", se = FALSE) +
labs(
x = "Electric Power Consumption (kWh per capita)",
y = "Primary School Completion Rate",
col = ""
) +
theme(legend.position = "none")
p_all <- pdata.frame(df_all, index = c("country", "year"))
model_all <- plm(edu_comp ~ kwh_per_cap, data = p_all, model = "within")
summary(model_all)
stargazer(model_all,
title = "Electricity and Education in Central America",
type = "html",
covariate.labels = "Electric Power Consumption (kWh per capita)",
dep.var.labels = "Primary School Completion Rate",
out="edu_elec.html")
#####