Hi All,
I have data which resembles the following:
Here, I have data which contains a variable num_obs, and another variable y. I wish to calculate conditional minimums of y by num_obs, making use of the egen command. There seem to be two different interpretations, the distinction between which is not obvious from the sytanx.
Consider
From the results, it seems the way egen works is that it evaluates the if condition first (line by line), and then computes the minimum from the surviving lines. For the lines that do not survive the -if- condition, a reasonable value of missing is assinged.
Another interpretation of the egen command could be that it would always calculate the global minimum (say the value which coincides with min3), and then only assign values where the -if- condition is met. In other words, the -if- condition is not used in computation, but only in assignment. At present, it seems that it is used in both computation as well as assignment. Have I completely lost the plot here? Is there a way to reconcile this seeming distinction? Or is this somehow apparent from the syntax which I might have missed.
Many thanks,
CS
I have data which resembles the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(num_obs y) 1 10 0 11 end
Here, I have data which contains a variable num_obs, and another variable y. I wish to calculate conditional minimums of y by num_obs, making use of the egen command. There seem to be two different interpretations, the distinction between which is not obvious from the sytanx.
Consider
Code:
egen min1=min(y) if num_obs==1 egen min2=min(y) if num_obs==0 egen min3=min(y)
Another interpretation of the egen command could be that it would always calculate the global minimum (say the value which coincides with min3), and then only assign values where the -if- condition is met. In other words, the -if- condition is not used in computation, but only in assignment. At present, it seems that it is used in both computation as well as assignment. Have I completely lost the plot here? Is there a way to reconcile this seeming distinction? Or is this somehow apparent from the syntax which I might have missed.
Many thanks,
CS
Comment