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
Scatter plotHi All, I would like to graph a scatter plot with two y-axis and one x-axis. However, I want the se…
A meta-comment about posts following up on old threadsI rarely find that a posting following up on an old thread is useful, and I wonder if that practice …
putexcel in foreach loopI am having some issue writing my data to excel in a for loop. I am very new to macros and loops. Ba…
Error test_boot(): 3301 subscript invalid using cdeco_jmp commandHello Stata community, when i run the cdeco_jmp command with bootstrap using "reps(#)" option stata …
Stata reports decimals in IQRI want to report the interquartile range of charlson comorbidity index. I want do to that for a grou…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding calculating percentages of distinct values
Post a Comment