Hi Statalisters,
I have data on Indian administrative units for the year 1991. Sample using dataex is below. On trying to merge this data with my master data I found that I was missing a few districts within a few states. So I obtained the details of the missing districts and I want to incorporate it into the sample data given below. So I wrote the following code as an example, obviously using gen when the variable shdist is already in place resulted in me failing to add this new info I want in my data:
Do let me know where I am going wrong and how to circumvent it.
Best,
Lori
I have data on Indian administrative units for the year 1991. Sample using dataex is below. On trying to merge this data with my master data I found that I was missing a few districts within a few states. So I obtained the details of the missing districts and I want to incorporate it into the sample data given below. So I wrote the following code as an example, obviously using gen when the variable shdist is already in place resulted in me failing to add this new info I want in my data:
Code:
// I want to incorporate district number 40 if state == 13 then generate a corresponding string variable = "Bilaspur" if shdist == 40 & state == 13 gen shdist = 40 if state == 13 gen district_labels = "Bilaspur" if shdist == 40 & state == 13 // MP gen shdist = 34 if state == 13 gen district_labels = "Narsimhapur" if shdist == 34 & state == 13 gen shdist = 3 if state == 14 gen district_labels = "Raigarh" if shdist == 3 & state == 14 // Maharashtra gen shdist = 27 if state == 14
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str27 district_labels byte shdist str17 sv024 long state "SRIKAKULAM" 1 "andhra pradesh" 1 "VIZIANAGARAM" 2 "andhra pradesh" 1 "VISAKHAPATNAM" 3 "andhra pradesh" 1 "EAST GODAVARI" 4 "andhra pradesh" 1 "WEST GODAVARI" 5 "andhra pradesh" 1 "KRISHNA" 6 "andhra pradesh" 1 "GUNTUR" 7 "andhra pradesh" 1 "PRAKASAM" 8 "andhra pradesh" 1 "NELLORE" 9 "andhra pradesh" 1 "CHITTOOR" 10 "andhra pradesh" 1 "CUDDAPAH" 11 "andhra pradesh" 1 "ANANTAPUR" 12 "andhra pradesh" 1 "KURNOOL" 13 "andhra pradesh" 1 "MAHBUBNAGAR" 14 "andhra pradesh" 1 "MEDAK" 17 "andhra pradesh" 1 "NIZAMABAD" 18 "andhra pradesh" 1 "ADILABAD" 19 "andhra pradesh" 1 "NALGONDA" 23 "andhra pradesh" 1 "KARIMNAGAR" 20 "andhra pradesh" 1 "WARANGAL" 21 "andhra pradesh" 1 "KHAMMAM" 22 "andhra pradesh" 1 "HYDERABAD" 16 "andhra pradesh" 1 "Dhubri" 1 "assam" 3 "Bongaigaon" 3 "assam" 3 "Goalpara" 4 "assam" 3 "Barpeta" 5 "assam" 3 "Nalbari" 6 "assam" 3 "Kamrup" 7 "assam" 3 "Sonitpur" 9 "assam" 3 "Lakhimpur" 10 "assam" 3 "Dhemaji" 11 "assam" 3 "Marigaon" 12 "assam" 3 "Nagaon" 13 "assam" 3 "Golaghat" 14 "assam" 3 "Jorhat" 15 "assam" 3 "Sibsagar" 16 "assam" 3 "Tinsukia" 18 "assam" 3 "Karbi Anglong" 19 "assam" 3 "Karimganj" 21 "assam" 3 "Hailakandi" 22 "assam" 3 "Cachar" 23 "assam" 3 "Dibrugarh" 17 "assam" 3 "Begusarai" 17 "bihar" 4 "Madhubani" 20 "bihar" 4 "Madhepura" 22 "bihar" 4 "Bhojpur" 3 "bihar" 4 "Rohtas" 4 "bihar" 4 "Patna" 1 "bihar" 4 "Nalanda" 2 "bihar" 4 "Jehanabad" 6 "bihar" 4 "Gaya" 7 "bihar" 4 "Nawada" 8 "bihar" 4 "Saran" 9 "bihar" 4 "Siwan" 10 "bihar" 4 "Gopalganj" 11 "bihar" 4 "Purba Champaran" 13 "bihar" 4 "Sitamarhi" 14 "bihar" 4 "Muzaffarpur" 15 "bihar" 4 "Vaishali" 16 "bihar" 4 "Samastipur" 18 "bihar" 4 "Darbhanga" 19 "bihar" 4 "Saharsa" 21 "bihar" 4 "Purnia" 23 "bihar" 4 "Katihar" 24 "bihar" 4 "Khagaria" 25 "bihar" 4 "Bhagalpur" 27 "bihar" 4 "Godda" 28 "bihar" 4 "Sahibganj" 29 "bihar" 4 "Dumka" 30 "bihar" 4 "Deoghar" 31 "bihar" 4 "Munger" 26 "bihar" 4 "Pashchim Champaran" 12 "bihar" 4 "Goa" 1 "goa" 6 "JAMNAGAR" 1 "gujarat" 7 "RAJKOT" 2 "gujarat" 7 "SURENDRANAGAR" 3 "gujarat" 7 "BHAVNAGAR" 4 "gujarat" 7 "AMRELI" 5 "gujarat" 7 "JUNAGADH" 6 "gujarat" 7 "KACHCHH" 7 "gujarat" 7 "BANASKANTHA" 8 "gujarat" 7 "SABARKANTHA" 9 "gujarat" 7 "MAHESANA" 10 "gujarat" 7 "GANDHINAGAR" 11 "gujarat" 7 "AHMADABAD" 12 "gujarat" 7 "KHEDA" 13 "gujarat" 7 "PANCHMAHALS" 14 "gujarat" 7 "VADODARA" 15 "gujarat" 7 "BHARUCH" 16 "gujarat" 7 "SURAT" 17 "gujarat" 7 "VALSAD" 18 "gujarat" 7 "KARNAL" 5 "haryana" 8 "SONIPAT" 7 "haryana" 8 "ROHTAK" 8 "haryana" 8 "AMBALA" 1 "haryana" 8 "YAMUNANAGAR" 2 "haryana" 8 "KURUKSHETRA" 3 "haryana" 8 "FARIDABAD" 9 "haryana" 8 "GURGAON" 10 "haryana" 8 "MAHENDRAGARH" 12 "haryana" 8 end label values state state label def state 1 "andhra pradesh", modify label def state 3 "assam", modify label def state 4 "bihar", modify label def state 6 "goa", modify label def state 7 "gujarat", modify label def state 8 "haryana", modify
Do let me know where I am going wrong and how to circumvent it.
Best,
Lori
Comment