-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.R
More file actions
63 lines (49 loc) · 2.54 KB
/
model.R
File metadata and controls
63 lines (49 loc) · 2.54 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# PPHA 30536 1 - Data and Programming for Public Policy II - R Programming
# Data Skills 2 - R
## Fall Quarter 2024
# Date: 11.30.24
# Student: Natalia Zorrilla
# Final Project - OLS Model
## Due: December 7, 2024 before midnight on Gradescope
############################################################################################################
#IN THIS PART OF THE PROJECT WE'LL PERFORM AN OLS ANALYSIS ON NARCOTICS CRIMES, MENTAL HEALTH RESOURCES AND SOCIOECONOMIC INDICATORS
#install.packages(c("tidyverse", "stargazer", "car"))
library(tidyverse)
library(stargazer)
library(car)
#Clear all objects
rm(list=ls())
#To replicate this project, please set your working directory in this initial stage.
setwd("/Users/Natalia/Documents/The University of Chicago/Harris School of Public Policy/MPP/Fall quarter 2024/PPHA 30536 1 - Data and Programming for Public Policy II - R Programming /Assignments/Final project")
#Import data. If you don't have it, please run first data.R file
narcotics_health_project_data <- read_csv("narcotics_health_project_data.csv")
#We are going to perform three different OLS regressions adjusting the independent variables
#Narcotics and total providers
model_1 <- lm(narcotics_crime_rate ~ total_providers, data = narcotics_health_project_data)
#Table 1 with results
stargazer(model_1, type = "text", title = "Regression Results for Narcotics Crime Rate Model 1",
notes = "Standard errors in parentheses")
#Narcotics, total providers and crisis providers
model_2 <- lm(narcotics_crime_rate ~ total_providers + crisis_providers + Population, data = narcotics_health_project_data)
#Check for multicollinearity using VIF
vif(model_2)
#Table 2 with results
stargazer(model_2, type = "text", title = "Regression Results for Narcotics Crime Rate Model 2",
notes = "Standard errors in parentheses")
#Narcotics, total providers, crisis providers and socioeconomic indicators
model_3 <- lm(narcotics_crime_rate ~
total_providers +
crisis_providers +
Population +
Neighborhood_Safety_Rate +
Trust_Law_Enforcement_Rate +
Trust_Local_Government_Rate +
Unemployment_Rate +
Median_Household_Income,
data = narcotics_health_project_data)
#Table 3 with results
stargazer(model_3, type = "text",
title = "OLS Regression Results for Narcotics Crime Rate Model 3",
notes = "Standard errors in parentheses")
#Check for multicollinearity using VIF
vif(model_3)