search for: first_year_at_1

Displaying 3 results from an estimated 3 matches for "first_year_at_1".

2018 May 28
3
How to generate a conditional dummy in R?
...X=1 that first specific year, it should only count once (X=1), not twice. The code that I have now is not complete and I would appreciate some advice here. This is the code: dat2 <- dat1 %>% group_by(country) %>% group_by(grp = cumsum(is.na(lag(Y))), add = TRUE) %>% mutate(first_year_at_1 = match(1, Y) * any(is.na(Y)) * any(tail(Y, 3) == 1L), X = {x <- integer(length(Y)) ; x[first_year_at_1] <- 1L ; x}) %>% ungroup() It doesn?t really generate what I described above. Any help here would be much appreciated. Below you can see my sample data with the desired o...
2018 May 29
0
How to generate a conditional dummy in R?
...c year, it should only count once (X=1), not twice. > > The code that I have now is not complete and I would appreciate some advice here. This is the code: > dat2 <- dat1 %>% > group_by(country) %>% > group_by(grp = cumsum(is.na(lag(Y))), add = TRUE) %>% > mutate(first_year_at_1 = match(1, Y) * any(is.na(Y)) * any(tail(Y, 3) == 1L), > X = {x <- integer(length(Y)) ; x[first_year_at_1] <- 1L ; x}) %>% > ungroup() > > It doesn?t really generate what I described above. Any help here would be much appreciated. > > Below you can see my sampl...
2018 May 29
1
How to generate a conditional dummy in R?
...count once (X=1), not twice. >> >> The code that I have now is not complete and I would appreciate some advice here. This is the code: >> dat2 <- dat1 %>% >> group_by(country) %>% >> group_by(grp = cumsum(is.na(lag(Y))), add = TRUE) %>% >> mutate(first_year_at_1 = match(1, Y) * any(is.na(Y)) * any(tail(Y, 3) == 1L), >> X = {x <- integer(length(Y)) ; x[first_year_at_1] <- 1L ; x}) %>% >> ungroup() >> >> It doesn?t really generate what I described above. Any help here would be much appreciated. >> >> Be...