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
estimating 5 year survivalHi, I have a dataset with survival months and event (dead/alive). I have been able to stset it and c…
poisson regression (ppmlhdfe) with multiplicative errorIs there a way to force ppmlhdfe to use multiplicative error term instead of additive? I wan to run…
Unequal number of observations in percentile groupsHi Stata users, I am trying to come up with percentile groups using the code below Code: _pctile …
Constructing Gini Index for Household dataDear All I'm computing the Gini coefficient in Stata 16 with the" ineqdeco" command. I'm using panel…
Creating a combined graphHi, I'm struggling to get this right. I have 2 variables that I want to show on a single graph. Fir…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding calculating percentages of distinct values
Post a Comment