*! version 1.0  19jun2001
* Stata version June 19, 2001 by John Hendrickx <John_Hendrickx@yahoo.com>
/*
Transforms ISCO-68 (International Classification of Occupation)
4-digit occupational codes into
a 10 category EGP scale (Erikson, Goldthorpe, Portocarero)

Source:
Ganzeboom, Harry B.G.;Treiman, Donald J.,
International Stratification and Mobility File: Conversion Tools.
Utrecht: Department of Sociologie,
http://www.fss.uu.nl/soc/hg/ismf.

ISCO-68 Reference:
ILO (International Labour Office). (1968).
International Standard Classification of Occupations, revised edition.
Geneva: International Labour Office.

EGP Reference:
Erikson, R., J.H. Goldthorpe, L. Portocarero. (1979).
International class mobility in three Westen European Countries:
England, France, and Sweden.
British Journal of Sociology 30: 415-451.

Categories:
	  1 "higher controllers"
	  2 "lo controllers"
	  3 "routine nonmanual"
	  4 "sempl with emp"
	  5 "sempl without empl"
	  7 "manual supervisor"
	  8 "skilled manual"
	  9 "semi-unskilld manual"
	 10 "farm labor"
	 11 "selfempl farm"

Notes:

Initial differences:

isco68                          i68lab      SPSS                 Stata
  1491                  'faith healer'         .                     0
  4107                      'smuggler'         .                     0
  4525              'narcotics peddlr'         .                     0
  9430         'nonmet minerl pr makr'         9                     8
  9839           'locomotive engineer'         8                     9

The Stata version has been modified to reproduce the SPSS values. Note that
9430 was recoded twice; the first recode was given precedence. Code 9839 was
recoded to 8 but included in a range that maps to 9.

*/

