Fairly new to stata (and stats in general).
I have a database I'm trying to analyze where each unique study ID has multiple entries in sequential rows, before the next study id. These rows are not numbered. I'm trying to figure out how to create a sequentially increasing variable that resets with each new unique study id. In other words, I want to create a variable for the first entry for studyid 1 to be 1, then the next entry for studyid 1 to be 2, the third entry for studyid 3 will be 3, etc. When studyid 2 comes up, I want the variable to reset to 1 then start climbing again until studyid 3, at which time it will reset to 1 again.
What I'm ultimately trying to do is create a j-variable I can use to reshape the database with a bunch of entries for each study id to a wide form so I can add a bunch of outcomes variables that were previously put into a different database where each study id just has one column.
Thanks for the advice. Sorry if this has been answered previously elsewhere, new to the forum...
I have a database I'm trying to analyze where each unique study ID has multiple entries in sequential rows, before the next study id. These rows are not numbered. I'm trying to figure out how to create a sequentially increasing variable that resets with each new unique study id. In other words, I want to create a variable for the first entry for studyid 1 to be 1, then the next entry for studyid 1 to be 2, the third entry for studyid 3 will be 3, etc. When studyid 2 comes up, I want the variable to reset to 1 then start climbing again until studyid 3, at which time it will reset to 1 again.
What I'm ultimately trying to do is create a j-variable I can use to reshape the database with a bunch of entries for each study id to a wide form so I can add a bunch of outcomes variables that were previously put into a different database where each study id just has one column.
Thanks for the advice. Sorry if this has been answered previously elsewhere, new to the forum...
Comment