Dear Statalist community,
This might be a simple question, but I am having trouble reshaping my dataset from wide to long.
Essentially, I was wondering, when I have 6000 variables that occur across three wave periods and follow a consistent naming pattern like "Aw1", "Aw2", "Aw3", "Bw1", "Bw2", "Bw3", and so on, is there any easy way to reshape the data to long without typing all the stub names?
I have used the explanation previously provided here (https://www.stata.com/support/faqs/d...-with-reshape/) to create an initial code, but I have been getting a syntax error.
Code that I have been using:
Here is an example dataset as needed:
This might be a simple question, but I am having trouble reshaping my dataset from wide to long.
Essentially, I was wondering, when I have 6000 variables that occur across three wave periods and follow a consistent naming pattern like "Aw1", "Aw2", "Aw3", "Bw1", "Bw2", "Bw3", and so on, is there any easy way to reshape the data to long without typing all the stub names?
I have used the explanation previously provided here (https://www.stata.com/support/faqs/d...-with-reshape/) to create an initial code, but I have been getting a syntax error.
Code that I have been using:
Error message I got for using the code:Code:unab vars : *w1 *w2 *w3 local stubs1 : subinstr local vars "w1" "", all local stubs2 : subinstr local vars "w2" "", all local stubs3 : subinstr local vars "w3" "", all reshape long `stubs1' `stubs2' `stubs3', i(id_key) j(wave) string
invalid syntaxAny insight would be greatly appreciated!
r(198);
Here is an example dataset as needed:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(ID Aw1 Aw2 Aw3 Bw1 Bw2 Bw3 Cw1 Cw2 Cw3) 1 50 50 50 50 50 50 50 50 50 2 60 60 60 60 60 60 60 60 60 3 70 70 70 70 70 70 70 70 70 4 80 80 80 80 80 80 80 80 80 5 90 90 90 90 90 90 90 90 90 end
Comment