Hey everybody,
I want to count how many time a dummy variable equals one if an identifier has a specific value.
In the end I want to compute percentage share when the dummy equals if an identifier has a specific value.
I tried that code:
It seems to work out.
But it would be even better if I can compute the percentage share for different values of id so that I don't have to repeat the command for each identifier.
Any suggestions?
Many thanks in advance.
Bene
I want to count how many time a dummy variable equals one if an identifier has a specific value.
In the end I want to compute percentage share when the dummy equals if an identifier has a specific value.
I tried that code:
Code:
gen freq = _N if id==1 egen dummy = count(mpg) if mpg==1 & id==1 egen cdummy = sum(dummy) & id==1 gen share = dummy/freq if id==1
But it would be even better if I can compute the percentage share for different values of id so that I don't have to repeat the command for each identifier.
Any suggestions?
Many thanks in advance.
Bene
Comment