I have dozens of different stubs each with four different suffix denoting the round of the survey my variables are from. Kindly examine this example of my data:
You can see that in this specific example, suffixes are _r1 and _r2 and that the stubs are COVa20m and COVb3a. When running the code:
I get the following output:
variable COVa20m_r1 not found
Which is quite puzzling given that i am perfectly able to look for this variable in my list. I can even use tab COVa20m_r1.
What did I do wrong?
Thank you for your help
Julia
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id byte(COVa20m_r1 COVa20m_r2 COVb3a_r1 COVb3a_r2) 652001 6 . 100 . 652341 . . . . 652240 6 . 100 . 652037 6 . 100 . 652243 . . . . 652320 6 . 100 . 652204 6 . 100 . 652157 6 . 100 . 652163 6 . 100 . 652351 6 . 100 . end label values COVa20m_r1 COVA20M label values COVa20m_r2 COVA20M label def COVA20M 6 "June", modify label values COVb3a_r1 COVB3A label values COVb3a_r2 COVB3A
Code:
forvalues x = 1/4 {
unab vars_r`x': *_r`x'
local stubs_r`x': subinstr local vars_r`x' "_r`x'" "", all
}
reshape long `stubs_r1' `stubs_r2' `stubs_r3' `stubs_r4', i(id) j(round_number _r1 _r2 _r3 _r4) s
variable COVa20m_r1 not found
Which is quite puzzling given that i am perfectly able to look for this variable in my list. I can even use tab COVa20m_r1.
What did I do wrong?
Thank you for your help
Julia

Comment