setwd("/Users/asiyavalidova/Dropbox/Demography/Causal inference/Paper_dissertation chapter")
library(haven)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
wiid<-read_dta("WIID.dta")
#dim(wiid)
#names(wiid)
#check years with HMD - 1995-2017
wiid<-wiid%>%
select(c("country","year","gini","gdp"))
wiid_fr<-wiid%>%
filter(country=="France")
wiid_ger<-wiid%>%
filter(country=="Germany")
table(wiid_ger$year)
wiid_jap<-wiid%>%
filter(country=="Japan")
table(wiid_jap$year)
wiid_nor<-wiid%>%
filter(country=="Norway")
table(wiid_nor$year)
wiid_can<-wiid%>%
filter(country=="Canada")
table(wiid_can$year)
wiid_bul<-wiid%>%
filter(country=="Bulgaria")
table(wiid_bul$year)
wiid_gre<-wiid%>%
filter(country=="Greece")
table(wiid_gre$year)
wiid_lat<-wiid%>%
filter(country=="Latvia")
table(wiid_lat$year)
wiid_usa<-wiid%>%
filter(country=="United States")
table(wiid_usa$year)
wiid_por<-wiid%>%
filter(country=="Portugal")
table(wiid_por$year)
wiid_bel<-wiid%>%
filter(country=="Belarus")
table(wiid_bel$year)
wiid_belg<-wiid%>%
filter(country=="Belgium")
table(wiid_belg$year)
wiid_est<-wiid%>%
filter(country=="Estonia")
table(wiid_est$year)
wiid_swe<-wiid%>%
filter(country=="Sweden")
table(wiid_swe$year)
wiid_lith<-wiid%>%
filter(country=="Lithuania")
table(wiid_lith$year)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(table1)
##
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
##
## units, units<-
wiid<-read_dta("WIID.dta")
wiid<-wiid%>%
select(c("country","year","gini","gdp"))
wiid<-wiid%>%
filter(year>=1995 & year<=2017 & (country=="France" |
country=="Germany" |
country=="Norway" |
country=="Canada" |
country=="Bulgaria" |
country=="Greece" |
country=="Latvia" |
country=="Portugal" |
country=="United States" |
country=="Belarus" |
country=="Belgium" |
country=="Estonia" |
country=="Sweden" |
country=="Lithuania"
)
)
belarus<-read.table("Belarus.txt",header=TRUE)
belarus<-belarus%>%
filter(Year>=1995 & Year<=2017)
belarus$country<-"Belarus"
belarus$leb<-belarus$Total
belarus$year<-belarus$Year
belarus$economic_development<-0
belarus<-belarus%>%
select(c("year","country","leb","economic_development"))
france<-read.table("France.txt",header=TRUE)
france<-france%>%
filter(Year>=1995 & Year<=2017)
france$country<-"France"
france$leb<-france$Total
france$year<-france$Year
france$economic_development<-1
france<-france%>%
select(c("year","country","leb","economic_development"))
germany<-read.table("Germany.txt",header=TRUE)
germany<-germany%>%
filter(Year>=1995 & Year<=2017)
germany$country<-"Germany"
germany$leb<-germany$Total
germany$year<-germany$Year
germany$economic_development<-1
germany<-germany%>%
select(c("year","country","leb","economic_development"))
norway<-read.table("Norway.txt",header=TRUE)
norway<-norway%>%
filter(Year>=1995 & Year<=2017)
norway$country<-"Norway"
norway$leb<-norway$Total
norway$year<-norway$Year
norway$economic_development<-1
norway<-norway%>%
select(c("year","country","leb","economic_development"))
canada<-read.table("Canada.txt",header=TRUE)
canada<-canada%>%
filter(Year>=1995 & Year<=2017)
canada$country<-"Canada"
canada$leb<-canada$Total
canada$year<-canada$Year
canada$economic_development<-1
canada<-canada%>%
select(c("year","country","leb","economic_development"))
bulgaria<-read.table("Bulgaria.txt",header=TRUE)
bulgaria<-bulgaria%>%
filter(Year>=1995 & Year<=2017)
bulgaria$country<-"Bulgaria"
bulgaria$leb<-bulgaria$Total
bulgaria$year<-bulgaria$Year
bulgaria$economic_development<-0
bulgaria<-bulgaria%>%
select(c("year","country","leb","economic_development"))
greece<-read.table("Greece.txt",header=TRUE)
greece<-greece%>%
filter(Year>=1995 & Year<=2017)
greece$country<-"Greece"
greece$leb<-greece$Total
greece$year<-greece$Year
greece$economic_development<-0
greece<-greece%>%
select(c("year","country","leb","economic_development"))
latvia<-read.table("Latvia.txt",header=TRUE)
latvia<-latvia%>%
filter(Year>=1995 & Year<=2017)
latvia$country<-"Latvia"
latvia$leb<-latvia$Total
latvia$year<-latvia$Year
latvia$economic_development<-0
latvia<-latvia%>%
select(c("year","country","leb","economic_development"))
portugal<-read.table("Portugal.txt",header=TRUE)
portugal<-portugal%>%
filter(Year>=1995 & Year<=2017)
portugal$country<-"Portugal"
portugal$leb<-portugal$Total
portugal$year<-portugal$Year
portugal$economic_development<-0
portugal<-portugal%>%
select(c("year","country","leb","economic_development"))
usa<-read.table("USA.txt",header=TRUE)
usa<-usa%>%
filter(Year>=1995 & Year<=2017)
usa$country<-"United States"
usa$leb<-usa$Total
usa$year<-usa$Year
usa$economic_development<-1
usa<-usa%>%
select(c("year","country","leb","economic_development"))
belgium<-read.table("Belgium.txt",header=TRUE)
belgium<-belgium%>%
filter(Year>=1995 & Year<=2017)
belgium$country<-"Belgium"
belgium$leb<-belgium$Total
belgium$year<-belgium$Year
belgium$economic_development<-1
belgium<-belgium%>%
select(c("year","country","leb","economic_development"))
estonia<-read.table("Estonia.txt",header=TRUE)
estonia<-estonia%>%
filter(Year>=1995 & Year<=2017)
estonia$country<-"Estonia"
estonia$leb<-estonia$Total
estonia$year<-estonia$Year
estonia$economic_development<-0
estonia<-estonia%>%
select(c("year","country","leb","economic_development"))
sweden<-read.table("Sweden.txt",header=TRUE)
sweden<-sweden%>%
filter(Year>=1995 & Year<=2017)
sweden$country<-"Sweden"
sweden$leb<-sweden$Total
sweden$year<-sweden$Year
sweden$economic_development<-1
sweden<-sweden%>%
select(c("year","country","leb","economic_development"))
lithuania<-read.table("Lithuania.txt",header=TRUE)
lithuania<-lithuania%>%
filter(Year>=1995 & Year<=2017)
lithuania$country<-"Lithuania"
lithuania$leb<-lithuania$Total
lithuania$year<-lithuania$Year
lithuania$economic_development<-0
lithuania<-lithuania%>%
select(c("year","country","leb","economic_development"))
#adding the dataframes
countries<-france
countries<-rbind(countries,germany)
countries<-rbind(countries,norway)
countries<-rbind(countries,canada)
countries<-rbind(countries,bulgaria)
countries<-rbind(countries,greece)
countries<-rbind(countries,latvia)
countries<-rbind(countries,portugal)
countries<-rbind(countries,usa)
countries<-rbind(countries,belarus)
countries<-rbind(countries,belgium)
countries<-rbind(countries,estonia)
countries<-rbind(countries,sweden)
countries<-rbind(countries,lithuania)
#merge wiid and countries
wiid<-merge(wiid,countries,by.x=c("year","country"),by.y=c("year","country"),all.x=TRUE,all.y=FALSE)
wiid<-wiid%>%
mutate(
economic_development=Recode(economic_development,recodes="0='developing';1='developed'", as.factor=T)
)
#need unique country+year information for plm function (to get rid of multiple gini for the same country+year)
wiid5<-unique(wiid[,c("year","country","leb","gdp","economic_development")])
wiid_mean<-wiid%>%
group_by(year,country)%>%
summarise(
gini=mean(gini)
)
## `summarise()` regrouping output by 'year' (override with `.groups` argument)
wiid<-merge(wiid5,wiid_mean,by.x=c("year","country"),by.y=c("year","country"),all.x=TRUE,all.y=FALSE)
save(wiid,file="wiid.Rdata")
library(dplyr)
library(haven)
library(car)
library(table1)
#install.packages("plm", dependencies = T)
library(plm)
##
## Attaching package: 'plm'
## The following objects are masked from 'package:dplyr':
##
## between, lag, lead
wiid<-get(load("wiid.Rdata"))
label(wiid$leb)<-"Life expectancy at birth"
label(wiid$economic_development)<-"Economic development"
label(wiid$gdp)<-"GDP per capita"
label(wiid$gini)<-"GINI"
table1(~ leb+gini+gdp|economic_development,data=wiid)
| developed (N=161) |
developing (N=161) |
Overall (N=322) |
|
|---|---|---|---|
| Life expectancy at birth | |||
| Mean (SD) | 79.7 (1.64) | 74.1 (3.91) | 76.9 (4.10) |
| Median [Min, Max] | 79.7 [75.9, 82.6] | 73.7 [66.0, 81.4] | 78.2 [66.0, 82.6] |
| GINI | |||
| Mean (SD) | 32.9 (4.62) | 35.6 (3.90) | 34.3 (4.47) |
| Median [Min, Max] | 31.9 [23.2, 44.3] | 36.3 [25.3, 42.5] | 34.4 [23.2, 44.3] |
| GDP per capita | |||
| Mean (SD) | 47300 (7200) | 22000 (8230) | 34700 (14900) |
| Median [Min, Max] | 46900 [34200, 63000] | 22800 [5810, 37300] | 35300 [5810, 63000] |
table(wiid$country)
##
## Belarus Belgium Bulgaria Canada Estonia
## 23 23 23 23 23
## France Germany Greece Latvia Lithuania
## 23 23 23 23 23
## Norway Portugal Sweden United States
## 23 23 23 23
datayear<-wiid%>%
filter(year==2017)
datayear<-datayear%>%
arrange(gdp)
#datayear
#Regressions
# Obtain demeaned data
wiid_demeaned <- with(wiid,
data.frame(leb = leb - ave(leb, country),
gini = gini - ave(gini, country),
gdp_log = log(gdp)-ave(log(gdp),country ),
gini_gdp_log = gini*log(gdp)-ave(gini*log(gdp),country)))
# Without interaction
fit<-lm(leb ~ gini - 1 + gdp_log-1 , data = wiid_demeaned)
summary(fit)
##
## Call:
## lm(formula = leb ~ gini - 1 + gdp_log - 1, data = wiid_demeaned)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1503 -0.6717 -0.1201 0.7098 2.7595
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## gini 0.11138 0.03004 3.708 0.000247 ***
## gdp_log 5.58887 0.30774 18.161 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.089 on 320 degrees of freedom
## Multiple R-squared: 0.599, Adjusted R-squared: 0.5965
## F-statistic: 239 on 2 and 320 DF, p-value: < 2.2e-16
# With interaction
# A within estimator of an interaction can be obtained by first demeaning each variable and then demeaning their product.
fit<-lm(leb ~ gini - 1 + gdp_log-1 +gini_gdp_log -1 , data = wiid_demeaned)
summary(fit)
##
## Call:
## lm(formula = leb ~ gini - 1 + gdp_log - 1 + gini_gdp_log - 1,
## data = wiid_demeaned)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1826 -0.6988 -0.0227 0.6373 2.4175
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## gini -2.8838 0.6099 -4.729 3.40e-06 ***
## gdp_log -3.9629 1.9653 -2.016 0.0446 *
## gini_gdp_log 0.2896 0.0589 4.917 1.41e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.052 on 319 degrees of freedom
## Multiple R-squared: 0.6272, Adjusted R-squared: 0.6237
## F-statistic: 178.9 on 3 and 319 DF, p-value: < 2.2e-16
fit_dummy<-lm(leb ~ gini + log(gdp) + country-1, data = wiid)
summary(fit_dummy)
##
## Call:
## lm(formula = leb ~ gini + log(gdp) + country - 1, data = wiid)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1503 -0.6717 -0.1201 0.7098 2.7595
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## gini 0.11138 0.03072 3.625 0.000338 ***
## log(gdp) 5.58887 0.31470 17.759 < 2e-16 ***
## countryBelarus 14.59915 2.72846 5.351 1.72e-07 ***
## countryBelgium 15.85071 3.12199 5.077 6.67e-07 ***
## countryBulgaria 15.32642 2.76584 5.541 6.48e-08 ***
## countryCanada 16.81587 3.07662 5.466 9.58e-08 ***
## countryEstonia 13.24818 2.90495 4.561 7.39e-06 ***
## countryFrance 17.53696 3.08584 5.683 3.08e-08 ***
## countryGermany 15.68299 3.11770 5.030 8.36e-07 ***
## countryGreece 17.91201 2.98125 6.008 5.32e-09 ***
## countryLatvia 12.50471 2.83222 4.415 1.40e-05 ***
## countryLithuania 12.81260 2.86189 4.477 1.07e-05 ***
## countryNorway 15.46666 3.19776 4.837 2.09e-06 ***
## countryPortugal 16.77935 2.97947 5.632 4.04e-08 ***
## countrySweden 17.74305 3.12729 5.674 3.24e-08 ***
## countryUnited States 12.42385 3.13456 3.964 9.20e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.114 on 306 degrees of freedom
## Multiple R-squared: 0.9998, Adjusted R-squared: 0.9998
## F-statistic: 9.619e+04 on 16 and 306 DF, p-value: < 2.2e-16
fit_dummy<-lm(leb ~ gini + log(gdp) + gini*log(gdp) + country-1, data = wiid)
summary(fit_dummy)
##
## Call:
## lm(formula = leb ~ gini + log(gdp) + gini * log(gdp) + country -
## 1, data = wiid)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1826 -0.6988 -0.0227 0.6373 2.4175
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## gini -2.88376 0.62369 -4.624 5.57e-06 ***
## log(gdp) -3.96293 2.00988 -1.972 0.0495 *
## countryBelarus 112.24007 20.47942 5.481 8.89e-08 ***
## countryBelgium 114.89798 20.82117 5.518 7.32e-08 ***
## countryBulgaria 114.59132 20.81904 5.504 7.87e-08 ***
## countryCanada 115.29680 20.69828 5.570 5.59e-08 ***
## countryEstonia 112.33000 20.79897 5.401 1.34e-07 ***
## countryFrance 116.40516 20.77928 5.602 4.74e-08 ***
## countryGermany 114.53874 20.78115 5.512 7.57e-08 ***
## countryGreece 116.71482 20.75156 5.624 4.21e-08 ***
## countryLatvia 111.65102 20.80291 5.367 1.59e-07 ***
## countryLithuania 111.90459 20.79550 5.381 1.48e-07 ***
## countryNorway 114.73156 20.87665 5.496 8.23e-08 ***
## countryPortugal 115.57330 20.74950 5.570 5.60e-08 ***
## countrySweden 116.94908 20.85458 5.608 4.59e-08 ***
## countryUnited States 109.89861 20.49938 5.361 1.64e-07 ***
## gini:log(gdp) 0.28959 0.06024 4.808 2.40e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.076 on 305 degrees of freedom
## Multiple R-squared: 0.9998, Adjusted R-squared: 0.9998
## F-statistic: 9.708e+04 on 17 and 305 DF, p-value: < 2.2e-16
# Without interaction
fit_plm <- plm(leb ~ gini+log(gdp),
data = wiid,
index = c("country", "year"),
model = "within")
summary(fit_plm)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp), data = wiid, model = "within",
## index = c("country", "year"))
##
## Balanced Panel: n = 14, T = 23, N = 322
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -3.15029 -0.67166 -0.12006 0.70980 2.75951
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini 0.111377 0.030721 3.6255 0.0003377 ***
## log(gdp) 5.588872 0.314705 17.7591 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 946.74
## Residual Sum of Squares: 379.67
## R-Squared: 0.59898
## Adj. R-Squared: 0.57932
## F-statistic: 228.525 on 2 and 306 DF, p-value: < 2.22e-16
# With interaction
fit_plmi <- plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid,
index = c("country", "year"),
model = "within")
summary(fit_plmi)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp) + gini * log(gdp), data = wiid,
## model = "within", index = c("country", "year"))
##
## Balanced Panel: n = 14, T = 23, N = 322
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -3.182642 -0.698797 -0.022686 0.637346 2.417450
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini -2.883756 0.623690 -4.6237 5.575e-06 ***
## log(gdp) -3.962935 2.009876 -1.9717 0.04954 *
## gini:log(gdp) 0.289594 0.060235 4.8077 2.401e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 946.74
## Residual Sum of Squares: 352.92
## R-Squared: 0.62723
## Adj. R-Squared: 0.60767
## F-statistic: 171.064 on 3 and 305 DF, p-value: < 2.22e-16
wiid_developed<-wiid%>%
filter(economic_development=="developed")
wiid_developing<-wiid%>%
filter(economic_development=="developing")
# Developed
fit_rich <- plm(leb ~ gini+log(gdp),
data = wiid_developed,
index = c("country", "year"),
model = "within")
summary(fit_rich)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp), data = wiid_developed, model = "within",
## index = c("country", "year"))
##
## Balanced Panel: n = 7, T = 23, N = 161
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -1.18668 -0.38798 -0.06468 0.40567 1.52379
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini 0.046348 0.029894 1.5504 0.1231
## log(gdp) 11.901311 0.625457 19.0282 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 281.26
## Residual Sum of Squares: 56.309
## R-Squared: 0.7998
## Adj. R-Squared: 0.78926
## F-statistic: 303.617 on 2 and 152 DF, p-value: < 2.22e-16
fit_richi <- plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid_developed,
index = c("country", "year"),
model = "within")
summary(fit_richi)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp) + gini * log(gdp), data = wiid_developed,
## model = "within", index = c("country", "year"))
##
## Balanced Panel: n = 7, T = 23, N = 161
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -1.03673 -0.40602 -0.05128 0.33358 1.53154
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini 1.762627 0.995319 1.7709 0.07859 .
## log(gdp) 17.220076 3.145133 5.4752 1.782e-07 ***
## gini:log(gdp) -0.160912 0.093276 -1.7251 0.08655 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 281.26
## Residual Sum of Squares: 55.22
## R-Squared: 0.80367
## Adj. R-Squared: 0.79197
## F-statistic: 206.035 on 3 and 151 DF, p-value: < 2.22e-16
# Developing
fit_poor <- plm(leb ~ gini+log(gdp),
data = wiid_developing,
index = c("country", "year"),
model = "within")
summary(fit_poor)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp), data = wiid_developing,
## model = "within", index = c("country", "year"))
##
## Balanced Panel: n = 7, T = 23, N = 161
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -3.005538 -0.918097 -0.098594 0.962719 2.813795
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini 0.056083 0.047292 1.1859 0.2375
## log(gdp) 5.187427 0.394645 13.1445 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 665.48
## Residual Sum of Squares: 270.68
## R-Squared: 0.59326
## Adj. R-Squared: 0.57186
## F-statistic: 110.854 on 2 and 152 DF, p-value: < 2.22e-16
fit_poori <- plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid_developing,
index = c("country", "year"),
model = "within")
summary(fit_poori)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = leb ~ gini + log(gdp) + gini * log(gdp), data = wiid_developing,
## model = "within", index = c("country", "year"))
##
## Balanced Panel: n = 7, T = 23, N = 161
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -3.09009 -0.91190 -0.10692 0.90539 2.56758
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## gini -3.767921 1.010485 -3.7288 0.0002715 ***
## log(gdp) -7.421105 3.349860 -2.2153 0.0282331 *
## gini:log(gdp) 0.378279 0.099859 3.7881 0.0002187 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 665.48
## Residual Sum of Squares: 247.19
## R-Squared: 0.62856
## Adj. R-Squared: 0.60642
## F-statistic: 85.1765 on 3 and 151 DF, p-value: < 2.22e-16
wiid2017<-wiid%>%
filter(year==2017)
wiid2017
## year country leb gdp economic_development gini
## 1 2017 Belarus 74.42 18280 developing 25.44000
## 2 2017 Belgium 81.37 50615 developed 30.68444
## 3 2017 Bulgaria 74.80 21371 developing 42.52083
## 4 2017 Canada 82.04 48634 developed 36.23333
## 5 2017 Estonia 78.20 33937 developing 34.90600
## 6 2017 France 82.48 44827 developed 33.43417
## 7 2017 Germany 80.94 53255 developed 34.53895
## 8 2017 Greece 81.16 28594 developing 35.65000
## 9 2017 Latvia 74.82 28664 developing 38.28917
## 10 2017 Lithuania 75.70 33827 developing 40.70250
## 11 2017 Norway 82.63 62941 developed 31.00250
## 12 2017 Portugal 81.44 33086 developing 37.91917
## 13 2017 Sweden 82.44 52739 developed 32.28167
## 14 2017 United States 78.85 60062 developed 44.28857
##Gini
wiid2017<-wiid2017%>%
arrange(gini)
orderGINI<-wiid2017$country
wiid2017$country
## [1] "Belarus" "Belgium" "Norway" "Sweden"
## [5] "France" "Germany" "Estonia" "Greece"
## [9] "Canada" "Portugal" "Latvia" "Lithuania"
## [13] "Bulgaria" "United States"
png("GINI.png")
plot(wiid2017$leb~wiid2017$gini,pch = 16, cex = 1.3, col = "blue",xlim=c(25,50), main = "Life expectancy at birth and Gini (2017)", xlab = "Gini", ylab = "Life expectancy at birth")
grid()
#abline(lm(wiid2017$leb~wiid2017$gini))
text(wiid2017$leb~wiid2017$gini, labels=orderGINI,data=wiid2017, cex=0.9, font=2,pos=4)
dev.off()
## quartz_off_screen
## 2
#GDP per capita
wiid2017<-wiid2017%>%
arrange(gdp)
orderGDP<-wiid2017$country
png("GDP.png")
plot(wiid2017$leb~wiid2017$gdp,pch = 16, cex = 1.3, col = "blue", xlim=c(20000,70000), main = "Life expectancy by birth and GDP per capita (2017)", xlab = "GDP per capita", ylab = "Life expectancy at birth")
grid()
#abline(lm(wiid2017$leb~wiid2017$gdp))
text(wiid2017$leb~wiid2017$gdp, labels=orderGDP,data=wiid2017, cex=0.9, font=2,pos=4)
dev.off()
## quartz_off_screen
## 2
#install.packages("modelsummary")
#install.packages("kableExtra")
#install.packages("gt")
#install.packages("systemfonts")
#install.packages("flextable")
library(modelsummary)
#library(kableExtra)
library(gt)
library(systemfonts)
library(flextable)
models <- list(
"Model 1 \n all countries" = plm(leb ~ gini+log(gdp),
data = wiid,
index = c("country", "year"),
model = "within"),
"Model 2 \n with interaction" = plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid,
index = c("country", "year"),
model = "within"),
"Model 3 \n High income countries" = plm(leb ~ gini+log(gdp),
data = wiid_developed,
index = c("country", "year"),
model = "within"),
"Model 4 \n High income countries " = plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid_developed,
index = c("country", "year"),
model = "within"),
"Model 5 \n Medium/low income countries" = plm(leb ~ gini+log(gdp),
data = wiid_developing,
index = c("country", "year"),
model = "within"),
"Model 6 \n Medium/low income countries" = plm(leb ~ gini+log(gdp)+gini*log(gdp),
data = wiid_developing,
index = c("country", "year"),
model = "within")
)
modelsummary(models, estimate = "{estimate}{stars}", output = "table.docx")
modelsummary(models, estimate = "{estimate}{stars}")
| Model 1 all countries | Model 2 with interaction | Model 3 High income countries | Model 4 High income countries | Model 5 Medium/low income countries | Model 6 Medium/low income countries | |
|---|---|---|---|---|---|---|
| gini | 0.111*** | -2.884*** | 0.046 | 1.763* | 0.056 | -3.768*** |
| (0.031) | (0.624) | (0.030) | (0.995) | (0.047) | (1.010) | |
| log(gdp) | 5.589*** | -3.963** | 11.901*** | 17.220*** | 5.187*** | -7.421** |
| (0.315) | (2.010) | (0.625) | (3.145) | (0.395) | (3.350) | |
| gini × log(gdp) | 0.290*** | -0.161* | 0.378*** | |||
| (0.060) | (0.093) | (0.100) | ||||
| Num.Obs. | 322 | 322 | 161 | 161 | 161 | 161 |
| R2 | 0.599 | 0.627 | 0.800 | 0.804 | 0.593 | 0.629 |
| R2 Adj. | 0.579 | 0.608 | 0.789 | 0.792 | 0.572 | 0.606 |