PID jbstat1 jbsemp1 jbstat2 jbsemp2 jbstat3 jbsemp3 1 2 3 4 5 6 7and we would like to have
PID wave jbstat jbsemp 1 1 2 3 1 2 4 5 1 3 6 7
. reshape long jbstat jbsemp, i(pid) j(wave)will move from the first to the second from almost instantaneously, while
. reshape wide jbstat jbsemp, i(pid) j(wave)will do the reverse.
vector jb=jbstat1 to jbstat3 /js=jbsemp1 to jbsemp3. loop #i = 1 to 3. . compute jbstat=jb(#i). . compute jbsemp=js(#i). . compute wave = #i. . xsave out = "longform.sav" /keep=pid, wave, jbstat, jbsemp. end loop.
varstocases /id=pid /index=wave /make jbstat from jbstat1 to jbstat3 /make jbsemp from jbsemp1 to jbsemp3.
get file "longform.sav". vector jbstat(3) /jbsemp(3). compute jbstat(wave)=jbstat. compute jbsemp(wave)=jbsemp. agg out = */break = pid /jbstat1 to jbsemp3 = first(jbstat1 to jbsemp3).
casestovars /id=pid /index=wave.
vector month(1200). loop #i=start to end. . compute month(#i)=state. end loop.
vector dur(5). compute dur(state) = duration. agg out = * /break = pid /dur1 to dur5 = sum(dur1 to dur5).
|