Hello,
I have a dataset (example below) with information taekn from three different waves (variables that start with "i" are the ones of wave 9, variables that start wiith "ce" are the ones of wave 5 and variables that start with "cg" are the ones related to wave 7). I would like to remove the "i", "ce" and "cg" from the beginning of the variables, rename them "wave 9", "wave 5" and "wave 7", respectively. Then I would like to convert the dataset into a longitudinal data with a column with the information of the waves. For example:
Wave. Var1 Var2 Var3
wave 9
wave 5
wave 7
wave 9
wave 5
wave 7
...
Thank you very mcuh in advance.
I have a dataset (example below) with information taekn from three different waves (variables that start with "i" are the ones of wave 9, variables that start wiith "ce" are the ones of wave 5 and variables that start with "cg" are the ones related to wave 7). I would like to remove the "i", "ce" and "cg" from the beginning of the variables, rename them "wave 9", "wave 5" and "wave 7", respectively. Then I would like to convert the dataset into a longitudinal data with a column with the information of the waves. For example:
Wave. Var1 Var2 Var3
wave 9
wave 5
wave 7
wave 9
wave 5
wave 7
...
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long(pidp pid) byte i_sex int i_dvage byte(i_nadoptch ce_age cg_age i_scghqi cg_scghqi ce_scghqi) 22445 10127798 2 33 0 . . 2 . . 29925 10192697 2 40 0 . . 2 . . 76165 10689869 2 34 0 . . 1 . . 280165 12430439 2 38 0 . . 1 . . 333205 12908843 2 26 0 . . 1 . . 469205 13857142 2 27 0 . . 2 . . 599765 14757249 2 30 0 . . 1 . . 732365 15752658 1 32 0 . . 4 . . 1587125 17870879 2 51 0 . . 2 . . 1697285 42526507 1 44 0 . . 2 . . 1833965 50832336 1 52 0 . . 2 . . 2270525 76446336 2 20 0 . . 3 . . 2626845 93565895 1 39 0 . . 2 . . 2888645 96949503 2 28 0 . . 2 . . 3587685 118781707 1 36 -7 . . -7 . . 3663845 119065835 1 33 0 . . -8 . . 3667245 119074613 2 29 0 . . 3 . . 3705325 119277506 2 63 0 . . 2 . . 4454005 154358304 1 72 0 . . 2 . . 4849085 176725733 1 34 0 . . 3 . . 4853165 176977635 1 47 0 . . 1 . . 68002045 10017933 2 74 0 . . -8 . . 68002725 10023526 2 63 0 . . 1 . . 68004087 -8 1 67 0 . . 3 . . 68006127 -8 2 47 0 . . 2 . . 68006807 -8 2 80 0 . . 4 . . 68008847 -8 2 59 0 . . 2 . . 68009527 -8 1 39 0 . . 2 . . 68010887 -8 2 53 0 . . 2 . . 68011567 -8 1 43 0 . . 2 . . 68020407 -8 2 80 0 . . 2 . . 68020564 -8 1 46 0 . . 4 . . 68021765 10200436 2 58 0 . . 1 . . 68021781 30139368 1 23 0 . . 1 . . 68028567 -8 2 46 0 . . 3 . . 68028571 -8 1 50 0 . . 2 . . 68028575 -8 2 26 0 . . 2 . . 68029927 -8 2 45 0 . . 2 . . 68029931 -8 1 48 0 . . 1 . . 68031967 -8 2 69 0 . . 2 . . 68035365 10403086 1 65 0 . . 1 . . 68035367 -8 1 36 0 . . 1 . . 68036727 -8 1 85 0 . . 1 . . 68037407 -8 2 48 0 . . 2 . . 68041487 -8 2 47 0 . . 2 . . 68041491 -8 1 44 0 . . 1 . . 68042167 -8 1 47 0 . . 2 . . 68042171 -8 2 46 0 . . 2 . . 68043527 -8 1 63 0 . . 2 . . 68044207 -8 2 42 0 . . 3 . . 68044211 -8 1 44 0 . . 2 . . 68044887 -8 2 70 0 . . 2 . . 68045567 -8 2 55 0 . . 1 . . 68045571 -8 1 57 0 . . 1 . . 68046927 -8 2 44 0 . . 2 . . 68046935 -8 2 17 0 . . 1 . . 68048287 -8 1 70 0 . . 1 . . 68049647 -8 1 59 0 . . 2 . . 68049651 -8 2 57 0 . . 2 . . 68051007 -8 1 56 0 . . 2 . . 68051011 -8 2 49 0 . . 2 . . 68056447 -8 1 54 0 . . 3 . . 68056451 -8 2 52 0 . . 2 . . 68056455 -8 2 22 0 . . 4 . . 68056459 -8 2 17 0 . . 1 . . 68058485 10628126 1 72 0 . . 2 . . 68058487 -8 1 77 0 . . 3 . . 68058489 10628169 2 72 0 . . 1 . . 68058491 -8 2 68 0 . . 3 . . 68059171 -8 2 27 1 . . 2 . . 68060525 10641556 1 90 0 . . 3 . . 68060527 -8 1 43 0 . . 1 . . 68060531 -8 2 44 0 . . 1 . . 68060533 160066204 2 61 0 . . 4 . . 68060537 160066239 1 73 0 . . 1 . . 68061288 -8 2 31 0 . . 2 . . 68063247 -8 2 50 0 . . 1 . . 68063251 -8 1 52 0 . . 1 . . 68063255 -8 1 17 0 . . 3 . . 68063927 -8 2 47 0 . . 1 . . 68063931 -8 1 49 0 . . 1 . . 68064605 10653872 1 68 0 . . 2 . . 68064609 10653902 2 65 0 . . 2 . . 68068007 -8 1 50 0 . . 1 . . 68068011 -8 2 50 0 . . 2 . . 68068015 -8 2 25 0 . . 1 . . 68068082 -8 1 56 0 . . 1 . . 68069367 -8 1 89 0 . . 1 . . 68071407 -8 1 28 0 . . 2 . . 68072087 -8 1 63 0 . . 3 . . 68076167 -8 2 68 0 . . 2 . . 68076171 -8 1 71 0 . . 1 . . 68086371 -8 2 28 0 . . 2 . . 68087727 -8 2 67 0 . . 1 . . 68090447 -8 2 64 0 . . 1 . . 68091127 -8 2 43 0 . . 2 . . 68091135 -8 2 20 0 . . 4 . . 68091139 -8 1 18 0 . . 4 . . 68097245 10913629 2 67 0 . . 1 . . 68097927 -8 2 68 0 . . 2 . . end label values pid pid label def pid -8 "inapplicable", modify label values i_sex i_sex label def i_sex 1 "male", modify label def i_sex 2 "female", modify label values i_dvage i_dvage label values i_nadoptch i_nadoptch label def i_nadoptch -7 "proxy", modify label values ce_age ce_age label values cg_age cg_age label values i_scghqi i_scghqi label def i_scghqi -8 "inapplicable", modify label def i_scghqi -7 "proxy", modify label def i_scghqi 1 "Not at all", modify label def i_scghqi 2 "No more than usual", modify label def i_scghqi 3 "Rather more than usual", modify label def i_scghqi 4 "Much more than usual", modify label values cg_scghqi cg_scghqi label values ce_scghqi ce_scghqi
Comment