I have a dataset where I have 4 municipalities. For each municipality, I have many villages. Similarly, for each municipality and village, I have many observations. I wish to create a unique id with municipality code+village code + observation no. I am facing a problem with the village code. Village is a string variable for me.
I want that villages should have the same set of codes for different municipalities. For municipality 1, there should be a village 1 till village 30. For municipality 2, there should be a village 1 till x. So that when I create my id, it turns out to be like '101' or '201' or '102'. 101 being 1st village of municipality 1. 201 being 1st village of municipality 2.
I can't think of any way to generate village codes in this order, apart from writing codes for 134 villages separately.
Please help me with this. Attaching a data example below:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double L_municipality str17 vill_mun 10 "Nayabasti10" 10 "Nayabasti10" 10 "Nayabasti10" 10 "Nayabasti10" 7 "Nayabasti7" 7 "Nayabasti7" 7 "Nayabasti7" 7 "Nayabasti7" 7 "Nayabasti7" 9 "Bhulke9" 9 "Bhulke9" 9 "Bhulke9" 9 "Bhulke9" 9 "Bhulke9" 9 "Bhulke9" 9 "Bhulke9" 5 "Simthana5" 5 "Simthana5" 5 "Simthana5" 5 "Simthana5" 5 "Simthana5" 9 "Singe9" 9 "Singe9" 9 "Singe9" 7 "Kauriya7" 9 "Singe9" 9 "Singe9" 7 "Kauriya7" 9 "Singe9" 7 "Kauriya7" 9 "Singe9" 7 "Kauriya7" 9 "Singe9" 10 "Sundabari10" 7 "Kauriya7" 10 "Sundabari10" 7 "Kauriya7" 10 "Sundabari10" 7 "Kauriya7" 10 "Sundabari10" 7 "Kauriya7" 10 "Sundabari10" 10 "Sundabari10" 7 "Kauriya7" 10 "Sundabari10" 10 "Sundabari10" 10 "Keraghari10" 10 "Sundabari10" 10 "Sundabari10" end label values L_municipality surveysection_1municipality label def surveysection_1municipality 5 "Dangisharan", modify label def surveysection_1municipality 7 "Lamahi", modify label def surveysection_1municipality 9 "Rapti", modify label def surveysection_1municipality 10 "Shantinagar", modify
0 Response to Unique id generation
Post a Comment