Hi there,
I have data on whether respondents took a particular medication, frequency of consumption (as needed/daily) and duration (less than 1 month, 1-6 months, more than 6 months) for each medication in wide form. The data was only collected once.
How can I change these variables into long form i.e., one variable for medication type, frequency and duration using loops? Thank you in advance.
Whether taking Medication 4,5 and 7 (Yes -1;No-2)
MHA1x3r4
MHA1x3r5
MHA1x3r7
Frequency of consumption of Medication 4,5 and 7 (As needed-1;Daily-5)
MHA1x3X1r4
MHA1x3X1r5
MHA1x3X1r7
Duration of consumption of Medication 4,5, and 7 (Less than 1 month - 1;1-6 months -6;More than 6 months-7)
MHA1x3X2r4
MHA1x3X2r5
MHA1x3X2r7
I have data on whether respondents took a particular medication, frequency of consumption (as needed/daily) and duration (less than 1 month, 1-6 months, more than 6 months) for each medication in wide form. The data was only collected once.
How can I change these variables into long form i.e., one variable for medication type, frequency and duration using loops? Thank you in advance.
Whether taking Medication 4,5 and 7 (Yes -1;No-2)
MHA1x3r4
MHA1x3r5
MHA1x3r7
Frequency of consumption of Medication 4,5 and 7 (As needed-1;Daily-5)
MHA1x3X1r4
MHA1x3X1r5
MHA1x3X1r7
Duration of consumption of Medication 4,5, and 7 (Less than 1 month - 1;1-6 months -6;More than 6 months-7)
MHA1x3X2r4
MHA1x3X2r5
MHA1x3X2r7
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(MHA1x3r4 MHA1x3r5 MHA1x3r7 MHA1x3X1r4 MHA1x3X1r5 MHA1x3X1r7 MHA1x3X2r4 MHA1x3X2r5 MHA1x3X2r7) . . . . . . . . . 2 1 1 . 1 1 . 1 7 2 2 2 . . . . . . 2 2 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1 1 . 5 5 . 7 6 2 1 1 . 1 5 . 6 7 2 1 2 . 5 . . 6 . 2 2 1 . . 1 . . 1 . . . . . . . . . 1 2 1 1 . 1 6 . 7 2 1 1 . 1 1 . 6 6 1 2 1 1 . 5 6 . 7 2 2 2 . . . . . . . . . . . . . . . 2 1 1 . 5 5 . 7 7 . . . . . . . . . 1 1 2 1 1 . 6 1 . 1 1 2 1 5 . 1 7 . 1 2 2 1 . . 6 . . . . . . . . . . . . . . . . . . . . 2 2 1 . . 1 . . 6 1 2 2 5 . . 1 . . 2 2 2 . . . . . . 2 1 1 . 1 1 . 6 6 . . . . . . . . . 2 1 1 . 1 5 . 7 6 . . . . . . . . . 2 2 2 . . . . . . 2 2 2 . . . . . . . . . . . . . . . 2 2 2 . . . . . . . . . . . . . . . 2 2 1 . . 1 . . 7 1 1 2 5 1 . 7 6 . 2 2 2 . . . . . . 2 2 1 . . 1 . . 6 1 1 2 1 1 . 6 1 . 1 2 1 1 . 5 1 . 6 2 1 1 . 1 5 . 6 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 1 1 . 1 7 . 7 2 2 1 . . 5 . . 7 2 2 1 . . 1 . . 1 1 2 1 5 . 5 7 . 7 2 1 2 . 1 . . 1 . 2 1 1 . 1 5 . 1 6 1 1 2 1 1 . 6 7 . 2 1 1 . 1 5 . 6 6 2 1 1 . 1 5 . 6 6 1 2 2 5 . . 7 . . 2 1 2 . 1 . . 1 . 2 2 1 . . 1 . . 6 2 2 2 . . . . . . . . . . . . . . . 2 2 2 . . . . . . . . . . . . . . . . . . . . . . . . 2 2 1 . . 1 . . 7 . . . . . . . . . 2 1 1 . 1 1 . 1 6 2 1 1 . 5 1 . 1 7 2 2 2 . . . . . . 1 2 1 1 . 5 6 . 7 . . . . . . . . . 1 2 2 5 . . 7 . . 1 1 2 1 1 . 1 6 . . . . . . . . . . . . . . . . . . . 1 2 1 5 . 5 6 . 7 2 1 2 . 5 . . 1 . 1 1 1 5 1 5 6 7 7 2 2 2 . . . . . . 1 2 2 1 . . 6 . . 1 1 1 1 5 1 6 6 7 . . . . . . . . . 2 1 2 . 5 . . 1 . 1 1 1 5 1 5 6 7 6 1 1 1 1 5 1 1 6 7 . . . . . . . . . 2 1 1 . 5 1 . 6 7 2 2 2 . . . . . . 1 2 1 1 . 5 1 . 6 2 2 1 . . 1 . . 6 1 1 1 5 1 5 7 6 6 2 2 2 . . . . . . 1 2 2 1 . . 1 . . 1 1 2 1 1 . 6 6 . 2 1 2 . 1 . . 7 . 1 1 1 1 5 1 7 6 6 1 2 1 1 . 1 6 . 6 . . . . . . . . . 1 1 1 1 1 1 1 6 6 end
Comment