Assume the following sample dataset:
I would like to get the concatenation seen in var3. The rule is simple: if var2 of the previous observation equals 0, then add the character of var1 before the string and output it concatenated. Or from a different perspective: if var2 is 0, then save the character of var1, and add it before the string in the next line. I've managed to come up with a solution, but to me it seems to be clumsy (therefore not necessarily robust), so I'd much appreciate your thoughts!
| var1 | var2 | var3 |
| A | 1 | A |
| B | 0 | B |
| C | 1 | BC |
| D | 1 | D |
| E | 0 | E |
| F | 0 | EF |
| G | 1 | EFG |

Comment