Hi stata user,
I have facing some problem while using reshape wide command, here is my data
. dataex
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
there is a duplicity in ID, I want unique id, so I tried reshape command which are as
now, variables converted into 6 to 9,
now there are 2 variable for one thing.
If I do this, output looks like:
please suggest what to do to convert into single variable without duplicity of ID.
I have facing some problem while using reshape wide command, here is my data
. dataex
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte id str3(elligible diabetic) str2 cholestrol str3 stroke 1 "Yes" "No" "No" "Yes" 2 "Yes" "Yes" "No" "No" 3 "No" "Yes" "Yes" "No" 4 "No" "No" "No" "No" 4 "Yes" "Yes" "No" "No" 5 "Yes" "No" "No" "No" 6 "Yes" "Yes" "Yes" "Yes" 7 "Yes" "No" "No" "Yes" 5 "Yes" "Yes" "No" "Yes" end
there is a duplicity in ID, I want unique id, so I tried reshape command which are as
Code:
bysort id:gen ab=_n . . replace ab=0 if ab==. (0 real changes made) . reshape wide elligible diabetic cholestrol stroke, i(id) j(ab) (note: j = 1 2) Data long -> wide ----------------------------------------------------------------------------- Number of obs. 9 -> 7 Number of variables 6 -> 9 j variable (2 values) ab -> (dropped) xij variables: elligible -> elligible1 elligible2 diabetic -> diabetic1 diabetic2 cholestrol -> cholestrol1 cholestrol2 stroke -> stroke1 stroke2 ----------------------------------------------------------------------------- end
now there are 2 variable for one thing.
If I do this, output looks like:
Code:
gen elligible = elligible1+ elligible2 . tab elligible elligible | Freq. Percent ------------+----------------------------------- No | 2 22.22 Yes | 5 55.55 YesYes | 2 22.22 ------------+----------------------------------- Total | 9 100.00 end
Comment