Hi all.
I am very new to Stata (using Stata 17 right now), trying to learn it by myself reading books and I got stuck on this one.
As I am not clear on how to word it, my attempt to search the forum has failed in finding a similar question. Most came up with merging and/or combining.
I am trying to create a new variable based on their unique study_id, read from survey_no. But doing so combines them into a single value when I am trying to list them in order.
For example what I would like to see is 21201 with 123, 21205 with 12 and so on, not 21201 with 6, 21205 with 3.
My hunch is that I list 1, 2, 3 of 20201 then separate it from the rest using lag function but that is the limit of what I understand.
Hopefully it makes sense to you.
Thank you in advance,
I am very new to Stata (using Stata 17 right now), trying to learn it by myself reading books and I got stuck on this one.
As I am not clear on how to word it, my attempt to search the forum has failed in finding a similar question. Most came up with merging and/or combining.
I am trying to create a new variable based on their unique study_id, read from survey_no. But doing so combines them into a single value when I am trying to list them in order.
For example what I would like to see is 21201 with 123, 21205 with 12 and so on, not 21201 with 6, 21205 with 3.
My hunch is that I list 1, 2, 3 of 20201 then separate it from the rest using lag function but that is the limit of what I understand.
Hopefully it makes sense to you.
Thank you in advance,
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long study_id str1 survey_no 21201 "1" 21201 "2" 21201 "3" 21205 "1" 21205 "2" 21301 "1" 21301 "2" 21301 "3" 21401 "1" 21401 "2" 21401 "3" 21403 "1" 21403 "2" 21403 "3" 21404 "1" 21404 "2" 21404 "3" 22101 "1" 22101 "2" 22101 "3" 22102 "1" 22102 "2" 22102 "3" 22103 "1" 22103 "2" 22103 "3" 22104 "1" 22104 "2" 22104 "3" 22105 "1" 22105 "2" 22105 "3" 22106 "1" 22106 "2" 22106 "3" 22107 "1" 22107 "3" 22201 "1" 22201 "2" 22201 "3" 22202 "1" 22202 "2" 22202 "3" 22203 "1" 22203 "2" 22203 "3" 22204 "1" 22204 "2" 22204 "3" 22302 "1" 22302 "2" 22302 "3" 23101 "1" 23101 "2" 23102 "1" 23102 "2" 23104 "1" 23104 "2" 23104 "3" 23106 "1" 23107 "1" 23107 "2" 23107 "3" 23108 "1" 23108 "2" 23108 "3" 23109 "1" 23109 "2" 23109 "3" 23110 "1" 23110 "2" 23110 "3" 23111 "1" 23111 "2" 23111 "3" 23201 "1" 23201 "2" 23201 "3" 23202 "1" 23202 "2" 23202 "3" 23203 "1" 23203 "2" 23203 "3" 23207 "1" 23210 "1" 23210 "2" 23212 "1" 23212 "2" 23212 "3" 23213 "1" 23213 "2" 23301 "1" 23301 "2" 23301 "3" 23302 "1" 23302 "2" 23302 "3" 23303 "1" 23303 "2" end
Comment