My dataset looks like this id gap insurance 1 -5 one 1 2 one 1 9 two 2 1 three 2 10 one 3 5 four 3 4 four 3 2 one 3 -3 two What i want to do is the following, i want a new variable created that will give me the most occuring insurance if the gap is between -5 to 5 days. id-Unique id of the individual gap-gap in days insurance-the different types of insurance So my final result should look like id gap insurance finalinsurance 1 -5 one one 1 2 one one 1 9 two one 2 1 three three 2 10 one three 3 5 four four 3 4 four four 3 2 one four 3 -3 two four some more insight on the result: ID 1 has 2 insurance that falls within my -5 to 5 days gap so i take a count of it, and i pick the most common one. In this case it is one so i populate the new variable with this answer. ID 2 only one met my criteria so i went with the insurance , which is three. ID 3, they all fall within my gap, so i take a count of the insurance input and go with the most common one, in this case insurance type four is the most common one. Please any assistance will be appreciated. Thank you.
... View more