Skip to content

Commit bc6f66c

Browse files
author
Carly Lovas
committed
categorical predictors
1 parent c8fc7f7 commit bc6f66c

1 file changed

Lines changed: 23 additions & 32 deletions

File tree

R/maine/lobster_did.R

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
## Lobster DiD ####
22
###################
33

4-
54
# Install & load the libraries ----
65
library(tidyverse)
76
library(tidygraph)
@@ -23,24 +22,26 @@ portfolio |>
2322
shrimpers |>
2423
filter(lc1 == 1 | lc2 == 1 | lc3 == 1 | lco == 1 | lc2o == 1 | lc3o == 1) -> shrimp_w_lobster
2524

26-
portfolio |>
27-
filter(landings_number %in% shrimp_w_lobster$landings_number) |>
28-
select(license_year, landings_number, csc, css, lc1, lco, lc2, lc2o, lc3, lc3o) |>
29-
arrange(landings_number, license_year) |>
30-
filter(license_year >= 2009 & !license_year == 2015) -> cs_portfolio
31-
25+
# All commercial lobster harvesters ----
3226
portfolio |>
3327
filter(lc1 == 1 | lc2 == 1 | lc3 == 1 | lco == 1 | lc2o == 1 | lc3o == 1) |>
34-
select(license_year, landings_number, lc1, lco, lc2, lc2o, lc3, lc3o) |> ## we need to compare lobster class changes across all harvesters t
28+
select(license_year, landings_number, lc1, lco, lc2, lc2o, lc3, lc3o) |>
3529
pivot_longer(lc1:lc3o, names_to = "lobster_class", values_to = "count") |>
3630
filter(!count == 0) |>
3731
mutate(class = case_when(
3832
lobster_class %in% c("lco", "lc1") ~ 1,
39-
lobster_class %in% c("lc2", "lc2o") ~ 2,
33+
lobster_class %in% c("lc2", "lc2o") ~ 2,
4034
lobster_class %in% c("lc3", "lc3o") ~ 3
41-
)) |>
35+
)) |>
36+
37+
## Ensure population of lobsterers had license in the year before and after the closure
4238
filter(license_year %in% c(2014,2016)) |>
43-
group_by(landings_number, lobster_class, class) |>
39+
40+
## Remove instances of mulitple license types issued in a year...
41+
mutate(n = n(), .by = c(landings_number, license_year)) |>
42+
filter(!n > 1L) |>
43+
select(!n) |>
44+
group_by(landings_number) |>
4445
summarise(years = n_distinct(license_year)) |>
4546
filter(years == 2) -> lobsterers
4647

@@ -54,24 +55,10 @@ portfolio |>
5455
lobster_class %in% c("lc2", "lc2o") ~ 2,
5556
lobster_class %in% c("lc3", "lc3o") ~ 3
5657
)) |>
57-
filter(license_year %in% c(2014,2016)) |>
58+
select(landings_number, license_year, class) |>
59+
filter(license_year %in% c(2014,2016)) |>
5860
pivot_wider(names_from = license_year, values_from = class) |>
59-
mutate(switch = ifelse(`2014` < `2016`, 1, 0)) -> switch # come back to the NAs later, may represent exit
60-
61-
# portfolio |>
62-
# select(license_year, landings_number, csc, css, lc1, lco, lc2, lc2o, lc3, lc3o) |>
63-
# filter(license_year >= 2009 & !license_year == 2015) |>
64-
# left_join(switch |> select(landings_number, switch)) |>
65-
# drop_na() |>
66-
# mutate(shrimp_w_lobster = ifelse(landings_number %in% shrimp_w_lobster$landings_number, 1, 0),
67-
# closure = ifelse(license_year >= 2016, 1, 0),
68-
# did = shrimp_w_lobster*closure) |>
69-
# select(license_year, landings_number, switch, shrimp_w_lobster, closure, did) -> lob_did
70-
71-
# lm(shrimp_w_lobster+closure+did, data = lob_did)
72-
73-
### Yeaaaaaah I don't think DiD is the right test here...
74-
61+
mutate(switch = ifelse(`2014` < `2016`, 1, 0)) -> switch
7562

7663
portfolio |>
7764
select(license_year, landings_number, lc1, lco, lc2, lc2o, lc3, lc3o) |>
@@ -88,10 +75,14 @@ portfolio |>
8875
closure = ifelse(license_year >= 2016, 1, 0),
8976
did = shrimp_w_lobster*closure) -> lob_did
9077

91-
lm(class ~ shrimp_w_lobster+closure+did, data = lob_did)
9278

93-
summary(lm(license_year ~ class+shrimp_w_lobster+closure+did, data = lob_did))
79+
# Categorical dependent variable ----
80+
## Did the lobster class type switch after the closure of the shrimp fishery?
81+
summary(MASS::polr(factor(class) ~ shrimp_w_lobster+closure+did, data = lob_did))
82+
83+
84+
# Category 1 --> 2 ----
85+
86+
9487

95-
## Better but still not right...
96-
## Maybe the regression should be proportion of license classes ~ shrimp-lobster coholders and license switch...?
9788

0 commit comments

Comments
 (0)