Hello,
I have the following example data set.
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(case_id audc11 audc12 audc13 audc14 randomnumber)
1 0 .28 .09 .07 .795571
2 .34 .28 .33 .26 .955492
3 .56 .59 .33 .81 .018467158
4 .66 .73 .7 .81 .030028736
5 1 1 1 1 .
end
The last column has the random numbers. I have to compare the random numbers row wise, with the columns audc11- audc14 value, so that Stata returns me the value in the case_id. I have to compare each row number with their respective columns.
For example, when random number is 0.795571 (1st row), I have to compare this value with those in the 1st column of audc11. If the values of the random number is the first near or equal to value to that contained in the columns, I need the corresponding case_id value to be returned.
For example, comparing 1st row of random value (0.799571), to that of those contained in 1st column, the nearest first value to 0.799571 is 0.66. Then the return value I should get is 4, because the corresponding case_id is 4.
Again,comparing 3rd row of random value (0.018467158), to that of those contained in 3rd column, the nearest first value to 0.018467158 is 0.09. Then the return value I should get is 1, because the corresponding case_id is 1.
Any help will be very helpful.
Thank you
I have the following example data set.
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(case_id audc11 audc12 audc13 audc14 randomnumber)
1 0 .28 .09 .07 .795571
2 .34 .28 .33 .26 .955492
3 .56 .59 .33 .81 .018467158
4 .66 .73 .7 .81 .030028736
5 1 1 1 1 .
end
The last column has the random numbers. I have to compare the random numbers row wise, with the columns audc11- audc14 value, so that Stata returns me the value in the case_id. I have to compare each row number with their respective columns.
For example, when random number is 0.795571 (1st row), I have to compare this value with those in the 1st column of audc11. If the values of the random number is the first near or equal to value to that contained in the columns, I need the corresponding case_id value to be returned.
For example, comparing 1st row of random value (0.799571), to that of those contained in 1st column, the nearest first value to 0.799571 is 0.66. Then the return value I should get is 4, because the corresponding case_id is 4.
Again,comparing 3rd row of random value (0.018467158), to that of those contained in 3rd column, the nearest first value to 0.018467158 is 0.09. Then the return value I should get is 1, because the corresponding case_id is 1.
Any help will be very helpful.
Thank you
Comment