-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatarequests_20240917.qmd
248 lines (201 loc) · 8.76 KB
/
datarequests_20240917.qmd
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
---
title: "Data Request: Incentives & Vacant Property"
author: "MVH& AWM"
format:
html:
df-print: paged
---
```{r}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(tidyverse)
ptax_pins <- read_csv("./Output/comm_ind_PINs_2006to2022_timeseries.csv") %>%
#filter(year >= 2011) %>%
mutate(class = as.numeric(class))
# pins that had incentive classes in 2022
incent_pins <- ptax_pins %>%
filter(class >= 600 & class <= 899 & year == 2022)
ptax_pins %>%
filter(pin %in% incent_pins$pin) %>% group_by(year, land_use) %>% summarize(pincount = n()) %>% filter(land_use == "Land") %>%
arrange(year)
# use list of incent pins in 2022 to filter out the same pins in 2011 and group by land use or major class
ptax_pins %>% filter(pin %in% incent_pins$pin & year == 2011) %>% group_by(major_class_code) %>%
summarize(pincount = n())
ptax_pins %>% filter(pin %in% incent_pins$pin & year == 2011) %>% group_by(land_use) %>%
summarize(pincount = n())
# how many were from amazon warehouse in Markham?
ptax_pins %>% filter(pin %in% incent_pins$pin & year == 2011 & clean_name %in% c("Markham", "Harvey")) %>% group_by(land_use) %>%
summarize(pincount = n())
```
```{r}
table(ptax_pins$land_use)
ptax_pins <- ptax_pins %>%
group_by(pin) %>%
mutate(years_existed = n(),
incentive_years = sum(incent_prop == "Incentive"),
landuse_change = ifelse(sum(land_use == "Commercial") == years_existed, "Always Commercial",
ifelse(sum(land_use == "Industrial") == years_existed, "Always Industrial",
ifelse(sum(land_use == "Land") == years_existed, "Always Land",
"Changes Land Use"
))) ) %>%
ungroup() %>%
mutate(incent_change = case_when(
incentive_years == years_existed ~ "Always Incentive",
incentive_years == 0 ~ "Never Incentive",
TRUE ~ "Changes Sometime"))
ptax_pins %>% filter(year == 2022) %>%
group_by(landuse_change, incent_change) %>%
summarize(Pin_Count = n())
```
4,362 PINs began as land (without buildings).
2,721 PINs began as vacant and existed as Land in 2022.
```{r}
ptax_pins %>% filter()
began_vacant <- ptax_pins %>%
group_by(pin) %>%
mutate(years_existed = n(),
began_vacant = ifelse(land_use == "Land", 1, 0),
always_vacant = ifelse(sum(land_use == "Land") == years_existed, 1, 0)) %>%
filter(began_vacant == 1 & year == 2011)
vacant_ever <- ptax_pins %>% filter(land_use == "Land")
# number of years that a pin was vacant
# and then number of pins that were vacant a certain number of years
ptax_pins %>%
filter(pin %in% vacant_ever$pin) %>%
group_by(pin) %>%
summarize(years_vacant = sum(ifelse(land_use == "Land",1,0) )) %>%
arrange(desc(years_vacant)) %>%
ungroup() %>%
group_by(years_vacant) %>%
summarize(pincount = n())
```
```{r}
# pins that started as vacant and changed use
vacant_changed <- ptax_pins %>%
group_by(pin) %>%
filter(pin %in% began_vacant$pin) %>% # keeps PINs that were Land in the first year of the data
mutate(always_vacant = ifelse(sum(land_use == "Land") == years_existed, 1, 0)) %>%
filter(always_vacant == 0 & year == 2022)
vacant_changed %>%
group_by(land_use, incent_prop) %>%
summarize(count =n())
vacant_changed %>%
group_by(major_class_code) %>%
summarize(count =n())
vacant_changed %>%
group_by(incent_prop) %>%
summarize(count =n())
```
## 2011 to 2022
```{r mvh_email_stats}
ptax_pins_mvh <- ptax_pins |>
mutate(land_use = as.factor(land_use),
incent_prop = as.factor(incent_prop)) |>
arrange(year) |>
group_by(pin) |>
mutate(
# lag land use
lag_land = ifelse(lag(land_use) == "Land", 1, 0),
# lag and lead incentive
lead_build = ifelse(land_use == "Land" & lead(land_use) != "Land", 1, 0),
lag_incent = ifelse(lag(incent_prop) == "Incentive", 1, 0), # lagged incent_prop
lag_lag_incent = lag(lag_incent), # two year lagged incent_prop
lag_3_incent = lag(lag_lag_incent) # three year lagged incent_prop
) |>
ungroup() |>
# Change to factors
# land
mutate(lag_land = as.factor(lag_land),
# incents
#
lead_build = as.factor(lead_build),
lag_incent = as.factor(lag_incent),
lag_lag_incent = as.factor(lag_lag_incent),
lag_3_incent = as.factor(lag_3_incent)) |>
# This line checks for flips!
mutate(build_land = ifelse(lag_land == "1" & land_use != "Land", 1, 0),
gain_incent = ifelse(lag_incent == "0" & incent_prop == "Incentive", 1, 0),
lose_incent = ifelse(lag_incent == "1" & incent_prop == "Non-Incentive", 1, 0),
gain_incent_lag = ifelse(lag_lag_incent == "0" & lag_incent == "1", 1, 0), ## Changed this line
lose_incent_lag = ifelse(lag_lag_incent == "1" & lag_incent == "0", 1, 0), ## Changed this line
gain_incent_lag_2 = ifelse(lag_3_incent == "0" & lag_lag_incent == "1" , 1, 0),
) |>
# change to factors
mutate(build_land = as.factor(build_land),
gain_incent = as.factor(gain_incent),
gain_incent_lag = as.factor(gain_incent_lag),
gain_incent_lag_2 = as.factor(gain_incent_lag_2),
) |>
# Condense Variables
mutate(build_incent = ifelse((gain_incent == "1" & build_land == "1"), 1, 0),
build_incent_lag = ifelse(gain_incent_lag == "1" & build_land == "1", 1, 0),
build_incent_lag_2 = ifelse(gain_incent_lag_2 == "1" & lag(land_use) == "Land" & land_use != "Land", 1, 0),
build_incent_lead = ifelse((incent_prop == "1" & land_use == "Land") & lead_build == "1", 1, 0)
) |>
# Change condensed variables to factors
mutate(build_incent = as.factor(build_incent),
build_incent_lag = as.factor(build_incent_lag),
build_incent_lag_2 = as.factor(gain_incent_lag_2),
build_incent_lead = as.factor(build_incent_lead)
)
table(ptax_pins_mvh$build_land)
table(ptax_pins_mvh$lead_build)
table(ptax_pins_mvh$gain_incent_lag)
table(ptax_pins_mvh$build_incent)
table(ptax_pins_mvh$build_incent_lag)
table(ptax_pins_mvh$build_incent_lag_2)
table(ptax_pins_mvh$build_incent_lead)
table(ptax_pins_mvh$lose_incent)
table(ptax_pins_mvh$lose_incent_lag)
```
```{r}
#| label: tbl-mvh_email_stats
#| tbl-cap: MVH's summary table. 2011 to 2022
ptax_pins_mvh_final <- ptax_pins_mvh |>
mutate(year = as.numeric(year)) |>
filter(year > 2012) |>
select(year, build_land, gain_incent, lose_incent, gain_incent_lag, lose_incent_lag, gain_incent_lag_2, build_incent, build_incent_lag, build_incent_lag_2, build_incent_lead) |>
group_by(year) |>
summarize("New Construction w/ Incentive" = sum(build_incent == "1", na.rm = T),
"New Construction w/ Lagged Incentive" = sum(build_incent_lag == "1", na.rm = T),
"New Construction W/ 2 Lagged Incent." = sum(build_incent_lag_2 == "1", na.rm = T),
"Gained Incent. w/ Lead New Construction" = sum(build_incent_lead=="1", na.rm = T),
"New Construction" = sum(build_land == "1", na.rm = T),
"Gained Incentive" = sum(gain_incent == "1", na.rm = T),
"Incentive Ends" = sum(lose_incent == "1", na.rm = T),
"Lagged gained incentive" = sum(gain_incent_lag == "1", na.rm = T),
"Lagged Incentive End" = sum(lose_incent_lag == "1", na.rm = T),
"2 Lagged gained incentive" = sum(gain_incent_lag_2 == "1", na.rm = T),
# "Lead gained incentive" = sum(gain_incent_lead == "1", na.rm = T)
)
ptax_pins_mvh_final %>% flextable::flextable()
```
## More Years of Data
```{r}
simpletable_nolags <- ptax_pins_mvh |>
mutate(year = as.character(year)) |>
select(year, build_land, gain_incent, lose_incent,
# gain_incent_lag, lose_incent_lag, gain_incent_lag_2,
build_incent#, build_incent_lag, build_incent_lag_2, build_incent_lead
) |>
group_by(year) |>
summarize("New Construction w/ Incentive" = sum(build_incent == "1", na.rm = T),
"New Construction" = sum(build_land == "1", na.rm = T),
"Gained Incentive" = sum(gain_incent == "1", na.rm = T),
"Incentive Ends" = sum(lose_incent == "1", na.rm = T)
)
simpletable_nolags %>% flextable::flextable()
```
```{r}
#| label: tbl-allyears
#| tbl-cap: Has all years of data.
ptax_pins_mvh |>
mutate(year = as.character(year)) %>%
select(year, build_land, gain_incent, gain_incent_lag, build_incent, build_incent_lag) |>
group_by(year) |>
summarize("New Construction w/ Incentive" = sum(build_incent == "1", na.rm = T),
"New Construction w/ Lagged Incentive" = sum(build_incent_lag == "1", na.rm = T),
"New Construction" = sum(build_land == "1", na.rm = T),
"Gained Incentive" = sum(gain_incent == "1", na.rm = T),
"Lagged gained incentive" = sum(gain_incent_lag == "1", na.rm = T),
) %>% flextable::flextable()
```