0
votes

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.

2
Your question contains its own answer. You can do what you know how to do because you can write down a condition that if can interpret using known variables and/or constants. So, you need to be able to do that. Usually some data manipulations would be required to get to that point. Depending on details, there may be partial exceptions e.g. check out groups from SSC.Nick Cox
I have no idea what you're saying to be honest. I want to know if there is a command that instead of telling me the frequency, I can put in the frequency and it will give me the value for the group. Is that possible?Pcarlitz
I am saying (e.g.) if you have a variable for frequency, then naturally you can specify a condition using that variable. Which part of "check out groups from SSC" did you not understand?Nick Cox
Anyone not familiar with SSC should follow help ssc.Nick Cox
I could figure out follow groups from ssc. I just didn't understand anything else you said.Pcarlitz

2 Answers

1
votes

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?

1
votes

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 |
  +----------------------------------+