Some context before I ask my question:
I have a country dataset that is in wide mode:
I need to distinguish some countries from others, so I have created some locals with countries lists that I need, and I used these locals to create the variables needed. I merged this data set with other data sets to create a multi-year data set. I use this compiled data sets for several analyses that I need.
For a different set of analyses, I need the data in a different shape. I use xpose to transpose and then a reshape from long to wide to finally have the following:
Now to my question:
I would like to create a categorical variable that identifies the countries in the same way I already did with the locals earlier. Something of this sort:
I would really appreciate any help on how to do this. I guess I could just replace the code above to have the full list of countries that are in each category, but I have several locals, each with several countries, so a more expedite way of doing so would be great!
I have a country dataset that is in wide mode:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str63 ghecause3 double(afghanistan albania algeria angola antiguaandbarbuda argentina armenia) "Population ('000) (2)" 29186 2948 35977 23356 88 40896 2877 "All Causes" 17638.90519 791.6554766 9000.543422 17835.01064 21.86865848 11472.27578 959.7303262 "I. Communicable, maternal, perinatal and nutritional conditions" . 58.131547 2148.348008 12606.21368 3.040690815 1520.611924 92.53143811 "A. Infectious and parasitic diseases" . 13.73803992 457.8259199 6035.01793 1.172297013 486.7600974 22.80165377 "1. Tuberculosis" . .505634161 177.5524798 899.9878949 .043649908 21.98516738 6.782443094 "2. STDs excluding HIV" . .467617604 9.656389858 103.4173163 .028337724 7.828691408 .699179626 "a. Syphilis" . .118382254 3.978862245 97.20594281 .001195393 1.235240785 .073528887 "b. Chlamydia" . .086156928 1.686355774 1.142276611 .004408259 1.346285491 .133672959 "c. Gonorrhoea" . .043373299 .823506852 1.351495562 .001852797 .713995777 .081503836 "d. Trichomoniasis" . .086024014 .874204434 .796841495 .004953674 .960610828 .14323437 "e. Genital herpes" . .052038173 .870731822 1.259828214 .005215848 1.74979586 .071220726 "f. Other STDs" . .081642937 1.422728904 1.660931562 .010711753 1.822762678 .196018839 "3. HIV/AIDS" . .484557871 8.781621292 646.3431386 .51618161 83.02695196 1.462131419 "4. Diarrhoeal diseases" . 6.460200488 161.511244 2027.283188 .152642029 56.17996447 6.319187744 end
For a different set of analyses, I need the data in a different shape. I use xpose to transpose and then a reshape from long to wide to finally have the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str24 country float(dalys_diarrhea2010 dalys_diarrhea2019 dalys_diarrheachange) "afghanistan" . . . "albania" 6.4602 5.510137 -.14706416 "algeria" 161.51125 151.41914 -.06248543 "angola" 2027.2832 1099.4377 -.4576792 "antiguaandbarbuda" .15264203 .1752379 .14803186 "argentina" 56.17997 52.46862 -.0660617 "armenia" 6.319188 5.967241 -.05569488 end
I would like to create a categorical variable that identifies the countries in the same way I already did with the locals earlier. Something of this sort:
Code:
local jee1 afghanistan angola benin botswana burkinafaso local jee2 algeria bhutan burundi cambodia cameroon comoros * more locals are added, the code continues, I xpose, reshape, etc. gen jee = 1 if inlist(country,`jee1') replace jee = 2 if inlist(country,`jee2')
Comment