Hello, I am sorry if the title is unclear.
I have an important number of country-specific datasets organized in wide, but I would like 1) to reshape them from wide to long 2) to append every dataset together, but this is not the subject of this thread.
Each country has a specific number of rounds that can vary from a country to another, which is why I must reshape them individually using a loop and then appending everything instead of reshaping the appended dataset.
Since I have many different stubs to use, I am following the article written by Nicholas J. Cox : https://www.stata.com/support/faqs/d...-with-reshape/
However there is something wrong in my code that doesn't leadme to the expected result. Please have a look at my data:
Let's suppose I would like to have two variables named "COVd2" and "COVb2a" with 3 observations per value of idstd, a unique identifier, each of these observations denoting the rounds _r1 _r2 _r3. I have many other stubs but not all of them start with "COV".
I used the commands
However when using the command -macro list- to check if the globals are correct I get the following outputs:
which is not what I want since these are not stubs I can use to reshape my data. I suspect this has to do with the "?" in my code but I don't know how to fix it in a way that the global stubs_r would have just COVd2 and COVb2a in store.
Does anyone know how I could fix this issue?
Thanks a lot for the help!
I have an important number of country-specific datasets organized in wide, but I would like 1) to reshape them from wide to long 2) to append every dataset together, but this is not the subject of this thread.
Each country has a specific number of rounds that can vary from a country to another, which is why I must reshape them individually using a loop and then appending everything instead of reshaping the appended dataset.
Since I have many different stubs to use, I am following the article written by Nicholas J. Cox : https://www.stata.com/support/faqs/d...-with-reshape/
However there is something wrong in my code that doesn't leadme to the expected result. Please have a look at my data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long idstd int(COVd2_r1 COVd2_r2 COVd2_r3) byte(COVb2a_r1 COVb2a_r2 COVb2a_r3) 674431 . . . . . . 674432 50 50 -9 2 3 -9 674433 6 7 8 3 2 2 674434 0 1 1 3 3 3 674435 7 . 7 3 . 2 674436 1 1 . 3 3 . 674437 . . 1 . . 2 674438 15 12 . 3 3 . 674439 0 1 0 1 1 2 674440 . 9 . . 1 . 674441 . 1 1 . 3 3 674442 123 65 120 3 3 1 674443 240 . . 3 . . 674444 50 20 . 3 3 . 674445 2 2 . 2 3 . 674446 . 11 14 . 2 2 674447 16 17 . 3 3 . 674448 1 . . 3 . . 674449 . 15 . . 3 . 674450 8 6 8 3 3 3 end label values idstd IDSTD label values COVd2_r1 COVD2 label values COVd2_r2 COVD2 label values COVd2_r3 COVD2 label values COVb2a_r1 COVB2A label values COVb2a_r2 COVB2A label values COVb2a_r3 COVB2A
Let's suppose I would like to have two variables named "COVd2" and "COVb2a" with 3 observations per value of idstd, a unique identifier, each of these observations denoting the rounds _r1 _r2 _r3. I have many other stubs but not all of them start with "COV".
I used the commands
Code:
unab vars_r: *_r? global stubs_r: subinstr local vars_r "_r`?'" "", all
Code:
macro list stubs_r: COVd21 COVb2a1 COVd22 COVb2a2
Does anyone know how I could fix this issue?
Thanks a lot for the help!

Comment