Stata: Continent variable based on Country variable (ISO code [ISO3166- numeric])

Standard

I recently wanted to examine migrants’ labour market situation  by their continent of birth , however datasets like the EU-Labour Forces Survey or EU-SILC or the UK-LFS, don’t provide a continent variable.

Below you can find the Stata code to generate a continent variable (e.g. indicating Antarctica as continent of origin) based on a variable containing country information (in ISO 3-digit format, e.g. 404 = “Kenya”).

*Generate empty string variable
gen continent = ""

*Replace empty observations with Continent string given a country variable.<\code>
replace continent = "Not defined" if(country_origin==-9 & continent=="")
replace continent = "Not defined" if(country_origin==-8 & continent=="")
replace continent = "AS" if(country_origin==4 & continent=="")
replace continent = "EU" if(country_origin==8 & continent=="")
replace continent = "ANT" if(country_origin==10 & continent=="")
replace continent = "AF" if(country_origin==12 & continent=="")
replace continent = "OC" if(country_origin==16 & continent=="")
replace continent = "EU" if(country_origin==20 & continent=="")
replace continent = "AF" if(country_origin==24 & continent=="")
replace continent = "CAR" if(country_origin==28 & continent=="")
replace continent = "AS" if(country_origin==31 & continent=="")
replace continent = "SA" if(country_origin==32 & continent=="")
replace continent = "OC" if(country_origin==36 & continent=="")
replace continent = "EU" if(country_origin==40 & continent=="")
replace continent = "CAR" if(country_origin==44 & continent=="")
replace continent = "AS" if(country_origin==48 & continent=="")
replace continent = "AS" if(country_origin==50 & continent=="")
replace continent = "AS" if(country_origin==51 & continent=="")
replace continent = "CAR" if(country_origin==52 & continent=="")
replace continent = "EU" if(country_origin==56 & continent=="")
replace continent = "CAR" if(country_origin==60 & continent=="")
replace continent = "AS" if(country_origin==64 & continent=="")
replace continent = "SA" if(country_origin==68 & continent=="")
replace continent = "EU" if(country_origin==70 & continent=="")
replace continent = "AF" if(country_origin==72 & continent=="")
replace continent = "ANT" if(country_origin==74 & continent=="")
replace continent = "SA" if(country_origin==76 & continent=="")
replace continent = "MA" if(country_origin==84 & continent=="")
replace continent = "AS" if(country_origin==86 & continent=="")
replace continent = "OC" if(country_origin==90 & continent=="")
replace continent = "CAR" if(country_origin==92 & continent=="")
replace continent = "AS" if(country_origin==96 & continent=="")
replace continent = "EU" if(country_origin==100 & continent=="")
replace continent = "AS" if(country_origin==104 & continent=="")
replace continent = "AF" if(country_origin==108 & continent=="")
replace continent = "EU" if(country_origin==112 & continent=="")
replace continent = "AS" if(country_origin==116 & continent=="")
replace continent = "AF" if(country_origin==120 & continent=="")
replace continent = "AN" if(country_origin==124 & continent=="")
replace continent = "AF" if(country_origin==132 & continent=="")
replace continent = "CAR" if(country_origin==136 & continent=="")
replace continent = "AF" if(country_origin==140 & continent=="")
replace continent = "AS" if(country_origin==144 & continent=="")
replace continent = "AF" if(country_origin==148 & continent=="")
replace continent = "SA" if(country_origin==152 & continent=="")
replace continent = "AS" if(country_origin==156 & continent=="")
replace continent = "AS" if(country_origin==158 & continent=="")
replace continent = "AS" if(country_origin==162 & continent=="")
replace continent = "AS" if(country_origin==166 & continent=="")
replace continent = "SA" if(country_origin==170 & continent=="")
replace continent = "AF" if(country_origin==174 & continent=="")
replace continent = "AF" if(country_origin==175 & continent=="")
replace continent = "AF" if(country_origin==178 & continent=="")
replace continent = "AF" if(country_origin==180 & continent=="")
replace continent = "OC" if(country_origin==184 & continent=="")
replace continent = "MA" if(country_origin==188 & continent=="")
replace continent = "EU" if(country_origin==191 & continent=="")
replace continent = "CAR" if(country_origin==192 & continent=="")
replace continent = "EU" if(country_origin==203 & continent=="")
replace continent = "AF" if(country_origin==204 & continent=="")
replace continent = "EU" if(country_origin==208 & continent=="")
replace continent = "CAR" if(country_origin==212 & continent=="")
replace continent = "CAR" if(country_origin==214 & continent=="")
replace continent = "SA" if(country_origin==218 & continent=="")
replace continent = "CAR" if(country_origin==222 & continent=="")
replace continent = "AF" if(country_origin==226 & continent=="")
replace continent = "AF" if(country_origin==231 & continent=="")
replace continent = "AF" if(country_origin==232 & continent=="")
replace continent = "EU" if(country_origin==233 & continent=="")
replace continent = "EU" if(country_origin==234 & continent=="")
replace continent = "SA" if(country_origin==238 & continent=="")
replace continent = "ANT" if(country_origin==239 & continent=="")
replace continent = "OC" if(country_origin==242 & continent=="")
replace continent = "EU" if(country_origin==246 & continent=="")
replace continent = "EU" if(country_origin==248 & continent=="")
replace continent = "EU" if(country_origin==250 & continent=="")
replace continent = "SA" if(country_origin==254 & continent=="")
replace continent = "OC" if(country_origin==258 & continent=="")
replace continent = "ANT" if(country_origin==260 & continent=="")
replace continent = "AF" if(country_origin==262 & continent=="")
replace continent = "AF" if(country_origin==266 & continent=="")
replace continent = "AS" if(country_origin==268 & continent=="")
replace continent = "AF" if(country_origin==270 & continent=="")
replace continent = "AS" if(country_origin==275 & continent=="")
replace continent = "EU" if(country_origin==276 & continent=="")
replace continent = "AF" if(country_origin==288 & continent=="")
replace continent = "EU" if(country_origin==292 & continent=="")
replace continent = "OC" if(country_origin==296 & continent=="")
replace continent = "EU" if(country_origin==300 & continent=="")
replace continent = "AN" if(country_origin==304 & continent=="")
replace continent = "CAR" if(country_origin==308 & continent=="")
replace continent = "CAR" if(country_origin==312 & continent=="")
replace continent = "OC" if(country_origin==316 & continent=="")
replace continent = "MA" if(country_origin==320 & continent=="")
replace continent = "AF" if(country_origin==324 & continent=="")
replace continent = "SA" if(country_origin==328 & continent=="")
replace continent = "CAR" if(country_origin==332 & continent=="")
replace continent = "ANT" if(country_origin==334 & continent=="")
replace continent = "EU" if(country_origin==336 & continent=="")
replace continent = "MA" if(country_origin==340 & continent=="")
replace continent = "AS" if(country_origin==344 & continent=="")
replace continent = "EU" if(country_origin==348 & continent=="")
replace continent = "EU" if(country_origin==352 & continent=="")
replace continent = "AS" if(country_origin==356 & continent=="")
replace continent = "AS" if(country_origin==360 & continent=="")
replace continent = "AS" if(country_origin==364 & continent=="")
replace continent = "AS" if(country_origin==368 & continent=="")
replace continent = "EU" if(country_origin==372 & continent=="")
replace continent = "AS" if(country_origin==376 & continent=="")
replace continent = "EU" if(country_origin==380 & continent=="")
replace continent = "AF" if(country_origin==384 & continent=="")
replace continent = "CAR" if(country_origin==388 & continent=="")
replace continent = "AS" if(country_origin==392 & continent=="")
replace continent = "AS" if(country_origin==398 & continent=="")
replace continent = "AS" if(country_origin==400 & continent=="")
replace continent = "AF" if(country_origin==404 & continent=="")
replace continent = "AS" if(country_origin==408 & continent=="")
replace continent = "AS" if(country_origin==410 & continent=="")
replace continent = "AS" if(country_origin==414 & continent=="")
replace continent = "AS" if(country_origin==417 & continent=="")
replace continent = "AS" if(country_origin==418 & continent=="")
replace continent = "AS" if(country_origin==422 & continent=="")
replace continent = "AF" if(country_origin==426 & continent=="")
replace continent = "EU" if(country_origin==428 & continent=="")
replace continent = "AF" if(country_origin==430 & continent=="")
replace continent = "AF" if(country_origin==434 & continent=="")
replace continent = "EU" if(country_origin==438 & continent=="")
replace continent = "EU" if(country_origin==440 & continent=="")
replace continent = "EU" if(country_origin==442 & continent=="")
replace continent = "AS" if(country_origin==446 & continent=="")
replace continent = "AF" if(country_origin==450 & continent=="")
replace continent = "AF" if(country_origin==454 & continent=="")
replace continent = "AS" if(country_origin==458 & continent=="")
replace continent = "AS" if(country_origin==462 & continent=="")
replace continent = "AF" if(country_origin==466 & continent=="")
replace continent = "EU" if(country_origin==470 & continent=="")
replace continent = "CAR" if(country_origin==474 & continent=="")
replace continent = "AF" if(country_origin==478 & continent=="")
replace continent = "AF" if(country_origin==480 & continent=="")
replace continent = "AN" if(country_origin==484 & continent=="")
replace continent = "EU" if(country_origin==492 & continent=="")
replace continent = "AS" if(country_origin==496 & continent=="")
replace continent = "EU" if(country_origin==498 & continent=="")
replace continent = "EU" if(country_origin==499 & continent=="")
replace continent = "CAR" if(country_origin==500 & continent=="")
replace continent = "AF" if(country_origin==504 & continent=="")
replace continent = "AF" if(country_origin==508 & continent=="")
replace continent = "AS" if(country_origin==512 & continent=="")
replace continent = "AF" if(country_origin==516 & continent=="")
replace continent = "OC" if(country_origin==520 & continent=="")
replace continent = "AS" if(country_origin==524 & continent=="")
replace continent = "EU" if(country_origin==528 & continent=="")
replace continent = "CAR" if(country_origin==530 & continent=="")
replace continent = "CAR" if(country_origin==531 & continent=="")
replace continent = "CAR" if(country_origin==533 & continent=="")
replace continent = "CAR" if(country_origin==534 & continent=="")
replace continent = "CAR" if(country_origin==535 & continent=="")
replace continent = "OC" if(country_origin==540 & continent=="")
replace continent = "OC" if(country_origin==548 & continent=="")
replace continent = "OC" if(country_origin==554 & continent=="")
replace continent = "MA" if(country_origin==558 & continent=="")
replace continent = "AF" if(country_origin==562 & continent=="")
replace continent = "AF" if(country_origin==566 & continent=="")
replace continent = "OC" if(country_origin==570 & continent=="")
replace continent = "OC" if(country_origin==574 & continent=="")
replace continent = "EU" if(country_origin==578 & continent=="")
replace continent = "OC" if(country_origin==580 & continent=="")
replace continent = "OC" if(country_origin==581 & continent=="")
replace continent = "OC" if(country_origin==583 & continent=="")
replace continent = "OC" if(country_origin==584 & continent=="")
replace continent = "OC" if(country_origin==585 & continent=="")
replace continent = "AS" if(country_origin==586 & continent=="")
replace continent = "MA" if(country_origin==591 & continent=="")
replace continent = "OC" if(country_origin==598 & continent=="")
replace continent = "SA" if(country_origin==600 & continent=="")
replace continent = "SA" if(country_origin==604 & continent=="")
replace continent = "AS" if(country_origin==608 & continent=="")
replace continent = "OC" if(country_origin==612 & continent=="")
replace continent = "EU" if(country_origin==616 & continent=="")
replace continent = "EU" if(country_origin==620 & continent=="")
replace continent = "AF" if(country_origin==624 & continent=="")
replace continent = "AS" if(country_origin==626 & continent=="")
replace continent = "CAR" if(country_origin==630 & continent=="")
replace continent = "AS" if(country_origin==634 & continent=="")
replace continent = "AF" if(country_origin==638 & continent=="")
replace continent = "EU" if(country_origin==642 & continent=="")
replace continent = "EU" if(country_origin==643 & continent=="")
replace continent = "AF" if(country_origin==646 & continent=="")
replace continent = "CAR" if(country_origin==652 & continent=="")
replace continent = "AF" if(country_origin==654 & continent=="")
replace continent = "CAR" if(country_origin==659 & continent=="")
replace continent = "CAR" if(country_origin==660 & continent=="")
replace continent = "CAR" if(country_origin==662 & continent=="")
replace continent = "CAR" if(country_origin==663 & continent=="")
replace continent = "CAR" if(country_origin==666 & continent=="")
replace continent = "CAR" if(country_origin==670 & continent=="")
replace continent = "EU" if(country_origin==674 & continent=="")
replace continent = "AF" if(country_origin==678 & continent=="")
replace continent = "AS" if(country_origin==682 & continent=="")
replace continent = "AF" if(country_origin==686 & continent=="")
replace continent = "EU" if(country_origin==688 & continent=="")
replace continent = "AF" if(country_origin==690 & continent=="")
replace continent = "AF" if(country_origin==694 & continent=="")
replace continent = "AS" if(country_origin==702 & continent=="")
replace continent = "EU" if(country_origin==703 & continent=="")
replace continent = "AS" if(country_origin==704 & continent=="")
replace continent = "EU" if(country_origin==705 & continent=="")
replace continent = "AF" if(country_origin==706 & continent=="")
replace continent = "AF" if(country_origin==710 & continent=="")
replace continent = "AF" if(country_origin==716 & continent=="")
replace continent = "AF" if(country_origin==728 & continent=="")
replace continent = "AF" if(country_origin==729 & continent=="")
replace continent = "AF" if(country_origin==732 & continent=="")
replace continent = "AF" if(country_origin==736 & continent=="")
replace continent = "SA" if(country_origin==740 & continent=="")
replace continent = "EU" if(country_origin==744 & continent=="")
replace continent = "AF" if(country_origin==748 & continent=="")
replace continent = "EU" if(country_origin==752 & continent=="")
replace continent = "EU" if(country_origin==756 & continent=="")
replace continent = "AS" if(country_origin==760 & continent=="")
replace continent = "AS" if(country_origin==762 & continent=="")
replace continent = "AS" if(country_origin==764 & continent=="")
replace continent = "AF" if(country_origin==768 & continent=="")
replace continent = "OC" if(country_origin==772 & continent=="")
replace continent = "OC" if(country_origin==776 & continent=="")
replace continent = "CAR" if(country_origin==780 & continent=="")
replace continent = "AS" if(country_origin==784 & continent=="")
replace continent = "AF" if(country_origin==788 & continent=="")
replace continent = "EU" if(country_origin==792 & continent=="")
replace continent = "AS" if(country_origin==795 & continent=="")
replace continent = "CAR" if(country_origin==796 & continent=="")
replace continent = "OC" if(country_origin==798 & continent=="")
replace continent = "AF" if(country_origin==800 & continent=="")
replace continent = "EU" if(country_origin==804 & continent=="")
replace continent = "EU" if(country_origin==807 & continent=="")
replace continent = "AF" if(country_origin==818 & continent=="")
replace continent = "EU" if(country_origin==831 & continent=="")
replace continent = "EU" if(country_origin==832 & continent=="")
replace continent = "EU" if(country_origin==833 & continent=="")
replace continent = "AF" if(country_origin==834 & continent=="")
replace continent = "AN" if(country_origin==840 & continent=="")
replace continent = "CAR" if(country_origin==850 & continent=="")
replace continent = "AF" if(country_origin==854 & continent=="")
replace continent = "SA" if(country_origin==858 & continent=="")
replace continent = "AS" if(country_origin==860 & continent=="")
replace continent = "SA" if(country_origin==862 & continent=="")
replace continent = "OC" if(country_origin==876 & continent=="")
replace continent = "OC" if(country_origin==882 & continent=="")
replace continent = "AS" if(country_origin==887 & continent=="")
replace continent = "EU" if(country_origin==891 & continent=="")
replace continent = "AF" if(country_origin==894 & continent=="")
replace continent = "EU" if(country_origin==901 & continent=="")
replace continent = "EU" if(country_origin==902 & continent=="")
replace continent = "EU" if(country_origin==903 & continent=="")
replace continent = "EU" if(country_origin==911 & continent=="")
replace continent = "EU" if(country_origin==912 & continent=="")
replace continent = "EU" if(country_origin==913 & continent=="")
replace continent = "EU" if(country_origin==921 & continent=="")
replace continent = "EU" if(country_origin==922 & continent=="")
replace continent = "EU" if(country_origin==923 & continent=="")
replace continent = "EU" if(country_origin==924 & continent=="")
replace continent = "EU" if(country_origin==925 & continent=="")
replace continent = "EU" if(country_origin==926 & continent=="")
replace continent = "EU" if(country_origin==931 & continent=="")
replace continent = "EU" if(country_origin==951 & continent=="")
replace continent = "EU" if(country_origin==971 & continent=="")
replace continent = "AS" if(country_origin==972 & continent=="")
replace continent = "EU" if(country_origin==973 & continent=="")
replace continent = "EU" if(country_origin==974 & continent=="")
replace continent = "EU" if(country_origin==981 & continent=="")
replace continent = "AF" if(country_origin==982 & continent=="")
replace continent = "AS" if(country_origin==983 & continent=="")
replace continent = "AS" if(country_origin==984 & continent=="")
replace continent = "AN" if(country_origin==985 & continent=="")
replace continent = "MA" if(country_origin==986 & continent=="")
replace continent = "SA" if(country_origin==987 & continent=="")
replace continent = "CAR" if(country_origin==988 & continent=="")
replace continent = "ANT" if(country_origin==989 & continent=="")
replace continent = "Not defined" if(country_origin==990 & continent=="")
replace continent = "Not defined" if(country_origin==991 & continent=="")
replace continent = "Not defined" if(country_origin==992 & continent=="")


