Consider two variables X , Z (these can have a different number of non-missing observations). I am trying to count the fraction of all possible (X, Z) pairs that have the property that X > Z. (Actually, I am trying to do something a bit more complicated but this should be a good warm-up!)
For example, suppose that my dataset is:
(Here, X has one missing observation.) In this case, there are two possible pairs, i.e. (1, 0) and (1, 2), and X > Z in 1/2 of the cases.
In Python, one could do this by writing something like:
However, I have no idea how to do this in STATA. Is it easy to do?
If I may a second question, I will ultimately want to bootstrap (a more complicated version of) this estimate. Is this also easy to do in STATA?
Thanks in advance for any suggestions or pointers.
For example, suppose that my dataset is:
X | Z |
1 | 0 |
. | 2 |
In Python, one could do this by writing something like:
HTML Code:
pairs = 0 x_exceeds_z = 0 for x in x_list: for z in z_list: pairs += 1 if x > z: x_exceeds_z += 1 print(x_exceeds_z/pairs)
If I may a second question, I will ultimately want to bootstrap (a more complicated version of) this estimate. Is this also easy to do in STATA?
Thanks in advance for any suggestions or pointers.
Comment