Last active
June 18, 2019 19:19
-
-
Save b-rodrigues/50d2fe25b376402ac464c1f60c0a06fa to your computer and use it in GitHub Desktop.
solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r, eval=FALSE, include=FALSE} | |
library(Ecdat) | |
library(dplyr) | |
data("LaborSupply") | |
# Compute the average annual hours worked by year (plus standard deviation) | |
LaborSupply %>% | |
group_by(year) %>% | |
summarise(mean(lnhr), sd(lnhr)) | |
# What age group worked the most hours in the year 1982? | |
LaborSupply %>% | |
filter(year == 1982) %>% | |
group_by(age) %>% | |
mutate(total_lnhr_age = sum(lnhr)) %>% | |
ungroup() %>% | |
filter(total_lnhr_age == max(total_lnhr_age)) | |
# Create a variable, `n_years` that equals the number of years an | |
# individual stays in the panel. Is the panel balanced? | |
LaborSupply %>% | |
group_by(id) %>% | |
mutate(n_years = n()) %>% | |
ungroup() %>% | |
summarise(mean(n_years)) | |
# Which are the individuals that do not have any kids during the whole period? | |
# Create a variable, `no_kids`, that flags these individuals (1 = no kids, 0 = kids) | |
LaborSupply = LaborSupply %>% | |
group_by(id) %>% | |
mutate(n_kids = max(kids)) %>% | |
mutate(no_kids = ifelse(n_kids == 0, 1, 0)) | |
# Using the `no_kids` variable from before compute the average wage in 1980 for these two groups (no kids group vs kids group). | |
LaborSupply %>% | |
filter(year == 1980) %>% | |
group_by(no_kids) %>% | |
summarise(mean(lnwg), sd(lnwg), n()) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment