this is comparison test 3 with minotor fixed effect

# library 
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(plm)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plm':
## 
##     between, lag, lead
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## load and rearrange data
test.dat <- load("D:/yang7916/Ozone_Drought_Final.RData/Ozone_Drought_Final.RData")

test.dat <- combinedAir.final

names(combinedAir.final)
##  [1] "MonitorID"             "Longitude"             "Latitude"             
##  [4] "Date..Local."          "GEOID"                 "month"                
##  [7] "Year"                  "State.Code"            "County.Code"          
## [10] "Site.Number"           "Parameter.Code"        "POC"                  
## [13] "Parameter.Name"        "Day.In.Year..Local."   "Exceptional.Data.Type"
## [16] "Observation.Count"     "Observation.Percent"   "Arithmetic.Mean"      
## [19] "First.Maximum.Value"   "First.Maximum.Hour"    "AQI"                  
## [22] "State.Name"            "County.Name"           "Local.Site.Name"      
## [25] "Max.Ozone"             "USDM.categorical"      "spei_12_DR_CAT"       
## [28] "eddi_12_DR_CAT"        "Urban.2013.full"       "ppt"                  
## [31] "tdmean"                "tmean"                 "elevation"
test.dat$USDM.categorical <- factor(test.dat$USDM.categorical, levels = c("NoDrought", "ModerateDrought", "SevereDrought"))
test.dat$USDM.categorical <- relevel(test.dat$USDM.categorical, ref = "NoDrought")


