Hi all
I have many variables which need to be stacked. Each one of these variables has a few associated variables in the same observation which I need to preserve, though multiple of the variables to be stacked are associated with a single set of variables. There's lots of crossover and I'm not sure what to do. In the example below, fooC1 and fooC2 need to be stacked on each other, barC1 and barC2 have to be stacked on each other and fooV and barV, as well as year and city, must be the same for each of the new observations created, to create the result given. I think I should be using reshape, but I'm not sure how to do this with so many variables at once.
Goes to
I have many variables which need to be stacked. Each one of these variables has a few associated variables in the same observation which I need to preserve, though multiple of the variables to be stacked are associated with a single set of variables. There's lots of crossover and I'm not sure what to do. In the example below, fooC1 and fooC2 need to be stacked on each other, barC1 and barC2 have to be stacked on each other and fooV and barV, as well as year and city, must be the same for each of the new observations created, to create the result given. I think I should be using reshape, but I'm not sure how to do this with so many variables at once.
| Year | City | fooV | barV | fooC1 | fooC2 | barC1 | barC2 |
| 1997 | NY | 528 | 629 | Annie | Brian | Carly | Daniel |
| Year | City | C | V |
| 1997 | NY | Annie | 528 |
| 1997 | NY | Brian | 528 |
| 1997 | NY | Carly | 629 |
| 1997 | NY | Daniel | 629 |

Comment