Dear Statalists,
I have a large number of variables (say, 100) with similar names and I would like to reshape my data long. Is there any how I can use wildcards, so I do not have to list all 100 variables in the reshape command?
Assume, the following is my data:
I can reshape the data set long by typing reshape long v_T1_ v_T2_, i(x) j(y) and reach the following result:
However, since I have a lot of variables it would be more convenient if it was possible to automatize the process. I am thinking of something along the lines reshape long v_??_ v_??_, i(x) j(y). Using wildcards works for me when I reshape wide (in similar situations) but when trying to reshape long (in this case), it doesn't.
How would one use wildcards in such a situation? And if not possible, is there a way around this with a local variable list maybe?
Thank you very much for your input.
Best wishes,
Milan
I have a large number of variables (say, 100) with similar names and I would like to reshape my data long. Is there any how I can use wildcards, so I do not have to list all 100 variables in the reshape command?
Assume, the following is my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(x v_T1_1 v_T1_2 v_T1_3 v_T1_4 v_T2_1 v_T2_2 v_T2_3 v_T2_4) 1 13 10 8 14 15 6 17 18 2 13 7 18 12 14 7 18 18 end
I can reshape the data set long by typing reshape long v_T1_ v_T2_, i(x) j(y) and reach the following result:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float x byte y float(v_T1_ v_T2_) 1 1 13 15 1 2 10 6 1 3 8 17 1 4 14 18 2 1 13 14 2 2 7 7 2 3 18 18 2 4 12 18 end
However, since I have a lot of variables it would be more convenient if it was possible to automatize the process. I am thinking of something along the lines reshape long v_??_ v_??_, i(x) j(y). Using wildcards works for me when I reshape wide (in similar situations) but when trying to reshape long (in this case), it doesn't.
How would one use wildcards in such a situation? And if not possible, is there a way around this with a local variable list maybe?
Thank you very much for your input.
Best wishes,
Milan
Comment