First we have to set our working directory, load in our data, and load the packages we will be using to make our figures.
setwd("C:/Users/jedia/Desktop/RWD")
qogts<-read.csv("C:/Users/jedia/Desktop/RWD/qog_std_ts_jan21.csv")
library(sjPlot)
## Learn more about sjPlot with 'browseVignettes("sjPlot")'.
library(sjmisc)
## Learn more about sjmisc with 'browseVignettes("sjmisc")'.
library(sjlabelled)
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following object is masked from 'package:sjlabelled':
##
## as_label
We now need to make plots to show the basic relationship between our main variable, and our most significant control
plot(qogts$oecd_incinequal_t1a ~ qogts$wdi_expeduge, xlab="Education Spending", ylab="Gini Income Inequality", main="Income Inequality vs Education Spending")
plot(qogts$oecd_incinequal_t1a ~ qogts$eu_sctgitt, xlab="% of Workers in Retail/Food Service", ylab="Income Inequality", main="Income Inequality vs % of Workers in Retail/Food Service")
We now have to run our two regressions. The first one is just looking at the relationship between education spending and income inequality, while the second one has controls.
polpov<-lm(oecd_incinequal_t1a ~ wdi_expeduge, qogts)
summary(polpov)
##
## Call:
## lm(formula = oecd_incinequal_t1a ~ wdi_expeduge, data = qogts)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.111993 -0.037889 -0.006592 0.040595 0.257812
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.195238 0.014100 13.85 < 2e-16 ***
## wdi_expeduge 0.008928 0.001060 8.42 1.4e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0567 on 311 degrees of freedom
## (15512 observations deleted due to missingness)
## Multiple R-squared: 0.1856, Adjusted R-squared: 0.183
## F-statistic: 70.89 on 1 and 311 DF, p-value: 1.403e-15
polpovcontrol<-lm(oecd_incinequal_t1a ~ wdi_expeduge + gcb_bed + eu_sctgitt + hf_taxbur, qogts)
summary(polpovcontrol)
##
## Call:
## lm(formula = oecd_incinequal_t1a ~ wdi_expeduge + gcb_bed + eu_sctgitt +
## hf_taxbur, data = qogts)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.047078 -0.018932 -0.006797 0.009822 0.079401
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0060128 0.0626543 -0.096 0.9241
## wdi_expeduge 0.0042265 0.0022054 1.916 0.0635 .
## gcb_bed 0.3844950 0.2290314 1.679 0.1021
## eu_sctgitt 0.0095950 0.0016711 5.742 1.69e-06 ***
## hf_taxbur 0.0008809 0.0004415 1.995 0.0539 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.03054 on 35 degrees of freedom
## (15785 observations deleted due to missingness)
## Multiple R-squared: 0.5361, Adjusted R-squared: 0.483
## F-statistic: 10.11 on 4 and 35 DF, p-value: 1.511e-05
Next we have to make out graphs for our regressions.
plot_model(polpov, type="pred", terms = "wdi_expeduge", show.data=TRUE)+xlab("Spending on Education as a % of Total Expenditures")+ylab("Gini Income Inequality")+ggtitle("Education Spending and Income Inequality")+theme_bw()
plot_model(polpovcontrol, type = "pred", terms = "wdi_expeduge", show.data=TRUE)+xlab("Spending on Education as a % of Total Expenditures")+ylab("Gini Income Inequality")+ggtitle("Income Inequality and Education Spending, with Controls")+theme_bw()
Now we just need to make a table to show our results in a more concise manner
tab_model(polpov, polpovcontrol, show.ci=FALSE, pred.labels = c("Intercept", "Education Spending", "Paid Bribes in Education", "% of Workers in Retail/Food Service", "Tax Burden"), dv.labels=c("Without Controls", "With Controls"))
## Argument 'df_method' is deprecated. Please use 'ci_method' instead.
## Argument 'df_method' is deprecated. Please use 'ci_method' instead.
| Without Controls | With Controls | |||
|---|---|---|---|---|
| Predictors | Estimates | p | Estimates | p |
| Intercept | 0.20 | <0.001 | -0.01 | 0.924 |
| Education Spending | 0.01 | <0.001 | 0.00 | 0.064 |
| Paid Bribes in Education | 0.38 | 0.102 | ||
| % of Workers in Retail/Food Service | 0.01 | <0.001 | ||
| Tax Burden | 0.00 | 0.054 | ||
| Observations | 313 | 40 | ||
| R2 / R2 adjusted | 0.186 / 0.183 | 0.536 / 0.483 | ||
Finally, we just need to export our files and upload them to the document