Hello! I have a data set of breathalyzer tests. There is a variable for arresting agency and zip code at location of test. My task is to make a unique list of arresting agencies matched with the most common zip code and the percent of the tests from that agency in the zip code. This is what I have so far:
I am getting errors, but after a search of the internet I cannot find any way to do what I am trying to. Thanks for your help!
Code:
#Find the mode for each arresting agency. (`modes' not working with bysort. find another way) bysort arrestingagency: gen mode_zip = modes zip #Find percent of cases with modal zip (count not working) by arrestingagency: gen perc_zip = (count if zip == mode_zip)/_N #Create unique list by arrestingagency: keep if _n=1
Comment