Hello,
Using Stata 16.1 for Mac, I have been doing quite a bit of searching online to try to figure this out and keep getting confused. I have a dataset with a large number of IDs, many of which are repeated multiple times. I want to figure out the percentage of IDs that have only been seen 1 time, that have been seen 2 times, 3 times, etc. so that I can calculate the percentage of people who were seen once, twice, three times, etc. My dataset is about 80,000 observations (which includes the repeated values), so it is impossible to recode any variables by hand.
I have used bysort patient_id : gen patient_id_count = _N, but the frequencies included the duplicate values, which makes my data meaningless.
I have downloaded the Distinct function, but it just shows me how many distinct values there are overall - what I need is the number of times each distinct value is showing up as a frequency and as a percentage.
I have also tried:
by patient_id, sort: gen nvals = _n == 1
tab nvals
which shows me the number of distinct values overall as well.
The only thing that got me close to what I want is Contract, but that eliminates the rest of my data, so it is difficult to use that.
contract patient_id
tab _freq
Any suggestions?
Thank you kindly.
Related Posts with Question regarding calculating percentages of distinct values
Merge two tables with different unique idHi, I have two tables named Ingreso and Trabajo. They look like this: Ingreso folioviv foliohog …
expand data?Dear All, I have this data set. Code: * Example generated by -dataex-. For more info, type help dat…
mmqreg with outreg2Dear All, I ran the regression (Please ssc install mmqreg, ssc install outreg2): Code: webuse nlswo…
Twoway Graph - option mlabformat() not allowedHi everyone, First time posting questions by myself here. I used to browse the questions and find s…
Behavior analysis (relational or random variables?)Dear, good night! I read several topics, but I got more lost. I tried to make a tree to check a path…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding calculating percentages of distinct values
Post a Comment