Hi, I have a dataset with multiple variables entered in the long format. I would like to reshape to wide format. I am using the code below but getting an error that "values of variable grade not unique within id, error code r9". Can you help me solve the issue? My data example is attached with the code.
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
----------------------- copy starting from the next line -----------------------
Code:
reshape wide Class Type classification gradeType, i(id) j(grade)
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int id str3 Type str6 Class str2(grade gradeType) str1 classification 1001 "In" "Day" "1" "XM" "0" 1001 "In" "Day" "1" "XM" "0" 1001 "In" "Midday" "1" "XM" "0" 1001 "In" "Midday" "1" "XM" "1" 1001 "In" "Midday" "1" "XM" "0" 1001 "In" "Midday" "1" "XM" "0" 1001 "In" "Night" "1" "XM" "0" 1001 "In" "Night" "1" "XM" "0" 1001 "In" "Night" "1" "XM" "0" 1001 "In" "Night" "1" "XM" "1" 1001 "In" "Night" "1" "XM" "0" 1001 "In" "Mixed" "1" "XM" "0" 1001 "In" "Mixed" "1" "XM" "1" 1001 "In" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "1" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "1" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "1" "XM" "0" 1001 "Out" "Mixed" "2" "YR" "1" 1001 "Out" "Mixed" "3" "YR" "1" 1001 "Out" "Mixed" "4" "YR" "1" 1001 "Out" "Mixed" "5" "YR" "1" 1001 "Out" "Mixed" "6" "YR" "1" 1001 "Out" "Mixed" "7" "YR" "1" 1001 "Out" "Mixed" "8" "YR" "1" 1001 "Out" "Mixed" "9" "YR" "1" 1001 "Out" "Mixed" "10" "YR" "1" 202 "In" "Day" "1" "XM" "0" 202 "In" "Day" "1" "XM" "1" 202 "In" "Midday" "1" "XM" "0" 202 "In" "Midday" "1" "XM" "0" 202 "In" "Midday" "1" "XM" "0" 202 "In" "Midday" "1" "XM" "0" 202 "In" "Night" "1" "XM" "0" 202 "In" "Night" "1" "XM" "0" 202 "In" "Night" "1" "XM" "1" 202 "In" "Night" "1" "XM" "0" 202 "In" "Night" "1" "XM" "0" 202 "In" "Mixed" "1" "XM" "0" 202 "In" "Mixed" "1" "XM" "0" 202 "In" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "1" 202 "Out" "Mixed" "1" "XM" "1" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "1" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "1" "XM" "0" 202 "Out" "Mixed" "2" "YR" "1" 202 "Out" "Mixed" "3" "YR" "1" 202 "Out" "Mixed" "4" "YR" "1" 202 "Out" "Mixed" "5" "YR" "1" 202 "Out" "Mixed" "6" "YR" "1" 202 "Out" "Mixed" "7" "YR" "1" 202 "Out" "Mixed" "8" "YR" "1" 202 "Out" "Mixed" "9" "YR" "1" 202 "Out" "Mixed" "10" "YR" "1" 307 "In" "Day" "1" "XM" "0" 307 "In" "Day" "1" "XM" "0" 307 "In" "Midday" "1" "XM" "1" 307 "In" "Midday" "1" "XM" "0" 307 "In" "Midday" "1" "XM" "0" 307 "In" "Midday" "1" "XM" "1" 307 "In" "Night" "1" "XM" "0" 307 "In" "Night" "1" "XM" "0" 307 "In" "Night" "1" "XM" "0" 307 "In" "Night" "1" "XM" "0" 307 "In" "Night" "1" "XM" "0" 307 "In" "Mixed" "1" "XM" "0" 307 "In" "Mixed" "1" "XM" "0" 307 "In" "Mixed" "1" "XM" "1" 307 "In" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "1" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "0" 307 "Out" "Mixed" "1" "XM" "1" 307 "Out" "Mixed" "2" "YR" "1" 307 "Out" "Mixed" "3" "YR" "1" 307 "Out" "Mixed" "4" "YR" "1" 307 "Out" "Mixed" "5" "YR" "1" 307 "Out" "Mixed" "6" "YR" "1" 307 "Out" "Mixed" "7" "YR" "1" 307 "Out" "Mixed" "8" "YR" "1" end
Comment