Hi all,
I have a wide dataset where most of the variables are at household level and the different columns represent the individuals. So, I need to reshape from wide to long.
All variables have the same pattern like: p6_1_1, where the last number is the one needed for the reshape.
However, I'm struggling on how managing the variables name to reshape the dataset as using
of course doesn't work.
Is there a way to have something like
where the `item' corresponds to the first part of the variable name p6_1_?
Thanks for your support!
I have a wide dataset where most of the variables are at household level and the different columns represent the individuals. So, I need to reshape from wide to long.
All variables have the same pattern like: p6_1_1, where the last number is the one needed for the reshape.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(p6_3_1 p6_3_2 p6_3_3 p6_3_4 p6_3_5 p6_3_6 p6_3_7 p6_3_8 p6_3_9 p6_4_1 p6_4_2 p6_4_3 p6_4_4 p6_4_5 p6_4_6 p6_4_7 p6_4_8 p6_4_9) 5 . . . . . . . . 11 . . . . . . . . 3 1 . . . . . . . 8 3 . . . . . . . 5 5 . . . . . . . 6 6 . . . . . . . 5 4 5 . . . . . . 7 3 6 . . . . . . 4 2 4 . . . . . . 3 14 9 . . . . . . end
However, I'm struggling on how managing the variables name to reshape the dataset as using
Code:
reshape long p*_@, i(h_number) j(ind_number)
Is there a way to have something like
Code:
reshape long `item'_@, i(h_number) j(ind_number)
Thanks for your support!
Comment