I have an issue with a database that I need to reshape from long to wide. The command line
Code:
reshape wide v, i(idvar) j(tvar)
In my example, my id string variable has 2 individuals (A and B). Individual A responded to 3 queries in Round1 (1, 2 and 3) and 3 queries in Round2 (1, 2 and 3) so that each individual appears in a long format of 9 rows. ResRound1 and ResRound2 are binary variables collecting responses (Yes/No) to respectively Round1 and Round2.
Code:
input str1 id Round1 Round2 ResRound1 ResRound2 "A" 1 1 0 0 "A" 1 2 0 1 "A" 1 3 0 1 "A" 2 1 1 0 "A" 2 2 1 1 "A" 2 3 1 1 "A" 3 1 1 0 "A" 3 2 1 1 "A" 3 3 1 1 "B" 1 1 0 1 "B" 1 2 0 1 "B" 1 3 0 0 "B" 2 1 1 1 "B" 2 2 1 1 "B" 2 3 1 0 "B" 3 1 0 1 "B" 3 2 0 1 "B" 3 3 0 0 end
I am looking to obtain one observation per individual, that is a wide format of only 2 rows, where Round1 and Round2 are dropped and their modality (1, 2 and 3) appear at the end of the variable ResRound1 and ResRound2 name. See below:
Code:
input str1 id ResRound11 ResRound12 ResRound13 ResRound21 ResRound22 ResRound23 A 0 1 1 0 1 1 B 0 1 0 1 1 0 end
Code:
reshape wide ResRound1 ResRound2, i(id Round1) j(Round2)
Best, TR
0 Response to Reshape long to wide for several variables
Post a Comment