Creating a counting variable in Stata

If we are working with a clinical data that is set in a long format, we might want to create a "counting" variable that would serve as the visit number.
First step is to make sure that every patient has a unique "numeric code associated to him/her".
In my case I will start by using the encode function
encode patientname, gen (id)         ///In my case I will start by using the encode function
bysort id: gen visit = _n         /// then we sort id and generate the counting variable visit

No comments:

Post a Comment