Dear Statalisters,
I was wondering if anyone can help me with a more efficient (programming wise) method to determine the number of different values that a variable has.
For example, lets assume the following data:
set obs 1000
gen dm=_n
drop if runiform()<.3
expand ceil(runiform()*40)
The way i would usually determine the number of cases is
codebook dm
and if i want to store it i would use the following code:
egen _k=group(dm)
sum _k
and the number of unique values will be stored in r(max).
I would appreiate if anyone knows of a faster method.
Thanks
Fernando Rios
I was wondering if anyone can help me with a more efficient (programming wise) method to determine the number of different values that a variable has.
For example, lets assume the following data:
set obs 1000
gen dm=_n
drop if runiform()<.3
expand ceil(runiform()*40)
The way i would usually determine the number of cases is
codebook dm
and if i want to store it i would use the following code:
egen _k=group(dm)
sum _k
and the number of unique values will be stored in r(max).
I would appreiate if anyone knows of a faster method.
Thanks
Fernando Rios
Comment