Hello! I am trying to prepare my dataset for a multiple membership multilevel model, and am getting stuck on how to create a series of "multiple membership identifier" variables. Essentially, I have data with individual identifiers (ID) and the states that they lived in from 1996-1999 (state_1996 to state_1999), where 1=Alaska, 2=Arizona, etc. For example (this is made up):
ID state_1996 state_1997 state_1998 state_1999
1 1 1 2 2
2 1 1 1 1
3 3 1 1 1
n 4 4 4 4
And I am trying to create variables s1 through s51 that give the proportion of time each individual spent in each state. For example, based on the previous table and giving just a subset of these new variables, I would like something that looks like this:
ID s1 s2 s3 s4
1 0.5 0.5 0 0
2 1.0 0 0 0
3 0.75 0 0.25 0
n 0 0 0 1.0
Any help on the best way to do this would be much appreciated, thank you!