*Destringing
local names = "AF ANT AN MA SA AS CAR EU OC"
local i = 0
foreach name of local names {
replace continent = "`i'" if(continent=="`name'")
local ++i
}
replace continent = "9" if(continent=="Not defined")

destring continent, replace

label define continent 0 "Africa" 1 "Antarctica" 2 "North America" 3 "South America" 4 "Middle America" 5 "Asia" 6 "Caribeans" 7 "Europe" 8 "Oceania" 9 "Not defined"
label val continent continent

Stata syntax to map SOC2010 to ISCO-08

Standard

Stata code for mapping the Standard Occupational Classification 2000 (SOC2010) to the International Standard Classification of Occupations (ISCO08).

The Stata dofile below maps the occupation categories of the the UK Standard Occupational Classification 2010  to the International Standard Classification of Occupations 2008 using the guidelines available from the Office for National Statistics (ONS).

The mapping has three elements: 1:1 mapping of SOC2010 categories with equivalents in ISCO08, 1-to-2 mapping of SOC2010 categories corresponding to two ISCO08 categories, and indicating those ISCO08 categories with no SOC2010 equivalent.

The 1-to-2 mapping is done using a random 50:50 or 40:60 assignment to reflect the proportions suggested by ONS (see guidelines above). – Given the random assignment the proportions are occasionally not exact 50% or 40/60% and users of the code might want to re-run the respective lines to achieve closer proportions if necessary.

Do-File for Soc2010 to ISCO2008 conversion (using the UK Labour Force variable  SOC10M): SOC10M_to_ISCO08_v1_1_20160409 (Do-file).

Related: