Question

I don't know if Stata can do this but I use the tabulate command a lot in order to find frequencies. For instance, I have a success variable which takes on values 0 to 1 and I would like to know the success rate for a certain group of observations ie tab success if group==1. I was wondering if I can do sort of the inverse of this operation. That is, I would like to know if I can find a value of "group" for which the frequency is greater than or equal to 15% for example.

Is there a command that does this?

Thanks

As an example

sysuse auto
gen success=mpg<29

Now I want to find the value of price such that the frequency of the success variable is greater than 75% for example.

Was it helpful?

Solution

According to @Nick:

ssc install groups 
sysuse auto 
count
   74
#return list optional
local nobs=r(N) # r(N) gives total observation 

groups  rep78, sel(f >(0.15*`r(N)')) #gives the group for which freq >15 % 

  +---------------------------------+
  | rep78   Freq.   Percent    % <= |
  |---------------------------------|
  |     3      30     43.48   57.97 |
  |     4      18     26.09   84.06 |
  +---------------------------------+
groups  rep78, sel(f >(0.10*`nobs'))# more than 10 %

  +----------------------------------+
  | rep78   Freq.   Percent     % <= |
  |----------------------------------|
  |     2       8     11.59    14.49 |
  |     3      30     43.48    57.97 |
  |     4      18     26.09    84.06 |
  |     5      11     15.94   100.00 |
  +----------------------------------+

OTHER TIPS

I'm not sure if I fully understand your question/situation, but I believe this might be useful. You can egen a variable that is equal to the mean of success, by group, and then see which observations have the value for mean(success) that you're looking for.

egen avgsuccess = mean(success), by(group)
tab group if avgsuccess >= 0.15
list group if avgsuccess >= 0.15

Does that accomplish what you want?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top