All installed packages were loaded to be used in the R Program.
library(plm)
library(knitr)
library(stringr)
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(tidyr)
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
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
—- Data —-
df <- load('Ozone_Drought_Final.RData')
df2 <- combinedAir.final
df3 <- read.csv("region_code.csv")
df2$State.Code = as.numeric(df2$State.Code)
df4 <- df2 %>%
merge(df3, by = "State.Code")
— Calculating the Statistics (Total Monitor, Mean, SD) —
df5 <- df4 %>%
group_by(State.Name, USDM.categorical) %>%
summarize(total_monitor = n(),
mean_O3 = mean(Max.Ozone),
sd = sd(Max.Ozone))
## `summarise()` has grouped output by 'State.Name'. You can override using the
## `.groups` argument.
df6 <- df5 %>%
group_by(State.Name) %>%
mutate(percentage = (total_monitor/sum(total_monitor))*100)
df8 <- df4 %>%
group_by(USDM.categorical) %>%
summarize(total_monitor = n(),
mean_O3 = mean(Max.Ozone),
sd = sd(Max.Ozone)) %>%
ungroup() %>%
mutate(percentage = (total_monitor/sum(total_monitor))*100,
State.Name = "Overall")
df9 <- df6 %>%
rbind(df8)
df7 <- df9 %>%
pivot_wider(names_from = USDM.categorical, values_from = c(total_monitor, mean_O3, percentage, sd)) %>%
mutate_if(is.numeric, funs(round(., 2)))
## `mutate_if()` ignored the following grouping variables:
## • Column `State.Name`
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## ℹ Please use a list of either functions or lambdas:
##
## # Simple named list: list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
##
## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
— Statistics Table —
# Move No Drought column to first column
df10 <- df7[, 1:4]
df11 <- df10[, c(1, 3, 2, 4)]
# Move the Overall row to the first row
ovr <- df11[df11$State.Name == "Overall", ]
df12 <- rbind(ovr, df11[df11$State.Name != "Overall", ])
kable(df12, caption = "Total Monitors", align = c("l", "c", "c", "c"))
Total Monitors
Overall |
4488807 |
1489317 |
611303 |
Alabama |
79554 |
20489 |
10654 |
Arizona |
55625 |
129243 |
71580 |
Arkansas |
36344 |
10846 |
2432 |
California |
522397 |
395018 |
225540 |
Colorado |
116004 |
52083 |
17270 |
Connecticut |
38670 |
6051 |
516 |
Delaware |
31838 |
4021 |
663 |
Florida |
280376 |
70340 |
22832 |
Georgia |
58139 |
25744 |
14517 |
Idaho |
7274 |
7437 |
2015 |
Illinois |
190976 |
27352 |
4605 |
Indiana |
145407 |
12312 |
1819 |
Iowa |
64312 |
10326 |
1577 |
Kansas |
41691 |
12993 |
4492 |
Kentucky |
129993 |
13638 |
2355 |
Louisiana |
130771 |
27624 |
9617 |
Maine |
63384 |
8374 |
294 |
Maryland |
71164 |
9524 |
1212 |
Massachusetts |
70294 |
8795 |
1733 |
Michigan |
100919 |
9191 |
31 |
Minnesota |
48068 |
12428 |
1164 |
Mississippi |
39139 |
7975 |
2215 |
Missouri |
86701 |
18673 |
2789 |
Montana |
18594 |
7252 |
1599 |
Nebraska |
15640 |
3815 |
1115 |
Nevada |
53296 |
54330 |
40135 |
New Hampshire |
47737 |
5956 |
744 |
New Jersey |
80788 |
10921 |
853 |
New Mexico |
62855 |
54949 |
28824 |
New York |
186049 |
17319 |
999 |
North Carolina |
134856 |
34656 |
13852 |
North Dakota |
38183 |
14217 |
1315 |
Ohio |
191516 |
18006 |
696 |
Oklahoma |
91517 |
35628 |
14100 |
Oregon |
21096 |
7648 |
1188 |
Pennsylvania |
247302 |
18351 |
774 |
Rhode Island |
11002 |
1260 |
29 |
South Carolina |
65301 |
29214 |
12940 |
South Dakota |
18989 |
7054 |
3022 |
Tennessee |
95095 |
20922 |
6031 |
Texas |
300886 |
129517 |
53699 |
Utah |
38866 |
44382 |
11849 |
Vermont |
12278 |
1330 |
NA |
Virginia |
92936 |
14566 |
1425 |
Washington |
46621 |
11217 |
842 |
West Virginia |
35876 |
1629 |
89 |
Wisconsin |
115754 |
17514 |
1071 |
Wyoming |
56734 |
27187 |
12190 |
# Move No Drought column to first column
df13 <- df7[, c(1,5:7)]
df14 <- df13[, c(1, 3, 2, 4)]
# Move the Overall row to the first row
ovr <- df14[df14$State.Name == "Overall", ]
df15 <- rbind(ovr, df14[df14$State.Name != "Overall", ])
kable(df15, caption = "Ozone Max", align = c("l", "c", "c", "c"))
Ozone Max
Overall |
41.53 |
44.03 |
45.99 |
Alabama |
42.12 |
45.50 |
48.64 |
Arizona |
48.57 |
45.83 |
51.38 |
Arkansas |
39.42 |
42.08 |
42.37 |
California |
41.44 |
44.81 |
44.98 |
Colorado |
45.57 |
47.11 |
47.64 |
Connecticut |
44.63 |
44.89 |
36.04 |
Delaware |
40.58 |
45.86 |
44.46 |
Florida |
37.53 |
41.15 |
41.95 |
Georgia |
43.22 |
47.66 |
48.02 |
Idaho |
44.92 |
45.56 |
44.31 |
Illinois |
37.98 |
36.68 |
36.28 |
Indiana |
44.99 |
48.85 |
54.69 |
Iowa |
40.62 |
40.39 |
40.56 |
Kansas |
39.02 |
41.06 |
43.91 |
Kentucky |
44.15 |
49.61 |
48.11 |
Louisiana |
39.02 |
40.49 |
45.82 |
Maine |
37.62 |
36.37 |
31.99 |
Maryland |
44.76 |
48.09 |
48.89 |
Massachusetts |
40.07 |
37.57 |
32.90 |
Michigan |
43.30 |
45.34 |
62.97 |
Minnesota |
38.48 |
38.01 |
35.16 |
Mississippi |
42.81 |
45.66 |
49.71 |
Missouri |
45.22 |
44.95 |
49.64 |
Montana |
37.82 |
36.88 |
35.44 |
Nebraska |
38.06 |
40.28 |
38.59 |
Nevada |
45.96 |
45.61 |
46.30 |
New Hampshire |
39.55 |
39.86 |
33.19 |
New Jersey |
39.48 |
40.38 |
41.71 |
New Mexico |
44.76 |
45.23 |
49.14 |
New York |
37.85 |
36.90 |
35.66 |
North Carolina |
45.37 |
49.50 |
52.61 |
North Dakota |
37.13 |
35.77 |
43.88 |
Ohio |
45.10 |
47.71 |
51.26 |
Oklahoma |
42.67 |
42.11 |
46.09 |
Oregon |
35.41 |
37.54 |
42.22 |
Pennsylvania |
41.14 |
42.11 |
42.51 |
Rhode Island |
44.39 |
41.03 |
37.38 |
South Carolina |
40.98 |
45.33 |
46.13 |
South Dakota |
38.66 |
41.39 |
40.69 |
Tennessee |
45.91 |
50.22 |
51.90 |
Texas |
38.41 |
40.37 |
40.34 |
Utah |
48.40 |
48.22 |
51.71 |
Vermont |
38.19 |
36.71 |
NA |
Virginia |
43.73 |
48.21 |
53.07 |
Washington |
34.21 |
35.93 |
35.03 |
West Virginia |
44.15 |
49.75 |
45.72 |
Wisconsin |
42.30 |
41.12 |
46.23 |
Wyoming |
44.79 |
46.39 |
45.72 |
# Move No Drought column to first column
df16 <- df7[, c(1,8:10)]
df17 <- df16[, c(1, 3, 2, 4)]
# Move the Overall row to the first row
ovr <- df17[df17$State.Name == "Overall", ]
df18 <- rbind(ovr, df17[df17$State.Name != "Overall", ])
kable(df18, caption = "Percentage Monitor", align = c("l", "c", "c", "c"))
Percentage Monitor
Overall |
68.12 |
22.60 |
9.28 |
Alabama |
71.87 |
18.51 |
9.62 |
Arizona |
21.69 |
50.40 |
27.91 |
Arkansas |
73.24 |
21.86 |
4.90 |
California |
45.71 |
34.56 |
19.73 |
Colorado |
62.58 |
28.10 |
9.32 |
Connecticut |
85.48 |
13.38 |
1.14 |
Delaware |
87.17 |
11.01 |
1.82 |
Florida |
75.06 |
18.83 |
6.11 |
Georgia |
59.08 |
26.16 |
14.75 |
Idaho |
43.49 |
44.46 |
12.05 |
Illinois |
85.67 |
12.27 |
2.07 |
Indiana |
91.14 |
7.72 |
1.14 |
Iowa |
84.38 |
13.55 |
2.07 |
Kansas |
70.45 |
21.96 |
7.59 |
Kentucky |
89.04 |
9.34 |
1.61 |
Louisiana |
77.83 |
16.44 |
5.72 |
Maine |
87.97 |
11.62 |
0.41 |
Maryland |
86.89 |
11.63 |
1.48 |
Massachusetts |
86.97 |
10.88 |
2.14 |
Michigan |
91.63 |
8.34 |
0.03 |
Minnesota |
77.96 |
20.16 |
1.89 |
Mississippi |
79.34 |
16.17 |
4.49 |
Missouri |
80.16 |
17.26 |
2.58 |
Montana |
67.75 |
26.42 |
5.83 |
Nebraska |
76.03 |
18.55 |
5.42 |
Nevada |
36.07 |
36.77 |
27.16 |
New Hampshire |
87.69 |
10.94 |
1.37 |
New Jersey |
87.28 |
11.80 |
0.92 |
New Mexico |
42.87 |
37.48 |
19.66 |
New York |
91.04 |
8.47 |
0.49 |
North Carolina |
73.55 |
18.90 |
7.55 |
North Dakota |
71.08 |
26.47 |
2.45 |
Ohio |
91.10 |
8.57 |
0.33 |
Oklahoma |
64.79 |
25.22 |
9.98 |
Oregon |
70.48 |
25.55 |
3.97 |
Pennsylvania |
92.82 |
6.89 |
0.29 |
Rhode Island |
89.51 |
10.25 |
0.24 |
South Carolina |
60.77 |
27.19 |
12.04 |
South Dakota |
65.33 |
24.27 |
10.40 |
Tennessee |
77.92 |
17.14 |
4.94 |
Texas |
62.15 |
26.75 |
11.09 |
Utah |
40.87 |
46.67 |
12.46 |
Vermont |
90.23 |
9.77 |
NA |
Virginia |
85.32 |
13.37 |
1.31 |
Washington |
79.45 |
19.12 |
1.43 |
West Virginia |
95.43 |
4.33 |
0.24 |
Wisconsin |
86.17 |
13.04 |
0.80 |
Wyoming |
59.03 |
28.29 |
12.68 |
# Move No Drought column to first column
df18 <- df7[, c(1,11:13)]
df19 <- df18[, c(1, 3, 2, 4)]
# Move the Overall row to the first row
ovr <- df19[df19$State.Name == "Overall", ]
df20 <- rbind(ovr, df19[df19$State.Name != "Overall", ])
kable(df20, caption = "Standard Deviation", align = c("l", "c", "c", "c"))
Standard Deviation
Overall |
14.21 |
15.06 |
15.02 |
Alabama |
13.27 |
13.64 |
15.36 |
Arizona |
12.61 |
11.89 |
12.07 |
Arkansas |
12.88 |
14.71 |
13.38 |
California |
16.56 |
17.12 |
15.51 |
Colorado |
12.91 |
12.80 |
13.41 |
Connecticut |
15.03 |
15.79 |
12.86 |
Delaware |
15.00 |
17.78 |
19.08 |
Florida |
11.79 |
12.60 |
13.85 |
Georgia |
13.74 |
14.84 |
16.44 |
Idaho |
10.80 |
11.44 |
11.38 |
Illinois |
14.47 |
15.66 |
19.09 |
Indiana |
13.63 |
15.87 |
13.10 |
Iowa |
11.61 |
12.94 |
14.07 |
Kansas |
13.59 |
14.28 |
14.08 |
Kentucky |
13.06 |
15.87 |
16.24 |
Louisiana |
13.57 |
14.00 |
17.70 |
Maine |
11.57 |
12.41 |
7.48 |
Maryland |
15.35 |
17.45 |
22.14 |
Massachusetts |
13.49 |
12.96 |
8.77 |
Michigan |
13.92 |
15.54 |
14.21 |
Minnesota |
11.60 |
11.63 |
10.36 |
Mississippi |
12.91 |
13.83 |
16.42 |
Missouri |
13.32 |
14.50 |
15.50 |
Montana |
9.57 |
10.05 |
11.98 |
Nebraska |
11.63 |
12.52 |
12.89 |
Nevada |
13.79 |
13.47 |
14.22 |
New Hampshire |
12.19 |
12.49 |
8.72 |
New Jersey |
15.82 |
19.16 |
11.79 |
New Mexico |
11.19 |
11.75 |
12.11 |
New York |
13.83 |
15.21 |
10.78 |
North Carolina |
13.40 |
14.50 |
17.76 |
North Dakota |
9.98 |
9.81 |
9.64 |
Ohio |
14.47 |
16.56 |
18.54 |
Oklahoma |
13.22 |
14.04 |
14.26 |
Oregon |
12.24 |
12.24 |
11.52 |
Pennsylvania |
14.93 |
17.43 |
19.03 |
Rhode Island |
13.55 |
14.41 |
9.63 |
South Carolina |
13.01 |
14.16 |
15.76 |
South Dakota |
10.50 |
11.35 |
11.00 |
Tennessee |
13.67 |
15.40 |
15.23 |
Texas |
14.96 |
14.83 |
14.50 |
Utah |
12.87 |
12.81 |
12.26 |
Vermont |
10.84 |
10.39 |
NA |
Virginia |
14.07 |
15.53 |
18.18 |
Washington |
11.95 |
12.57 |
11.79 |
West Virginia |
13.50 |
16.88 |
12.94 |
Wisconsin |
12.97 |
14.03 |
16.42 |
Wyoming |
8.51 |
9.20 |
9.13 |