All installed packages were loaded to be used in the R Program.
library(stargazer)
##
## 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
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── 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(plm)
##
## Attaching package: 'plm'
##
## The following objects are masked from 'package:dplyr':
##
## between, lag, lead
library(knitr)
test.dat <- load("Ozone_Drought_Final.RData")
regions <- read.csv("region_code.csv")
df <- combinedAir.final
df$State.Code <- as.numeric(df$State.Code)
df$month = as.numeric(df$month)
df1 <- df %>%
mutate(no_drought = ifelse(USDM.categorical == "NoDrought", 1, 0),
moderate = ifelse(USDM.categorical == "ModerateDrought", 1, 0),
severe = ifelse(USDM.categorical == "SevereDrought", 1, 0))
df2 <- df1 %>%
merge(regions, by = "State.Code")
um <- df2 %>%
filter(noaa_region == "upper_midwest")
kable(unique(um$State.Name), caption = "States in Upper Midwest Region")
x |
---|
Iowa |
Michigan |
Minnesota |
Wisconsin |
iw <- um %>%
filter(State.Name == "Iowa")
iw_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = iw,
index = c("GEOID", "Year", "month"),
model = ("random"))
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
iw_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = iw,
index = c("GEOID", "Year", "month"),
effect = "twoway")
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
stargazer(iw_random, iw_fix, type = "text", title = "Iowa", align = TRUE,
add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")),
column.labels = c("Random Effect Model", "Fixed Effect Model"),
dep.var.caption = "Dependent Variable: Ozone Max",
dep.var.labels.include = FALSE,
omit.table.layout = "#")
##
## Iowa
## ===========================================================
## Dependent Variable: Ozone Max
## ----------------------------------------------
## Random Effect Model Fixed Effect Model
## -----------------------------------------------------------
## moderate -0.252** -2.312***
## (0.126) (0.140)
##
## severe -0.459 -7.394***
## (0.299) (0.344)
##
## elevation 0.090*** 0.195***
## (0.005) (0.009)
##
## Longitude 3.280*** 19.072***
## (0.284) (1.683)
##
## Latitude -6.376*** -28.931***
## (0.696) (1.572)
##
## Constant 586.496***
## (45.297)
##
## -----------------------------------------------------------
## Model Name Random Effect Model Fixed Effect Model
## Observations 76,215 76,215
## R2 0.009 0.017
## Adjusted R2 0.009 0.016
## F Statistic 413.537*** 256.487*** (df = 5; 76181)
## ===========================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
mc <- um %>%
filter(State.Name == "Michigan")
mc_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = mc,
index = c("GEOID", "Year", "month"),
model = ("random"))
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
mc_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = mc,
index = c("GEOID", "Year", "month"),
effect = "twoway")
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
stargazer(mc_random, mc_fix, type = "text", title = "Michigan", align = TRUE,
add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")),
column.labels = c("Random Effect Model", "Fixed Effect Model"),
dep.var.caption = "Dependent Variable: Ozone Max",
dep.var.labels.include = FALSE,
omit.table.layout = "#")
##
## Michigan
## ============================================================
## Dependent Variable: Ozone Max
## -----------------------------------------------
## Random Effect Model Fixed Effect Model
## ------------------------------------------------------------
## moderate 1.677*** -0.032
## (0.149) (0.155)
##
## severe 14.252*** 11.333***
## (2.465) (2.418)
##
## elevation 0.034*** 0.010**
## (0.003) (0.005)
##
## Longitude 6.180*** 18.516***
## (0.337) (0.690)
##
## Latitude 0.955** 0.701
## (0.405) (1.177)
##
## Constant 518.479***
## (32.392)
##
## ------------------------------------------------------------
## Model Name Random Effect Model Fixed Effect Model
## Observations 110,141 110,141
## R2 0.010 0.011
## Adjusted R2 0.010 0.010
## F Statistic 710.454*** 234.694*** (df = 5; 110092)
## ============================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
mn <- um %>%
filter(State.Name == "Minnesota")
mn_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = mn,
index = c("GEOID", "Year", "month"),
model = ("random"))
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
mn_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = mn,
index = c("GEOID", "Year", "month"),
effect = "twoway")
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
stargazer(mn_random, mn_fix, type = "text", title = "Minnesota", align = TRUE,
add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")),
column.labels = c("Random Effect Model", "Fixed Effect Model"),
dep.var.caption = "Dependent Variable: Ozone Max",
dep.var.labels.include = FALSE,
omit.table.layout = "#")
##
## Minnesota
## ===========================================================
## Dependent Variable: Ozone Max
## ----------------------------------------------
## Random Effect Model Fixed Effect Model
## -----------------------------------------------------------
## moderate -0.347*** -1.569***
## (0.113) (0.124)
##
## severe -2.455*** -5.642***
## (0.335) (0.349)
##
## elevation 0.085*** 0.117***
## (0.006) (0.008)
##
## Longitude -0.643 29.077***
## (0.477) (1.789)
##
## Latitude 0.640** 13.219***
## (0.259) (0.760)
##
## Constant -77.943**
## (36.787)
##
## -----------------------------------------------------------
## Model Name Random Effect Model Fixed Effect Model
## Observations 61,660 61,660
## R2 0.013 0.014
## Adjusted R2 0.013 0.014
## F Statistic 544.816*** 179.157*** (df = 5; 61621)
## ===========================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
wc <- um %>%
filter(State.Name == "Wisconsin")
wc_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = wc,
index = c("GEOID", "Year", "month"),
model = ("random"))
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
wc_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = wc,
index = c("GEOID", "Year", "month"),
effect = "twoway")
## Warning in pdata.frame(data, index): duplicate couples (id-time) in resulting pdata.frame
## to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
stargazer(wc_random, wc_fix, type = "text", title = "Winsconsin", align = TRUE,
add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")),
column.labels = c("Random Effect Model", "Fixed Effect Model"),
dep.var.caption = "Dependent Variable: Ozone Max",
dep.var.labels.include = FALSE,
omit.table.layout = "#")
##
## Winsconsin
## ===========================================================
## Dependent Variable: Ozone Max
## ----------------------------------------------
## Random Effect Model Fixed Effect Model
## -----------------------------------------------------------
## moderate -0.179* -1.574***
## (0.107) (0.117)
##
## severe 3.454*** 1.078***
## (0.398) (0.406)
##
## elevation -0.006** -0.027***
## (0.003) (0.004)
##
## Longitude 1.059*** 4.688***
## (0.321) (1.035)
##
## Latitude -0.488 6.401***
## (0.358) (1.024)
##
## Constant 159.862***
## (29.326)
##
## -----------------------------------------------------------
## Model Name Random Effect Model Fixed Effect Model
## Observations 134,339 134,339
## R2 0.008 0.003
## Adjusted R2 0.008 0.002
## F Statistic 106.903*** 72.091*** (df = 5; 134283)
## ===========================================================
## Note: *p<0.1; **p<0.05; ***p<0.01