Hello,
I'm using the below codes to create a district variable.
I'm trying to create a loop for each of the values of the variable 'statecode' as follows:
How can I incorporate the value of the variable 'district' in the above codes? It's different for each `x', so I'm confused about it. Also, is it possible to combine all the values of the variable 'statecode' in one loop?
Thanks
I'm using the below codes to create a district variable.
Code:
gen dist = "" replace dist = "Nicobars" if statecode==35 & district==1 replace dist = "North & Middle Andaman" if statecode==35 & district==2 replace dist = "South Andaman" if statecode==35 & district==3 replace dist = "Srikakulam" if statecode==28 & district==1 replace dist = "Vizianagaram" if statecode==28 & district==2 replace dist = "Visakhapatnam" if statecode==28 & district==3 replace dist = "East Godavari" if statecode==28 & district==4 replace dist = "West Godavari" if statecode==28 & district==5 replace dist = "Krishna" if statecode==28 & district==6 replace dist = "Guntur" if statecode==28 & district==7 replace dist = "Prakasam" if statecode==28 & district==8 replace dist = "Sri Potti Sriramulu Nellore" if statecode==28 & district==9 replace dist = "Y.S.R. (Cuddapah)" if statecode==28 & district==10 replace dist = "Kurnool" if statecode==28 & district==11 replace dist = "Anantapur" if statecode==28 & district==12 replace dist = "Chittoor" if statecode==28 & district==13
Code:
foreach x in Nicobars North & Middle Andaman South Andaman { replace dist = `x' if statecode==28 }
Thanks
Comment