In research, we often have to figure out the number of unique observations-
For a small set of data, you can of course just use the command cookbook.
However, when you want to create a variable containing the unique number of observation by certain group then you can’t just use codebook.
Thankfully, we have the command egen to save the day-
**marks the unique observation
**Adds the unique observations and provides the total
egen tot_uniq=total(uniq), by(id)
I use this code to count the unique number of files for each firm or to count the number of unique directors for each firm-
It works well and it saves a ton of time-
Hope this code saves you some time and stress 😀
If this code solved a problem for you, please leave a comment-
Rejoice at all times. Pray without ceasing. Give thanks in every circumstance, for this is God’s will for you in Christ Jesus.
1 Thessalonians 5: 16-18