program define iscoegp
	version 7
	syntax newvarname, isco(varname numeric) sempl(varname numeric) supvis(varname numeric)

	/* comments in the original SPSS version:
	** Please cite use of our conversion tools as:
	** "Ganzeboom, Harry B.G.;Treiman, Donald J.,
	** International Stratification and Mobility
	** File: Conversion Tools. Utrecht: Department of Sociologie,
	** http://www.fss.uu.nl/soc/hg/ismf." Date of last revision.


	** STANDARD RECODE OF OCCUPATIONS IN EGP SCORE
	* THE MODULE HAS BEEN CHANGED TO A FORMAT FOR AN INDETERMINATE
	* NUMBER OF VARIABLES. YOU NEED TO DEFINE IN YOUR FILE THE FOLLOWING
	* MACRO VARIABLES:
	* @ISCO
	* @EGP10
	* @SEMPL
	* @SUPVIS

	comment        **************** iscoegp*******************************
	               last revision March 12 1993
	               ********************************************************
	               You have to define for each occupation:
	               isco: four digit International Standard Classification
	               sempl: (2) self employed
	               supvis: (>10) large (1-10) small supervisor
	               *******************************************************
	               manual workers who are self-employed and have more than
	               10 subordinates now end up in EGP 1
	               **************** changes *******************************
	               MARCH 3 1991: 1960=1 (GENERIC PROFESSIONALS)
	               version august 20, 1988. Changes compared to recoding
	               scheme for dutch mobility data:
	               * self-employed farmers (ivc) will be scored as (11)
	               * tracers (321) to 3 (from 9)
	               * primary principal (1391) to 2 (from 1)
	               * general managers (2110) to 2 (from 1)
	               * expeditors/dispatchers (3590) to 3 (from 7)
	               * conductors (3600-3601) in 3 (from 2)
	               * sales engineers (4200-4222) to 2 (from 3)
	               * other salesmen (4510-4514) to 3 (from 9)
	               * market/street vendor (4520-4521) to 5 (from 9)
	               * watchman (5890) to 9 (from 7)
	               * prison guard (5891) to 9 (from 7)
	               * entertainment attendant (5991) to 3 (from 9)
	               * fishermen (6400-6490) to 10/11 (from 9)
	               * miller (7710) into 9 (from 8)
	               * woodmachine operators (8120) into 9 (from 8)
	               * shoe and leather workers (8020-8030) into 9 (from 8)
	               * dental mechanic (8422) electricians (8540-8550)
	                 telephone installers (8560-8590) broadcast oprt (8610)
	                 to 8 (from 7)
	               * ceramic kilnmen (8930) and ceramic wrke nec (8990)
	                 into 9 (from 8)
	               * carpenters helper (9542) insulation wrkr (9560)
	                 glazier (9570) to 9 (from 8)
	               * crane-road mach oprtr (9730-9740) to 8 (from 9)
	               * unskilled foreman are not promoted to 7
	               * added revision for isco, that distinguishes between
	                 2-, 3-, and 4-digits (4-digit categories that end on 0,
	                 are moved to a code with 9 as last digit
	               * as a consequence, 5999 is now a "medical attendant",
	                 and "illegal lottery agent" is lost
	               ********************************************************
	*/

	quietly {
		gen `varlist'=.
		replace `varlist'=1 if (`isco' >= 100 & `isco' <= 139)
		replace `varlist'=2 if (`isco' == 140 | `isco' == 149)
		replace `varlist'=1 if (`isco' >= 200 & `isco' <= 299)
		replace `varlist'=2 if (`isco' == 300 | `isco' == 320 | `isco' == 329)
		replace `varlist'=2 if (`isco' == 310)
		replace `varlist'=3 if (`isco' == 321)
		replace `varlist'=2 if (`isco' >= 330 & `isco' <= 390)
		replace `varlist'=1 if ((`isco' >= 400 & `isco' <= 420) | `isco' == 429)
		replace `varlist'=2 if (`isco' == 421)
		replace `varlist'=1 if (`isco' == 430)
		replace `varlist'=1 if (`isco' == 500 | (`isco' >= 510 & `isco' <= 539))
		replace `varlist'=2 if (`isco' >= 540 & `isco' <= 549)
		replace `varlist'=1 if (`isco' >= 600 & `isco' <= 619)
		replace `varlist'=2 if (`isco' == 620)
		replace `varlist'=1 if (`isco' == 630)
		replace `varlist'=2 if (`isco' == 640)
		replace `varlist'=1 if (`isco' == 650)
		replace `varlist'=2 if (`isco' == 660)
		replace `varlist'=1 if (`isco' == 670)
		replace `varlist'=2 if (`isco' == 680 | `isco' == 690)
		replace `varlist'=2 if (`isco' == 700)
		replace `varlist'=2 if (`isco' >= 710 & `isco' <= 719)
		replace `varlist'=3 if (`isco' == 720)
		replace `varlist'=2 if ((`isco' >= 721 & `isco' <= 761) | `isco' == 769)
		replace `varlist'=8 if (`isco' == 762)
		replace `varlist'=2 if (`isco' >= 770 & `isco' <= 799)
		replace `varlist'=1 if (`isco' >= 800 & `isco' <= 820)
		replace `varlist'=2 if (`isco' == 830)
		replace `varlist'=2 if (`isco' == 840 | `isco' == 849)
		replace `varlist'=1 if ((`isco' >= 900 & `isco' <= 1290) | `isco' == 1299)
		replace `varlist'=2 if (`isco' == 1291)
		replace `varlist'=1 if (`isco' >= 1310 & `isco' <= 1319)
		replace `varlist'=2 if (`isco' == 1300 | (`isco' >= 1320 & `isco' <= 1389))
		replace `varlist'=2 if (`isco' == 1390 | `isco' == 1399)
		replace `varlist'=2 if (`isco' == 1391)
		replace `varlist'=3 if (`isco' == 1393)
		replace `varlist'=1 if (`isco' == 1392 | `isco' == 1394)
		replace `varlist'=2 if (`isco' == 1400 | `isco' == 1410 | (`isco' >= 1412 & `isco' <= 1490) | `isco' == 1499)
		replace `varlist'=1 if (`isco' == 1411)
		 replace `varlist'=0 if (`isco' == 1491)
		replace `varlist'=2 if (`isco' >= 1500 & `isco' <= 1739)
		replace `varlist'=1 if (`isco' == 1740)
		replace `varlist'=2 if (`isco' >= 1741 & `isco' <= 1809)
		replace `varlist'=1 if (`isco' == 1900)
		replace `varlist'=2 if (`isco' == 1910)
		replace `varlist'=1 if (`isco' >= 1920 & `isco' <= 1929)
		replace `varlist'=2 if ((`isco' >= 1930 & `isco' <= 1950) | `isco' == 1959)
		replace `varlist'=1 if (`isco' == 1960)
		replace `varlist'=1 if (`isco' == 1951)
		replace `varlist'=2 if (`isco' >= 1990 & `isco' <= 1999)
		replace `varlist'=1 if (`isco' >= 2000 & `isco' <= 2039)
		replace `varlist'=2 if (`isco' >= 2100 & `isco' <= 2110)
		replace `varlist'=1 if (`isco' == 2119)
		replace `varlist'=2 if (`isco' == 2112 | `isco' == 2113)
		replace `varlist'=1 if (`isco' == 2114 | `isco' == 2115)
		replace `varlist'=2 if (`isco' == 2190 | `isco' == 2191 | `isco' == 2196 | `isco' == 2199)
		replace `varlist'=2 if (`isco' == 2116 | `isco' == 2120)
		replace `varlist'=1 if (`isco' == 2111)
		replace `varlist'=1 if ((`isco' >= 2192 & `isco' <= 2195) | `isco' == 2197)
		replace `varlist'=2 if (`isco' >= 2200 & `isco' <= 3109)
		replace `varlist'=3 if (`isco' >= 3200 & `isco' <= 3420)
		replace `varlist'=3 if (`isco' == 3590)
		replace `varlist'=2 if (`isco' == 3500 | `isco' == 3510 | `isco' == 3520)
		replace `varlist'=3 if (`isco' >= 3600 & `isco' <= 3609)
		replace `varlist'=9 if (`isco' >= 3700 & `isco' <= 3709)
		replace `varlist'=3 if (`isco' >= 3800 & `isco' <= 3999)
		replace `varlist'=2 if (`isco' >= 4000 & `isco' <= 4009)
		replace `varlist'=4 if (`isco' == 4101 | `isco' == 4103 | `isco' == 4104 | `isco' == 4106 | `isco' == 4108)
		replace `varlist'=5 if (`isco' == 4100 | `isco' == 4102 | `isco' == 4105 | `isco' == 4109)
		 replace `varlist'=0 if (`isco' == 4107)
		replace `varlist'=2 if (`isco' == 4200 | `isco' == 4210)
		replace `varlist'=2 if (`isco' >= 4220 & `isco' <= 4229)
		replace `varlist'=2 if ((`isco' >= 4300 & `isco' <= 4310) | `isco' == 4319)
		replace `varlist'=3 if (`isco' == 4311 | `isco' == 4320)
		replace `varlist'=2 if (`isco' >= 4400 & `isco' <= 4439)
		replace `varlist'=3 if ((`isco' >= 4500 & `isco' <= 4511) | `isco' ==  4519)
		replace `varlist'=9 if (`isco' == 4512)
		replace `varlist'=3 if (`isco' == 4513 | `isco' == 4514)
		replace `varlist'=5 if (`isco' == 4520 | `isco' == 4521 | `isco' == 4529)
		replace `varlist'=3 if (`isco' == 4522 | `isco' == 4523)
		replace `varlist'=9 if (`isco' == 4524)
		 replace `varlist'=0 if (`isco' == 4525)
		replace `varlist'=3 if (`isco' == 4900)
		replace `varlist'=2 if (`isco' >= 5000 & `isco' <= 5009)
		replace `varlist'=4 if (`isco' >= 5100 & `isco' <= 5109)
		replace `varlist'=3 if (`isco' >= 5200 & `isco' <= 5209)
		replace `varlist'=8 if ((`isco' >= 5300 & `isco' <= 5311) | `isco' ==  5319)
		replace `varlist'=9 if (`isco' == 5312)
		replace `varlist'=3 if (`isco' >= 5320 & `isco' <= 5329)
		replace `varlist'=9 if (`isco' >= 5400 & `isco' <= 5600)
		replace `varlist'=8 if (`isco' >= 5700 & `isco' <= 5709)
		replace `varlist'=8 if (`isco' == 5800 | `isco' == 5810)
		replace `varlist'=2 if (`isco' == 5820 | `isco' == 5829)
		replace `varlist'=1 if (`isco' == 5822)
		replace `varlist'=2 if (`isco' == 5821 | `isco' == 5823)
		replace `varlist'=9 if (`isco' >= 5890 & `isco' <= 5899)
		replace `varlist'=3 if (`isco' >= 5900 & `isco' <= 5920)
		replace `varlist'=9 if (`isco' == 5990 | `isco' == 5999)
		replace `varlist'=3 if (`isco' == 5991)
		replace `varlist'=9 if (`isco' >= 5992 & `isco' <= 5995)
		replace `varlist'=3 if (`isco' >= 5996 & `isco' <= 5998)
		replace `varlist'=11 if (`isco' >= 6000 & `isco' <= 6120)
		replace `varlist'=10 if (`isco' >= 6200 & `isco' <= 6329)
		replace `varlist'=10 if (`isco' == 6400 | `isco' == 6410 | `isco' == 6419)
		replace `varlist'=11 if (`isco' == 6411)
		replace `varlist'=10 if (`isco' >= 6490 & `isco' <= 6499)
		replace `varlist'=7 if (`isco' == 7000 | `isco' == 7001 | `isco' == 7009)
		replace `varlist'=8 if (`isco' == 7100 | `isco' == 7110 | `isco' == 7111 | `isco' == 7113 | `isco' == 7119)
		replace `varlist'=9 if (`isco' == 7112 | `isco' == 7120)
		replace `varlist'=8 if (`isco' >= 7130 & `isco' <= 7280)
		replace `varlist'=9 if (`isco' == 7290)
		replace `varlist'=8 if (`isco' >= 7300 & `isco' <= 7329)
		replace `varlist'=9 if (`isco' >= 7330 & `isco' <= 7340)
		replace `varlist'=9 if (`isco' >= 7400 & `isco' <= 7520)
		replace `varlist'=8 if (`isco' >= 7530 & `isco' <= 7549)
		replace `varlist'=8 if (`isco' >= 7550 & `isco' <= 7560)
		replace `varlist'=9 if (`isco' >= 7570 & `isco' <= 7590)
		replace `varlist'=8 if (`isco' >= 7600 & `isco' <= 7699)
		replace `varlist'=9 if ((`isco' >= 7700 & `isco' <= 7710) | `isco' == 7719)
		replace `varlist'=4 if (`isco' == 7711)
		replace `varlist'=8 if (`isco' == 7720 | `isco' == 7730 | `isco' == 7739)
		replace `varlist'=9 if (`isco' == 7731)
		replace `varlist'=8 if (`isco' == 7732)
		replace `varlist'=9 if (`isco' == 7740 | `isco' == 7750)
		replace `varlist'=8 if (`isco' >= 7760 & `isco' <= 7780)
		replace `varlist'=9 if (`isco' >= 7790 & `isco' <= 7890)
		replace `varlist'=8 if (`isco' >= 7900 & `isco' <= 7940)
		replace `varlist'=9 if (`isco' >= 7950 & `isco' <= 7970)
		replace `varlist'=8 if (`isco' == 7980)
		replace `varlist'=9 if (`isco' == 7990)
		replace `varlist'=8 if (`isco' >= 8000 & `isco' <= 8010)
		replace `varlist'=9 if (`isco' == 8020 | `isco' == 8030)
		replace `varlist'=8 if (`isco' == 8100 | `isco' == 8110)
		replace `varlist'=9 if (`isco' == 8120)
		replace `varlist'=8 if (`isco' >= 8190 & `isco' <= 8339)
		replace `varlist'=9 if (`isco' == 8340)
		replace `varlist'=8 if (`isco' >= 8350 & `isco' <= 8399)
		replace `varlist'=8 if ((`isco' >= 8400 & `isco' <= 8490) | `isco' == 8499)
		replace `varlist'=9 if (`isco' >= 8491 & `isco' <= 8494)
		replace `varlist'=8 if (`isco' == 8500 | `isco' == 8510 | `isco' == 8520)
		replace `varlist'=9 if (`isco' == 8530)
		replace `varlist'=8 if ((`isco' >= 8540 & `isco' <= 8550) | `isco' == 8559)
		replace `varlist'=4 if (`isco' == 8551)
		replace `varlist'=8 if (`isco' >= 8560 & `isco' <= 8610)
		replace `varlist'=3 if (`isco' == 8620)
		replace `varlist'=8 if (`isco' == 8700 | `isco' == 8710 | `isco' == 8719)
		replace `varlist'=4 if (`isco' == 8711)
		replace `varlist'=8 if (`isco' >= 8720 & `isco' <= 8920)
		replace `varlist'=9 if (`isco' >= 8930 & `isco' <= 8990)
		replace `varlist'=9 if (`isco' >= 9000 & `isco' <= 9100)
		replace `varlist'=8 if (`isco' >= 9200 & `isco' <= 9299)
		replace `varlist'=8 if (`isco' >= 9300 & `isco' <= 9319)
		replace `varlist'=9 if (`isco' == 9390)
		replace `varlist'=9 if (`isco' == 9400)
		replace `varlist'=8 if (`isco' == 9410)
		replace `varlist'=9 if (`isco' == 9430)
		replace `varlist'=9 if (`isco' == 9420)
		 replace `varlist'=8 if (`isco' == 9430)
		replace `varlist'=8 if ((`isco' >= 9490 & `isco' <= 9492) | `isco' == 9499)
		replace `varlist'=9 if (`isco' == 9493)
		replace `varlist'=8 if (`isco' >= 9500 & `isco' <= 9520)
		replace `varlist'=9 if (`isco' == 9530)
		replace `varlist'=8 if (`isco' == 9540 | `isco' == 9541 | `isco' == 9549)
		replace `varlist'=9 if (`isco' == 9542)
		replace `varlist'=8 if (`isco' == 9550 | `isco' == 9551 | `isco' == 9559)
		replace `varlist'=9 if (`isco' >= 9560 & `isco' <= 9570)
		replace `varlist'=8 if ((`isco' >= 9590 & `isco' <= 9593) | `isco' == 9599)
		replace `varlist'=9 if (`isco' == 9594 | `isco' == 9595)
		replace `varlist'=8 if (`isco' == 9596)
		replace `varlist'=9 if (`isco' >= 9600 & `isco' <= 9699)
		replace `varlist'=9 if (`isco' >= 9700 & `isco' <= 9719)
		replace `varlist'=8 if (`isco' == 9720)
		replace `varlist'=8 if (`isco' == 9730 | `isco' == 9739)
		replace `varlist'=9 if (`isco' == 9731)
		replace `varlist'=8 if (`isco' == 9740)
		replace `varlist'=9 if (`isco' == 9790)
		replace `varlist'=9 if (`isco' >= 9800 & `isco' <= 9820)
		replace `varlist'=9 if (`isco' == 9830)
		replace `varlist'=8 if (`isco' == 9839)
		replace `varlist'=9 if ((`isco' >= 9831 & `isco' <= 9854) & `isco' ~= 9839)
		replace `varlist'=3 if (`isco' == 9855)
		replace `varlist'=9 if (`isco' == 9859)
		replace `varlist'=9 if (`isco' >= 9860 & `isco' <= 9900)
		replace `varlist'=8 if (`isco' == 9950 | `isco' == 9959)
		replace `varlist'=5 if (`isco' == 9951)
		replace `varlist'=9 if (`isco' >= 9970 & `isco' <= 9999)
		replace `varlist'=7 if (`isco' == 10000)
		replace `varlist'=1 if (`isco' == 10001)
		replace `varlist'=7 if (`isco' == 10002)
		replace `varlist'=8 if (`isco' == 10003)
		replace `varlist'=7 if (`isco' == 5830)
		replace `varlist'=1 if (`isco' == 5831)
		replace `varlist'=7 if (`isco' == 5832)
		replace `varlist'=8 if (`isco' == 5833)
	}

	*** ascertain self-employment on basis of isco title ***

	tempvar semp
	gen `semp'=`sempl'
	quietly {
		replace `semp'=1 if (`isco' >= 4100 & `isco' <= 4108)
		replace `semp'=1 if (`isco' >= 6100 & `isco' <= 6112)
		replace `semp'=1 if (`isco' == 6120)
		replace `semp'=1 if (`isco' == 8551 | `isco' == 8711)
		replace `semp'=1 if (`isco' == 4520 | `isco' == 4521)
		replace `semp'=1 if (`isco' == 9951)
	}

	*** jobtitles are sorted into iva or ivb in advance ***
	tempvar x
	quietly gen `x'=.
	#delimit ;
	quietly replace `x'=4 if (`isco' ==  421 |
	                          `isco' == 3000 |
	                         (`isco' >= 4000 & `isco' <= 4002) |
	                          `isco' == 4101 |
	                          `isco' == 4106 |
	                          `isco' == 4210 |
	                          `isco' == 5000 |
	                          `isco' == 5001 |
	                          `isco' == 5002 |
	                          `isco' == 5100 |
	                          `isco' == 5101 |
	                          `isco' == 5103 |
	                          `isco' == 7730 |
	                          `isco' == 7760 |
	                          `isco' == 9596 |
	                          `isco' == 5103 |
	                          `isco' == 5920);
	quietly replace `x'=5 if (`isco' == 1630 |
	                          `isco' == 1631 |
	                         (`isco' >= 3300 & `isco' <= 3391) |
	                          `isco' == 3310 |
	                          `isco' == 3520 |
	                          `isco' == 3700 |
	                          `isco' == 4104 |
	                         (`isco' >= 4300 & `isco' <= 4320) |
	                          `isco' == 4400 |
	                         (`isco' >= 4420 & `isco' <= 4900) |
	                         (`isco' >= 5300 & `isco' <= 5999));
	#delimit cr
	quietly replace `varlist'=`x' if ((`x' == 4 | `x' == 5) & `semp' == 1)


	* #P CODES PROMOTABILITY OF CERTAIN OCCUPATIONS

	tempvar p
	quietly gen `p'=.
	#delimit ;
	quietly replace `p'=1 if ((`isco' >= 410 & `isco' <= 430) |
	                           `isco' ==  711 |
	                           `isco' ==  793 |
	                           `isco' == 1391 |
	                           `isco' == 1394 |
	                           `isco' == 1591 |
	                          (`isco' >= 2010 & `isco' <= 2197) |
	                           `isco' == 3000 |
	                          (`isco' >= 3100 & `isco' <= 3104) |
	                           `isco' == 3312 |
	                          (`isco' >= 3500 & `isco' <= 3590) |
	                          (`isco' >= 4000 & `isco' <= 4220) |
	                          (`isco' >= 4410 & `isco' <= 4412) |
	                          (`isco' >= 5000 & `isco' <= 5201) |
	                          (`isco' >= 5821 & `isco' <= 5823));

	quietly replace `varlist'=4  if ((`varlist' >= 7 & `varlist' <= 9) &
	                                  `semp' == 1  &
	                                  `supvis' >= 1  &  `supvis' ~= .);
	quietly replace `varlist'=5  if ((`varlist' >= 7 & `varlist' <= 9) &
	                                  `semp' == 1  &
	                                  `supvis' <= 0);
	quietly replace `varlist'=7  if ((`varlist' == 8) & (`supvis' >= 10) & (`supvis' ~= .));
	quietly replace `varlist'=11 if ((`varlist' == 10) & (`semp' == 1));
	quietly replace `varlist'=5  if ((`varlist' == 4) & (`supvis' == 0));
	quietly replace `varlist'=4  if ((`varlist' == 5) & (`supvis' >= 1) & (`supvis' ~= .));
	quietly replace `p'=1        if  (`varlist' == 4 | `varlist' == 5);
	quietly replace `varlist'=1  if ((`varlist' == 2 | `varlist' == 3 | `varlist' == 4) &
	                                 (`supvis' >= 10) & (`supvis' ~= .) &
	                                 (`p' == 1));
	quietly replace `varlist'=2  if ((`varlist' == 3) &
	                                 (`supvis' >= 1 & `supvis' < 10) &
	                                 (`p' == 1));

	capture label define egp10
	  1 "higher controllers"
	  2 "lo controllers"
	  3 "routine nonmanual"
	  4 "sempl with emp"
	  5 "sempl without empl"
	  7 "manual supervisor"
	  8 "skilled manual"
	  9 "semi-unskilld manual"
	 10 "farm labor"
	 11 "selfempl farm";
	#delimit cr
	label values `varlist' egp10
end