Hi,
I am trying to reshape my data to wide, but then I reshape the order is messed up so tube"j" contains differnet tubes since there is lacking data for some ids (only 3 different tubes for some).
Is there a way to create new observations containing id and tube, but missing data in Assay to help the order?
Thank you for your inputs!
/Anne
Current output:

Desired output:

clear
input str2 id str4 tube str3 Assay
"1" zym Il2
"1" zym Il4
"1" zym IL6
"1" lps Il2
"1" lps Il4
"1" lps IL6
"2" null Il2
"2" null Il4
"2" null IL6
"2" zym Il2
"2" zym Il4
"2" zym IL6
"2" lps Il2
"2" lps Il4
"2" lps IL6
"2" null Il2
"2" null Il4
"2" null IL6
"2" cd3 Il2
"2" cd3 Il4
"2" cd3 IL6
"3" zym Il2
"3" zym Il4
"3" zym IL6
"3" lps Il2
"3" lps Il4
"3" lps IL6
"3" cd3 Il2
"3" cd3 Il4
"3" cd3 IL6
end
bysort id (tube): gen j=_n
reshape wide tube Assay, i(id) j(j)
I am trying to reshape my data to wide, but then I reshape the order is messed up so tube"j" contains differnet tubes since there is lacking data for some ids (only 3 different tubes for some).
Is there a way to create new observations containing id and tube, but missing data in Assay to help the order?
Thank you for your inputs!
/Anne
Current output:
Desired output:
clear
input str2 id str4 tube str3 Assay
"1" zym Il2
"1" zym Il4
"1" zym IL6
"1" lps Il2
"1" lps Il4
"1" lps IL6
"2" null Il2
"2" null Il4
"2" null IL6
"2" zym Il2
"2" zym Il4
"2" zym IL6
"2" lps Il2
"2" lps Il4
"2" lps IL6
"2" null Il2
"2" null Il4
"2" null IL6
"2" cd3 Il2
"2" cd3 Il4
"2" cd3 IL6
"3" zym Il2
"3" zym Il4
"3" zym IL6
"3" lps Il2
"3" lps Il4
"3" lps IL6
"3" cd3 Il2
"3" cd3 Il4
"3" cd3 IL6
end
bysort id (tube): gen j=_n
reshape wide tube Assay, i(id) j(j)
Comment