I am stuck at this point. I would like to transform input data (long format) to wide format (output needed).
I tried to find a unique identifier within a patient's id using _n or _N. It does not work. I do know what I am missing here.
Any help in this regards highly appreciated.
Thank you
Code:
****Input data**** clear input id str5 medicine 1 "med1" 1 "med2" 1 "med5" 1 "med6" 1 "med8" 2 "med1" 2 "med1" 2 "med3" 2 "med4" 2 "med10" end list
Code:
*****Output needed**** clear input id med1 med2 med3 med4 med5 med6 med8 med10 1 1 1 0 0 1 1 1 0 2 2 0 1 1 0 0 0 1 end list
I tried to find a unique identifier within a patient's id using _n or _N. It does not work. I do know what I am missing here.
Code:
bysort id medicine: gen subindex=_n bysort id medicine: gen submax=_N
Thank you
Comment