if(!is.null(dev.list())) dev.off()null device
1
cat("\014")rm(list = ls())if(!is.null(dev.list())) dev.off()null device
1
cat("\014")rm(list = ls())library(foreign)
library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.2
✔ ggplot2 4.0.0 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(tinytex)
library(summarytools)Warning: package 'summarytools' was built under R version 4.5.2
Attaching package: 'summarytools'
The following object is masked from 'package:tibble':
view
library(knitr)
library(ivreg)Warning: package 'ivreg' was built under R version 4.5.2
library(stargazer)Warning: package 'stargazer' was built under R version 4.5.2
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
theUrl_ca2a_ectrics2 <- "https://surfdrive.surf.nl/files/index.php/s/9rH7XWcOqm6eniR/download"
literacy <- read.dta (file = theUrl_ca2a_ectrics2)
literacy <- na.omit(literacy)plot(literacy$kmwittenberg, literacy$inctax,
xlab="Distance from Wittenberg", ylab="Income tax revenues per capita",
ylim = c(0, 400))
abline(lm(literacy$inctaxpc ~ literacy$kmwittenberg))reg_te <- ivreg(inctaxpc ~ f_prot + f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss | f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss + kmwittenberg, data=literacy)
stargazer(reg_te, type="text")
===============================================
Dependent variable:
---------------------------
inctaxpc
-----------------------------------------------
f_prot 0.835***
(0.276)
f_jew 11.407**
(4.435)
f_fem -23.015***
(3.029)
f_young -6.758***
(1.924)
f_pruss 3.073
(2.066)
hhsize -43.951***
(12.903)
pop -0.00001
(0.0002)
gpop 0.162
(1.092)
f_miss -10.438***
(3.446)
Constant 1,401.692***
(267.109)
-----------------------------------------------
Observations 426
R2 0.195
Adjusted R2 0.178
Residual Std. Error 63.810 (df = 416)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
a) 0.835 Marks
summary(literacy$f_prot) Min. 1st Qu. Median Mean 3rd Qu. Max.
0.2576 24.2803 84.7366 64.2521 98.2670 99.8888
b)
1st quartile: 24.2803
3rd quartile: 98.2670
Difference in percentage points = 98.2670 - 24.2803 = 73.9867.
0.835*73.9867 = 61.77889
Compared to the mean: 61.77889 / 198.3194 = 0.3115121 = 31,15% increase in per capita income tax revenues.
Mean per capita income tax revenues: 198.3194
mean(literacy$inctaxpc)[1] 198.3194
c)
Prosperity
Protestantism
Literacy
Protestantism
reg_ie1 <- ivreg(f_rw ~ f_prot + f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss | f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss + kmwittenberg, data=literacy)
stargazer(reg_ie1, type="text")
===============================================
Dependent variable:
---------------------------
f_rw
-----------------------------------------------
f_prot 0.303***
(0.057)
f_jew 1.557*
(0.918)
f_fem -3.608***
(0.627)
f_young -1.780***
(0.398)
f_pruss -0.212
(0.428)
hhsize -6.145**
(2.671)
pop -0.0001***
(0.00004)
gpop -0.102
(0.226)
f_miss -2.131***
(0.713)
Constant 356.536***
(55.290)
-----------------------------------------------
Observations 426
R2 -0.029
Adjusted R2 -0.052
Residual Std. Error 13.208 (df = 416)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
d) 0.303. If share of Protestantism increases by 1 percentage point, then share if literate population increases by 0.303 percentage points.
e) 0.083
reg_ie2 <- ivreg(inctaxpc ~ f_rw + f_prot + f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss | f_prot + f_jew + f_fem + f_young + f_pruss + hhsize + pop
+ gpop + f_miss + kmwittenberg, data=literacy)
stargazer(reg_ie2, type="text")
===============================================
Dependent variable:
---------------------------
inctaxpc
-----------------------------------------------
f_rw 2.484***
(0.855)
f_prot 0.083
(0.084)
f_jew 7.539**
(3.282)
f_fem -14.052***
(4.091)
f_young -2.336
(2.193)
f_pruss 3.601*
(1.926)
hhsize -28.687**
(14.302)
pop 0.0003*
(0.0002)
gpop 0.416
(1.025)
f_miss -5.145*
(2.937)
Constant 516.056
(445.571)
-----------------------------------------------
Observations 426
R2 0.345
Adjusted R2 0.329
Residual Std. Error 57.648 (df = 415)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01
f) Total effect = direct + indirect effect so: 0.835 = 0.083 + indirect effect, thus indirect effect = 0.835 - 0.083 = 0.752.
Product of two indirect effects: 0.303*2.484 = 0.752652.
g) Indirect effect / total effect: 0.752 / 0.835 = 90.1%