## model 1 
md1_random <- plm(Max.Ozone ~USDM.categorical, data = test.dat, model = "random", index = c("MonitorID", "Year","month"))
## 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")
md1_fix <- plm(Max.Ozone ~USDM.categorical, data = test.dat,  effect=("twoways"),model = "within", index = c("MonitorID", "Year","month"))
## 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(md1_random, md1_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 1", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 1
## ===================================================================================
##                                                 Dependent variable:                
##                                 ---------------------------------------------------
##                                         (1)                       (2)              
## -----------------------------------------------------------------------------------
## USDM.categoricalModerateDrought      1.262***                  1.348***            
##                                       (0.014)                   (0.014)            
##                                                                                    
## USDM.categoricalSevereDrought        2.529***                  2.921***            
##                                       (0.020)                   (0.021)            
##                                                                                    
## Constant                             42.415***                                     
##                                       (0.116)                                      
##                                                                                    
## -----------------------------------------------------------------------------------
## Model Name                      Random Effect Model       Fixed Effect Model       
## Observations                         6,608,332                 6,608,332           
## R2                                     0.006                     0.003             
## Adjusted R2                            0.006                     0.003             
## F Statistic                        19,007.910***    11,454.870*** (df = 2; 6606349)
## ===================================================================================
## Note:                                                   *p<0.1; **p<0.05; ***p<0.01
## model 2
md2_random<- plm(Max.Ozone ~ USDM.categorical +elevation+ Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md2_fix<- plm(Max.Ozone ~ USDM.categorical +elevation+ Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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(md2_random, md2_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 2", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 2
## ==================================================================================
##                                                Dependent variable:                
##                                 --------------------------------------------------
##                                         (1)                      (2)              
## ----------------------------------------------------------------------------------
## USDM.categoricalModerateDrought      1.261***                  1.348***           
##                                       (0.014)                  (0.014)            
##                                                                                   
## USDM.categoricalSevereDrought        2.528***                  2.922***           
##                                       (0.020)                  (0.021)            
##                                                                                   
## elevation                            0.004***                  0.004***           
##                                      (0.0002)                  (0.001)            
##                                                                                   
## Longitude                            0.044***                 -3.812***           
##                                       (0.007)                  (0.928)            
##                                                                                   
## Latitude                             -0.191***                 -4.697*            
##                                       (0.024)                  (2.819)            
##                                                                                   
## Constant                             51.871***                                    
##                                       (1.199)                                     
##                                                                                   
## ----------------------------------------------------------------------------------
## Model Name                      Random Effect Model       Fixed Effect Model      
## Observations                         6,608,332                6,608,332           
## R2                                     0.006                    0.003             
## Adjusted R2                            0.006                    0.003             
## F Statistic                        19,589.350***    4,591.235*** (df = 5; 6606346)
## ==================================================================================
## Note:                                                  *p<0.1; **p<0.05; ***p<0.01
## model 3

md3_random <- plm(Max.Ozone ~ USDM.categorical + tmean +
elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md3_fix <- plm(Max.Ozone ~ USDM.categorical + tmean+
elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md3_random, md3_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 3", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 3
## ====================================================================================
##                                                 Dependent variable:                 
##                                 ----------------------------------------------------
##                                         (1)                       (2)               
## ------------------------------------------------------------------------------------
## USDM.categoricalModerateDrought      1.138***                   1.213***            
##                                       (0.013)                   (0.013)             
##                                                                                     
## USDM.categoricalSevereDrought        1.392***                   1.738***            
##                                       (0.019)                   (0.019)             
##                                                                                     
## tmean                                0.644***                   0.639***            
##                                       (0.001)                   (0.001)             
##                                                                                     
## elevation                            0.006***                    -0.001             
##                                      (0.0002)                   (0.001)             
##                                                                                     
## Longitude                            0.050***                  -6.629***            
##                                       (0.006)                   (0.861)             
##                                                                                     
## Latitude                             0.180***                   -5.105*             
##                                       (0.020)                   (2.614)             
##                                                                                     
## Constant                             27.028***                                      
##                                       (0.999)                                       
##                                                                                     
## ------------------------------------------------------------------------------------
## Model Name                      Random Effect Model        Fixed Effect Model       
## Observations                         6,608,332                 6,608,332            
## R2                                     0.147                     0.143              
## Adjusted R2                            0.147                     0.142              
## F Statistic                      1,102,463.000***   183,286.600*** (df = 6; 6606345)
## ====================================================================================
## Note:                                                    *p<0.1; **p<0.05; ***p<0.01
## model 4 

md4_random <- plm(Max.Ozone ~  tmean+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md4_fix <- plm(Max.Ozone ~  tmean+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md4_random, md4_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 4", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 4
## =================================================================
##                              Dependent variable:                 
##              ----------------------------------------------------
##                      (1)                       (2)               
## -----------------------------------------------------------------
## tmean             0.646***                   0.642***            
##                    (0.001)                   (0.001)             
##                                                                  
## elevation         0.006***                   -0.002**            
##                   (0.0002)                   (0.001)             
##                                                                  
## Longitude         0.040***                  -6.478***            
##                    (0.006)                   (0.861)             
##                                                                  
## Latitude          0.163***                  -10.136***           
##                    (0.020)                   (2.616)             
##                                                                  
## Constant          27.019***                                      
##                    (1.030)                                       
##                                                                  
## -----------------------------------------------------------------
## Model Name   Random Effect Model        Fixed Effect Model       
## Observations      6,608,332                 6,608,332            
## R2                  0.145                     0.141              
## Adjusted R2         0.145                     0.141              
## F Statistic   1,090,206.000***   271,194.500*** (df = 4; 6606347)
## =================================================================
## Note:                                 *p<0.1; **p<0.05; ***p<0.01
## model 5 


md5_random <- plm(Max.Ozone ~  ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md5_fix <- plm(Max.Ozone ~  ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md5_random, md5_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 5", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 5
## ================================================================
##                              Dependent variable:                
##              ---------------------------------------------------
##                      (1)                       (2)              
## ----------------------------------------------------------------
## ppt               -0.230***                 -0.228***           
##                    (0.001)                   (0.001)            
##                                                                 
## elevation         0.004***                    0.002             
##                   (0.0002)                   (0.001)            
##                                                                 
## Longitude         0.043***                  -3.275***           
##                    (0.008)                   (0.921)            
##                                                                 
## Latitude          -0.225***                -12.533***           
##                    (0.025)                   (2.798)            
##                                                                 
## Constant          54.158***                                     
##                    (1.241)                                      
##                                                                 
## ----------------------------------------------------------------
## Model Name   Random Effect Model       Fixed Effect Model       
## Observations      6,608,332                 6,608,332           
## R2                  0.021                     0.018             
## Adjusted R2         0.021                     0.018             
## F Statistic    122,290.100***    30,122.480*** (df = 4; 6606347)
## ================================================================
## Note:                                *p<0.1; **p<0.05; ***p<0.01
## model 6


md6_random <- plm(Max.Ozone ~  tdmean+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md6_fix <- plm(Max.Ozone ~  tdmean+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md6_random, md6_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 6", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 6
## ================================================================
##                              Dependent variable:                
##              ---------------------------------------------------
##                      (1)                       (2)              
## ----------------------------------------------------------------
## tdmean            0.321***                  0.318***            
##                    (0.001)                   (0.001)            
##                                                                 
## elevation         0.006***                    0.001             
##                   (0.0002)                   (0.001)            
##                                                                 
## Longitude          -0.003                   -3.977***           
##                    (0.008)                   (0.914)            
##                                                                 
## Latitude          -0.078***                 -7.205***           
##                    (0.025)                   (2.776)            
##                                                                 
## Constant          40.112***                                     
##                    (1.236)                                      
##                                                                 
## ----------------------------------------------------------------
## Model Name   Random Effect Model       Fixed Effect Model       
## Observations      6,608,332                 6,608,332           
## R2                  0.037                     0.033             
## Adjusted R2         0.037                     0.033             
## F Statistic    230,301.800***    56,814.670*** (df = 4; 6606347)
## ================================================================
## Note:                                *p<0.1; **p<0.05; ***p<0.01
## model 7

md7_random <- plm(Max.Ozone ~  tdmean+tmean+ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md7_fix <- plm(Max.Ozone ~  tdmean+tmean+ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md7_random, md7_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 7", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 7
## =================================================================
##                              Dependent variable:                 
##              ----------------------------------------------------
##                      (1)                       (2)               
## -----------------------------------------------------------------
## tdmean            -0.850***                 -0.858***            
##                    (0.001)                   (0.001)             
##                                                                  
## tmean             1.364***                   1.367***            
##                    (0.001)                   (0.001)             
##                                                                  
## ppt               -0.134***                 -0.131***            
##                    (0.001)                   (0.001)             
##                                                                  
## elevation         0.004***                  -0.004***            
##                   (0.0002)                   (0.001)             
##                                                                  
## Longitude         0.143***                  -8.219***            
##                    (0.006)                   (0.820)             
##                                                                  
## Latitude          0.211***                  -21.447***           
##                    (0.020)                   (2.492)             
##                                                                  
## Constant          31.869***                                      
##                    (1.023)                                       
##                                                                  
## -----------------------------------------------------------------
## Model Name   Random Effect Model        Fixed Effect Model       
## Observations      6,608,332                 6,608,332            
## R2                  0.223                     0.221              
## Adjusted R2         0.223                     0.220              
## F Statistic   1,865,932.000***   311,826.400*** (df = 6; 6606345)
## =================================================================
## Note:                                 *p<0.1; **p<0.05; ***p<0.01
## model 8


md8_random <- plm(Max.Ozone ~ USDM.categorical+ tdmean+tmean+ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "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")
md8_fix <- plm(Max.Ozone ~  USDM.categorical+tdmean+tmean+ppt+elevation + Longitude + Latitude,
data=test.dat,
index = c("MonitorID", "Year","month"),
model = "within",
effect = "twoways"
)
## 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(md8_random, md8_fix, type = "text", title = "Comparison of Random and Fixed Effect Models 8", align = TRUE, 
          add.lines = list(c("Model Name", "Random Effect Model", "Fixed Effect Model")), 
          dep.var.labels.include = FALSE)
## 
## Comparison of Random and Fixed Effect Models 8
## ====================================================================================
##                                                 Dependent variable:                 
##                                 ----------------------------------------------------
##                                         (1)                       (2)               
## ------------------------------------------------------------------------------------
## USDM.categoricalModerateDrought      0.489***                   0.640***            
##                                       (0.012)                   (0.012)             
##                                                                                     
## USDM.categoricalSevereDrought        0.277***                   0.657***            
##                                       (0.018)                   (0.018)             
##                                                                                     
## tdmean                               -0.847***                 -0.854***            
##                                       (0.001)                   (0.001)             
##                                                                                     
## tmean                                1.361***                   1.362***            
##                                       (0.001)                   (0.001)             
##                                                                                     
## ppt                                  -0.134***                 -0.131***            
##                                       (0.001)                   (0.001)             
##                                                                                     
## elevation                            0.004***                  -0.004***            
##                                      (0.0002)                   (0.001)             
##                                                                                     
## Longitude                            0.146***                  -8.204***            
##                                       (0.006)                   (0.820)             
##                                                                                     
## Latitude                             0.217***                  -19.220***           
##                                       (0.020)                   (2.492)             
##                                                                                     
## Constant                             31.849***                                      
##                                       (0.998)                                       
##                                                                                     
## ------------------------------------------------------------------------------------
## Model Name                      Random Effect Model        Fixed Effect Model       
## Observations                         6,608,332                 6,608,332            
## R2                                     0.223                     0.221              
## Adjusted R2                            0.223                     0.221              
## F Statistic                      1,868,030.000***   234,361.500*** (df = 8; 6606343)
## ====================================================================================
## Note:                                                    *p<0.1; **p<0.05; ***p<0.01