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)

—- Data —-

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")

— States in Northwest Region —

nw <- df2 %>%
    filter(noaa_region == "northwest")

kable(unique(nw$State.Name), caption = "States in Northwest Region")
States in Northwest Region
x
Idaho
Oregon
Washington

— Idaho —

id <- nw %>%
    filter(State.Name == "Idaho")

id_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = id,
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")
id_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = id,
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(id_random, id_fix, type = "text", title = "Idaho", 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 = "#")
## 
## Idaho
## ===========================================================
##                      Dependent Variable: Ozone Max         
##              ----------------------------------------------
##              Random Effect Model     Fixed Effect Model    
## -----------------------------------------------------------
## moderate           -0.049                -1.093***         
##                    (0.187)                (0.281)          
##                                                            
## severe            -2.646***              -6.222***         
##                    (0.297)                (0.439)          
##                                                            
## elevation         -0.087***               -0.137**         
##                    (0.006)                (0.061)          
##                                                            
## Longitude         33.629***              66.220***         
##                    (2.108)                (9.903)          
##                                                            
## Latitude          -1.560***              -83.257***        
##                    (0.278)                (24.543)         
##                                                            
## Constant        4,098.243***                               
##                   (251.051)                                
##                                                            
## -----------------------------------------------------------
## Model Name   Random Effect Model     Fixed Effect Model    
## Observations       16,726                  16,726          
## R2                  0.161                  0.063           
## Adjusted R2         0.161                  0.061           
## F Statistic      393.270***      222.868*** (df = 5; 16696)
## ===========================================================
## Note:                           *p<0.1; **p<0.05; ***p<0.01

— Oregon —

or <- nw %>%
    filter(State.Name == "Oregon")

or_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = or,
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")
or_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = or,
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(or_random, or_fix, type = "text", title = "Oregon", 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 = "#")
## 
## Oregon
## ===========================================================
##                      Dependent Variable: Ozone Max         
##              ----------------------------------------------
##              Random Effect Model     Fixed Effect Model    
## -----------------------------------------------------------
## moderate           0.348**                 -0.034          
##                    (0.155)                (0.207)          
##                                                            
## severe            1.170***                 -0.661          
##                    (0.353)                (0.431)          
##                                                            
## elevation         0.007***                0.031***         
##                    (0.001)                (0.002)          
##                                                            
## Longitude         -4.612***              -33.276***        
##                    (0.753)                (1.537)          
##                                                            
## Latitude          -3.964***              -17.084***        
##                    (0.794)                (1.297)          
##                                                            
## Constant         -350.523***                               
##                   (108.720)                                
##                                                            
## -----------------------------------------------------------
## Model Name   Random Effect Model     Fixed Effect Model    
## Observations       29,932                  29,932          
## R2                  0.015                  0.021           
## Adjusted R2         0.015                  0.020           
## F Statistic      153.204***      126.682*** (df = 5; 29898)
## ===========================================================
## Note:                           *p<0.1; **p<0.05; ***p<0.01

— Washington —

ws <- nw %>%
    filter(State.Name == "Washington")

ws_random <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = ws,
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")
ws_fix <- plm(Max.Ozone ~ moderate + severe + elevation + Longitude + Latitude,
data = ws,
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(ws_random, ws_fix, type = "text", title = "Washington", 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 = "#")
## 
## Washington
## ===========================================================
##                      Dependent Variable: Ozone Max         
##              ----------------------------------------------
##              Random Effect Model     Fixed Effect Model    
## -----------------------------------------------------------
## moderate          0.784***               -0.424***         
##                    (0.114)                (0.158)          
##                                                            
## severe            -1.144***              -4.649***         
##                    (0.372)                (0.439)          
##                                                            
## elevation         0.012***                0.012***         
##                   (0.0002)                (0.0002)         
##                                                            
## Longitude         -3.424***              -4.292***         
##                    (0.157)                (0.174)          
##                                                            
## Latitude          -2.410***              -2.394***         
##                    (0.380)                (0.397)          
##                                                            
## Constant         -270.013***                               
##                   (25.348)                                 
##                                                            
## -----------------------------------------------------------
## Model Name   Random Effect Model     Fixed Effect Model    
## Observations       58,680                  58,680          
## R2                  0.072                  0.069           
## Adjusted R2         0.071                  0.068           
## F Statistic     4,208.798***     863.773*** (df = 5; 58645)
## ===========================================================
## Note:                           *p<0.1; **p<0.05; ***p<0.01