Data example below: each person has multiple rows, for various levels of the viral strain and visit. i wanted to reshape the Visit variable from long to wide but stata brings up the error:
variable Visit not found
i used this code:
Im not sure how to debug this-am i specifying the reshape command incorrectly? should i try doing this an alternative way instead of using reshape? something like
variable Visit not found
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float person byte strain_type double Visit float highrisk str12 infection float firstinfdate 1 6 1 0 "No infection" . 1 6 2 0 "No infection" . 1 6 4 0 "No infection" . 1 11 1 0 "No infection" . 1 11 2 0 "No infection" . 1 11 4 0 "No infection" . 1 16 1 1 "No infection" . 1 16 2 1 "No infection" . 1 16 4 1 "No infection" . 1 18 1 1 "No infection" . 1 18 2 1 "No infection" . 1 18 4 1 "No infection" . 1 31 1 1 "No infection" . 1 31 2 1 "No infection" . 1 31 4 1 "No infection" . 1 33 1 1 "No infection" . 1 33 2 1 "No infection" . 1 33 4 1 "No infection" . 1 34 1 0 "No infection" . 1 34 2 0 "No infection" . 1 34 4 0 "No infection" . 1 35 1 1 "No infection" . 1 35 2 1 "No infection" . 1 35 4 1 "No infection" . 1 39 1 1 "No infection" . 1 39 2 1 "No infection" . 1 39 4 1 "No infection" . 1 40 1 0 "No infection" . 1 40 2 0 "No infection" . 1 40 4 0 "No infection" . 1 42 1 0 "No infection" . 1 42 2 0 "No infection" . 1 42 4 0 "No infection" . 1 43 1 0 "No infection" . 1 43 2 0 "No infection" . 1 43 4 0 "No infection" . 1 44 1 0 "No infection" . 1 44 2 0 "No infection" . 1 44 4 0 "No infection" . 1 45 1 1 "No infection" . 1 45 2 1 "No infection" . 1 45 4 1 "No infection" . 1 51 1 1 "No infection" . 1 51 2 1 "No infection" . 1 51 4 1 "No infection" . 1 52 1 1 "No infection" . 1 52 2 1 "No infection" . 1 52 4 1 "No infection" . 1 53 1 0 "No infection" . 1 53 2 0 "No infection" . 1 53 4 0 "No infection" . 1 54 1 0 "No infection" . 1 54 2 0 "No infection" . 1 54 4 0 "No infection" . 1 56 1 1 "No infection" . 1 56 2 1 "No infection" . 1 56 4 1 "No infection" . 1 58 1 1 "No infection" . 1 58 2 1 "No infection" . 1 58 4 1 "No infection" . 1 59 1 1 "No infection" . 1 59 2 1 "No infection" . 1 59 4 1 "No infection" . 1 66 1 1 "No infection" . 1 66 2 1 "No infection" . 1 66 4 1 "No infection" . 1 68 1 0 "No infection" . 1 68 2 0 "No infection" . 1 68 4 0 "No infection" . 1 70 1 0 "No infection" . 1 70 2 0 "No infection" . 1 70 4 0 "No infection" . 1 74 1 0 "No infection" . 1 74 2 0 "No infection" . 1 74 4 0 "No infection" . 2 6 1 0 "No infection" . 2 11 1 0 "No infection" . 2 16 1 1 "No infection" . 2 18 1 1 "No infection" . 2 31 1 1 "No infection" . 2 33 1 1 "No infection" . 2 34 1 0 "No infection" . 2 35 1 1 "No infection" . 2 39 1 1 "No infection" . 2 40 1 0 "No infection" . 2 42 1 0 "No infection" . 2 43 1 0 "No infection" . 2 44 1 0 "No infection" . 2 45 1 1 "No infection" . 2 51 1 1 "No infection" . 2 52 1 1 "No infection" . 2 53 1 0 "No infection" . 2 54 1 0 "No infection" . 2 56 1 1 "No infection" . 2 58 1 1 "No infection" . 2 59 1 1 "No infection" . 2 66 1 1 "No infection" . 2 68 1 0 "No infection" . 2 70 1 0 "No infection" . 2 74 1 0 "No infection" . end format %td firstinfdate label values highrisk highrisk_ label def highrisk_ 0 "Not High-risk", modify label def highrisk_ 1 "High-Risk", modify
i used this code:
Code:
reshape wide Visit , i(ID strain_type) j(Visit)
Code:
gen Visit1=. gen Visit2=. gen Visit3=. gen Visit4=. gen Visit5=. foreach x of numlist 1/5 { replace Visit`x'=1 if Visit==`x'; }
Comment