Hi, guys, I'm a new stata user, and I got the following raw data, which documents the brand choice for different teams in different neighborhoods as well as the expenditure on environmental education in each neighborhood. In the following illustrative table, the brand column documents brand choice, team column documents team name, loc_id column documents neighborhood id, and loc_edu documents education expenditure:
team1 could choose brand A and B, only brand A, only brand B or none. team 2 could choose brand X and Y, only brand X, only brand Y or none.
I want to reorganize my data in the following way:
In the new table each row corresponds to a loc_id (an observation) and each column corresponds to a variable. team1's choice equals 1 if both A and B are purchased, and equals 2 if only A is purchased, and equals 3 if only B is purchased and equals 0 if none is purchased. team2' choice equals 1 if both X and Y are purchased, equals 2 if only X is purchased, equals 3 if only Y is purchased and equals 0 if none is purchased.
What's the stata codes that could achieve this? Thanks!
brand | team | loc_id | loc_edu |
A | team1 | n1 | 13.1 |
B | team1 | n1 | 13.1 |
A | team1 | n2 | 9.7 |
B | team1 | n2 | 9.7 |
X | team2 | n1 | 13.1 |
Y | team2 | n1 | 13.1 |
X | team2 | n3 | 5 |
B | team1 | n4 | 6.2 |
Y | team2 | n4 | 6.2 |
team1 could choose brand A and B, only brand A, only brand B or none. team 2 could choose brand X and Y, only brand X, only brand Y or none.
I want to reorganize my data in the following way:
loc_id | choice_team1 | choice_team2 | loc_edu |
n1 | 1 | 1 | 13.1 |
n2 | 1 | 0 | 9.7 |
n3 | 0 | 2 | 5 |
n4 | 3 | 3 | 6.2 |
In the new table each row corresponds to a loc_id (an observation) and each column corresponds to a variable. team1's choice equals 1 if both A and B are purchased, and equals 2 if only A is purchased, and equals 3 if only B is purchased and equals 0 if none is purchased. team2' choice equals 1 if both X and Y are purchased, equals 2 if only X is purchased, equals 3 if only Y is purchased and equals 0 if none is purchased.
What's the stata codes that could achieve this? Thanks!
Comment