I have an id and variables identifying date and the id's peers. I also have a treatment variable. I would like to create a new variable using gcollapse that would show if a peer has received treatment. I have a solution that loops over days instead of gcollapse but I am frustrated because of the computational intensity.
The new variable would take the id of the first neighbor then tag all observations where the first neighbor was treated on a given day.
I've tried using the merge and replace options in gcollapse but this appears to simply replace neighbor 1 with the id column:
Here is a sample data set
the desired outcome would look like:
The new variable would take the id of the first neighbor then tag all observations where the first neighbor was treated on a given day.
I've tried using the merge and replace options in gcollapse but this appears to simply replace neighbor 1 with the id column:
Code:
gcollapse treated_1 = treated neighbor = id, by(id date) merge replace
Code:
ssc install dataex input long id str10 date long neighbor1 long neighbor2 long treated 1 "01/01/1960" 2 4 0 1 "01/02/1960" 2 4 0 1 "01/03/1960" 2 4 1 2 "01/01/1960" 1 3 0 2 "01/02/1960" 1 3 0 2 "01/03/1960" 1 3 0 3 "01/01/1960" 2 4 1 3 "01/02/1960" 2 4 0 3 "01/03/1960" 2 4 0 4 "01/01/1960" 3 1 0 4 "01/02/1960" 3 1 0 4 "01/03/1960" 3 1 0 end
the desired outcome would look like:
Code:
input long id str10 date long neighbor1 long neighbor2 long treated long neighbor1_treated 1 "01/01/1960" 2 4 0 0 1 "01/02/1960" 2 4 0 0 1 "01/03/1960" 2 4 1 0 2 "01/01/1960" 1 3 0 0 2 "01/02/1960" 1 3 0 0 2 "01/03/1960" 1 3 0 1 3 "01/01/1960" 2 4 1 0 3 "01/02/1960" 2 4 0 0 3 "01/03/1960" 2 4 0 0 4 "01/01/1960" 3 1 0 0 4 "01/02/1960" 3 1 0 0 4 "01/03/1960" 3 1 0 0 end