data %>% group_by(highprice) %>% count(qsmk) %>% mutate( pct = n/sum(n) * 100 ) %>% filter(qsmk == 1, !is.na(highprice))
## # A tibble: 2 × 4## # Groups: highprice [2]## highprice qsmk n pct## <dbl> <fct> <int> <dbl>## 1 0 1 8 19.5## 2 1 1 370 25.8
# an instrument as weak if the F-statistic from the first-stage model is less than 10# two-stage-least-squares regressionlibrary(ivreg)ivreg(wt82_71 ~ qsmk | highprice, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 2.40 19.8 0.121 0.904 -36.5 41.3
# Chapter answer: 2.4 kg (-36.5; 41.3)
data %<>% mutate(highprice2 = if_else(price82 >= 1.6, 1, 0), highprice3 = if_else(price82 >= 1.7, 1, 0), highprice4 = if_else(price82 >= 1.8, 1, 0), highprice5 = if_else(price82 >= 1.9, 1, 0) )
ivreg(wt82_71 ~ qsmk | highprice2, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 41.3 165. 0.250 0.802 -282. 365.
ivreg(wt82_71 ~ qsmk | highprice3, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 -40.9 188. -0.218 0.828 -409. 327.
ivreg(wt82_71 ~ qsmk | highprice4, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 -21.1 28.4 -0.742 0.458 -76.9 34.7
ivreg(wt82_71 ~ qsmk | highprice5, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 -12.8 23.7 -0.541 0.588 -59.2 33.6
ivreg(wt82_71 ~ qsmk + sex + race + age + smokeintensity + smokeyrs + exercise + active + wt71 | highprice5 + sex + race + age + smokeintensity + smokeyrs + exercise + active + wt71, data = data) %>% broom::tidy(., conf.int = T) %>% filter(term == "qsmk1")
## # A tibble: 1 × 7## term estimate std.error statistic p.value conf.low conf.high## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>## 1 qsmk1 -2.38 17.3 -0.138 0.891 -36.2 31.5
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |