clear all * beginning prog apcg program define apcg , rclass version 11.0 syntax varlist(numeric ts) [fw aw pw iw] [if] [in], /// [age(varname numeric) period(varname numeric) gap(varname numeric) /// save(varname numeric) offset(varname numeric) exposure(varname numeric) *] marksample touse markout `touse' `age' `period' `gap' `save' `offset' `exposure' tempname bic0 bic1 bicd bicd0 bicd1 dbic_cohort dbic_hyster CC HH aar ccr ppr tempvar agag pepe aaa iap ccc coco end ppp y tempa tempy coeffcoh hystecoh hyst1 w2 alpha omega ga1 ga2 ga3 ga4 ga5 ga6 ga7 ga8 ga9 gen alpha=. qui tab `gap', gen(ga) local gapm=r(r) * apcg version 1.1 / Oct 6 2012 * this ado file quotes fractions of the Yang & colleagues apc_ie.ado (ssc install apc) di "" di "" di "" di "" di "" di "" di "" di "" di "" di "" di "*********************" di "* apcg version 1.1 *" di "*********************" di "" local expb = subinstr("`exp'","=","",.) local expc : word count `expb' if (`expc'==0) { quietly: gen `w2'= 1 } else { quietly: gen `w2'= `expb' } local lc : word count `varlist' forvalues i = 1(1)`lc' { local nomy`i' : word `i' of `varlist' } local control "" forvalues i = 2/`lc' { local toto `nomy`i'' local control "`control' `toto'" } *quietly: gen `y' = `nomy1' if `touse' quietly: gen `aaa' = `age' if `touse' quietly: gen `ppp' = `period' if `touse' quietly: tostring `aaa' `ppp' , generate(`tempa' `tempy') quietly: encode `tempa' if `touse', gen(`agag') quietly: encode `tempy' if `touse', gen(`pepe') *drop `temp*' quietly: su `agag' local maag=int(r(max)) quietly: su `pepe' local mape=int(r(max)) quietly: gen `ccc' = `period' -`age' if `touse' quietly: su `ccc' if `touse' quietly: gen `coco' = `pepe'-`agag'+`maag' quietly: su `coco' local maco=int(r(max)) *tab `aaa' `ppp', su(`ccc') nofreq nost w quietly: su `agag' [fw=`w2'] quietly: gen rescaage =2*(`agag'-r(min))/(r(max)-r(min))-1 quietly: gen rescaper =(`pepe')/(r(max)-r(min)) quietly: gen rescacoh =(`coco')/(r(max)-r(min)) quietly: su rescaper [fw=`w2'] quietly: replace rescaper =rescaper-(r(max)+r(min))/2 quietly: su rescacoh [fw=`w2'] quietly: replace rescacoh =rescacoh -(r(max)+r(min))/2 quietly: replace rescaage =rescaage +runiform()*.001-.0005 quietly: replace rescacoh =rescacoh +runiform()*.001-.0005 quietly: replace rescaper =rescaper +runiform()*.001-.0005 quietly tab `aaa' if `touse', matrow(`aar') quietly tab `ppp' if `touse', matrow(`ppr') quietly tab `ccc' if `touse', matrow(`ccr') local pace `aar'[2,1]-`aar'[1,1] local macob=int(`maco'-1) forvalues i = 2(1)`macob' { tempvar cc`i' quietly: gen `cc`i''= (`i'==`coco' )+runiform()*.001-.0005 if `touse' local ccrr=`ccr'[`i',1] quietly: gen coh_`ccrr'= `cc`i'' if `touse' forvalues h = 1(1)`gapm' { quietly: gen gc`h'_`ccrr'= coh_`ccrr'*ga`h' if `touse' } } forvalues i = 1(1)`maag' { tempvar aa`i' quietly: gen `aa`i''= (`i'==`agag')+runiform()*.001-.0005 local aarr=`aar'[`i',1] quietly: gen age_00`aarr'= `aa`i'' if `touse' forvalues h = 1(1)`gapm' { quietly: gen ga`h'_00`aarr'= age_00`aarr'*ga`h' if `touse' } } forvalues i = 1(1)`mape' { tempvar pp`i' quietly: gen `pp`i''= (`i'==`pepe')+runiform()*.001-.0005 local pprr=`ppr'[`i',1] quietly: gen per_`pprr'= `pp`i'' if `touse' forvalues h = 1(1)`gapm' { quietly: gen gp`h'_`pprr'= per_`pprr'*ga`h' if `touse' } } local consg1 "0" local consg2 "0" local listcoh "" forvalues i=2(1)`macob' { local j=int(-`maco'-1+`i'*2) local k=`ccr'[`i',1] local consg1 "`consg1'+coh_`k'" local consg2 "`consg2'+(`j')*coh_`k'" local listcoh "`listcoh' coh_`k'" } local consg1 "`consg1'=0" local consg2 "`consg2'=0" local listga "" local listgc "" local gapmb=int(`gapm'-1) forvalues h = 1(1)`gapmb' { * local listgap "`listgap' ga`h'_00* gp`h'_* gc`h'_*" local listga "`listga' ga`h'_00*" local listgc "`listgc' gc`h'_*" } local consg3 "0" local consg4 "0" forvalues i=1(1)`maag' { local j=int(-`maag'-1+`i'*2) local k=`aar'[`i',1] local consg3 "`consg3'+age_00`k'" local consg4 "`consg4'+(`j')*age_00`k'" } local consg3 "`consg3'=0" local consg4 "`consg4'=0" forvalues h = 1(1)`gapm' { local consg1`h' "0" local consg2`h' "0" } forvalues i=1(1)`maag' { local j=int(-`maag'-1+`i'*2) local k=`aar'[`i',1] forvalues h = 1(1)`gapm' { local consg1`h' "`consg1`h''+ga`h'_00`k'" local consg2`h' "`consg2`h''+(`j')*ga`h'_00`k'" } } forvalues h = 1(1)`gapm' { local consg1`h' "`consg1`h''=0" local consg2`h' "`consg2`h''=0" } local consg5 "0" local consg6 "0" forvalues i=1(1)`mape' { local j=int(-`mape'-1+`i'*2) local k=`ppr'[`i',1] local consg5 "`consg5'+per_`k'" local consg6 "`consg6'+(`j')*per_`k'" } local consg5 "`consg5'=0" local consg6 "`consg6'=0" local cogali "11" forvalues h = 2(1)`gapmb' { local cogali "`cogali' 1`h'" } local cogasl "21" forvalues h = 2(1)`gapmb' { local cogasl "`cogasl' 2`h'" } quietly: compress constraint 1 `consg1' constraint 2 `consg2' constraint 3 `consg3' constraint 4 `consg4' constraint 5 `consg5' constraint 6 `consg6' forvalues h = 1(1)`gapm' { constraint 1`h' `consg1`h'' constraint 2`h' `consg2`h'' } *constraint 8 `consg8' /* di "" di "" di "*******************************************" di "####### AP model #######" di "*******************************************" di "" glm `nomy1' age_00* per_* rescacoh rescaage `control' `in' [`weight' `exp'] if `coco'!=1 & `coco'<`maco' & `touse', /// `options' constraints ( 3 4 5 6 ) scalar `bic0'=e(bic) est store mcoho0 */ di "" di "" di "*******************************************" di "####### APC Gap #######" di "*******************************************" di "" gen omega=. glm `nomy1' `listcoh' `listgc' `listga' age_00* per_* rescacoh rescaage `control' `in' [`weight' `exp'] if `coco'!=1 & `coco'<`maco' & `touse', /// `options' constraints (1 2 3 4 5 6 `cogali' `cogasl' ) predict predictedapcd, xb predict residuedevapcd, deviance scalar `bic1'=e(bic) drop alpha-omega /* return local bicap = `bic0' return local bicapcd = `bic1' return local deltabic= `bic1'-`bic0' di "" di "" di "*******************************************" di "Delta Bic = " `bic1'-`bic0' di "*******************************************" di "" */ end *end program apcg * beginning prog apct program define apct, rclass version 11.0 *version june 2016 syntax varlist(numeric ts) [fw aw pw iw] [if] [in], /// [age(varname numeric) period(varname numeric) /// offset(varname numeric) exposure(varname numeric) *] marksample touse markout `touse' `age' `period' `offset' `exposure' tempname bic0 bic1 bicd bicd0 bicd1 dbic_cohort dbic_hyster CC HH aar ccr ppr tempvar agag pepe aaa ccc coco end ppp y tempa tempy coeffcoh hystecoh hyst1 w2 alpha omega gen alpha=. * based on apcd version 1.1 (April 5 2012) * this ado file quotes fractions of the Yang & colleagues apc_ie.ado (ssc install apc) di "" di "" di "" di "" di "" di "" di "" di "" di "" di "" di "*********************" di "* apct version 1.1 *" di "*********************" di "" local expb = subinstr("`exp'","=","",.) local expc : word count `expb' if (`expc'==0) { quietly: gen `w2'= 1 } else { quietly: gen `w2'= `expb' } local lc : word count `varlist' forvalues i = 1(1)`lc' { local nomy`i' : word `i' of `varlist' } local control "" forvalues i = 2/`lc' { local toto `nomy`i'' local control "`control' `toto'" } *quietly: gen `y' = `nomy1' if `touse' quietly: gen `aaa' = `age' if `touse' quietly: gen `ppp' = `period' if `touse' quietly: tostring `aaa' `ppp' , generate(`tempa' `tempy') quietly: encode `tempa' if `touse', gen(`agag') quietly: encode `tempy' if `touse', gen(`pepe') *drop `temp*' quietly: su `agag' local maag=int(r(max)) quietly: su `pepe' local mape=int(r(max)) quietly: gen `ccc' = `period' -`age' if `touse' quietly: su `ccc' if `touse' quietly: gen `coco' = `pepe'-`agag'+`maag' quietly: su `coco' local maco=int(r(max)) *tab `aaa' `ppp', su(`ccc') nofreq nost w quietly: su `agag' [fw=`w2'] quietly: gen rescaage =2*(`agag'-r(min))/(r(max)-r(min))-1 quietly: gen rescaper =(`pepe')/(r(max)-r(min)) quietly: gen rescacoh =(`coco')/(r(max)-r(min)) quietly: su rescaper [fw=`w2'] quietly: replace rescaper =rescaper-(r(max)+r(min))/2 quietly: su rescacoh [fw=`w2'] quietly: replace rescacoh =rescacoh -(r(max)+r(min))/2 quietly: replace rescaage =rescaage +runiform()*.001-.0005 quietly: replace rescacoh =rescacoh +runiform()*.001-.0005 quietly: replace rescaper =rescaper +runiform()*.001-.0005 quietly tab `aaa' if `touse', matrow(`aar') quietly tab `ppp' if `touse', matrow(`ppr') quietly tab `ccc' if `touse', matrow(`ccr') local pace `aar'[2,1]-`aar'[1,1] forvalues i = 1(1)`maco' { tempvar cc`i' quietly: gen `cc`i''= (`i'==`coco' )+runiform()*.001-.0005 if `touse' local ccrr=`ccr'[`i',1] quietly: gen coh_`ccrr'= `cc`i'' if `touse' } forvalues i = 1(1)`maag' { tempvar aa`i' quietly: gen `aa`i''= (`i'==`agag')+runiform()*.001-.0005 local aarr=`aar'[`i',1] quietly: gen age_00`aarr'= `aa`i'' if `touse' } forvalues i = 1(1)`mape' { tempvar pp`i' quietly: gen `pp`i''= (`i'==`pepe')+runiform()*.001-.0005 local pprr=`ppr'[`i',1] quietly: gen per_`pprr'= `pp`i'' if `touse' } local consg1 "0" local consg2 "0" local listcoh "" local macob=int(`maco'-1) forvalues i=2(1)`macob' { local j=int(-`maco'-1+`i'*2) local k=`ccr'[`i',1] local consg1 "`consg1'+coh_`k'" local consg2 "`consg2'+(`j')*coh_`k'" local listcoh "`listcoh' coh_`k'" } local consg1 "`consg1'=0" local consg2 "`consg2'=0" local consg3 "0" local consg4 "0" forvalues i=1(1)`maag' { local j=int(-`maag'-1+`i'*2) local k=`aar'[`i',1] local consg3 "`consg3'+age_00`k'" local consg4 "`consg4'+(`j')*age_00`k'" } local consg3 "`consg3'=0" local consg4 "`consg4'=0" local consg5 "0" local consg6 "0" forvalues i=1(1)`mape' { local j=int(-`mape'-1+`i'*2) local k=`ppr'[`i',1] local consg5 "`consg5'+per_`k'" local consg6 "`consg6'+(`j')*per_`k'" } local consg5 "`consg5'=0" local consg6 "`consg6'=0" quietly: compress constraint 1 `consg1' constraint 2 `consg2' constraint 3 `consg3' constraint 4 `consg4' constraint 5 `consg5' constraint 6 `consg6' di "" di "" di "*******************************************" di "####### AP model #######" di "*******************************************" di "" /* glm `nomy1' age_00* per_* rescacoh rescaage `control' `in' [`weight' `exp'] if `coco'!=1 & `coco'<`maco' & `touse', /// `options' constraints ( 3 4 5 6 ) scalar `bic0'=e(bic) est store mcoho0 */ di "" di "" di "**************************************************" di "####### APCT = APC with cohort Trend########" di "**************************************************" di "" glm `nomy1' `listcoh' age_00* per_* `control' `in' [`weight' `exp'] if `coco'!=1 & `coco'<`maco' & `touse', /// `options' constraints (1 4 3 5 6) predict predictedapcd, xb predict residuedevapcd, deviance scalar `bic1'=e(bic) gen omega=. drop alpha-omega * return local bicap = `bic0' * return local bicapcd = `bic1' * return local deltabic= `bic1'-`bic0' di "" di "" di "*******************************************" *di "Delta Bic = " `bic1'-`bic0' di "*******************************************" di "" end *end program apct use "C:\tmp\ipumsi_00079.dta", clear *extract ipumsi French census for book keep if 250011<=geo *metropolitan France only *interger weight replace perw=int(perw) * recode education gen ed1=int(educfr/10) recode ed1 (0=1) * recode socioeconomic status -- professions et categories socio-professionnelles * based on the INSEE-SAPHIR harmonised 2 digits recode of 1962 to todays gen socc=fr1962a_soccup if fr1962a_soccup!=. replace socc=fr1968a_socc if fr1968a_socc!=. replace socc=fr1975a_socc if fr1975a_socc!=. replace socc=fr1982a_socc if fr1982a_socc!=. replace socc=fr1990a_socc if fr1990a_socc!=. replace socc=fr1999a_occty if fr1999a_occty !=. replace socc=fr2006a_socio42 if fr2006a_socio42 !=. replace socc=fr2011a_occ if fr2011a_occ !=. * we retain the first of the two digits... * 1=farmers 2=self employed 3=managers experts and professionals 4=intermediate occupations : associate managers experts and professionals * 5=routine white collars 6=blue collar workers 7=no category (never worked) replace socc=int(socc/10) *dichotomic variable cho = 0/1 = "is unemployed" gen cho = (int( empstatd /100)==2) *dichotomic variable tcho = * 0 = "is employed" * 1 = "is unemployed" * missing values for those outside the labor force gen tcho = cho replace tcho =. if (int( empstatd /100)>2) *table for G2_5 ta socc ye if socc<7 & socc>2 & age>=30 & age<=54 [w=perw], s(tcho) nofr nost w noobs *the same with no age selection gives much more pessimistic results... ta socc ye if socc<7 & socc>2 [w=perw], s(tcho) nofr nost w noobs recode socc (7 8 9 = .) *table for G2_6 ta socc ye if socc<7 [w=perw], nofr col *is professional or associate professional (0/1) gen moysup=socc == 3 | socc == 4 if socc<7 *is associate professional (0/1) gen moym=socc == 4 if socc<7 *is full professional (0/1) gen sup=socc == 3 if socc<7 *table for G2_7 ta ed1 ye if age>=25 & age<=35 [fw=perw], s(moysup) nofr nost w noobs keep if age>=25 & age<=54 & ed1 <=5 gen perw1982=perwt*(year==1982)+1 logit moys i.ed1 if socc<=6 & socc>=3 [fw=perw1982], iterate(15) predict predlomoys, p logit sup i.ed1 if socc<=6 & socc>=3 [fw=perw1982], iterate(15) predict predlosup, p *table for G2_8 tabstat moys predlomoys sup predlosup if socc<=6 & socc>=3 [fw=perwt] , by(year) stat(mean ) gen a5=int((age-25)/5)*5+25 gen y5=int((year+int(runiform()*10-5))/5)*5 replace y5=2010 if y5>=2010 replace y5=1965 if y5<=1965 gen c5=y5-a5 replace c5=int(c5/5)*5 gen bacplus=ed1==4 | ed1==5 gen edsup=ed1==5 *ta a5 y5 [fw=perwt] if sex==1 & y5>=1965 , s(sup) nofr nost w noobs gen score=. replace score= -0.902 if socc== 1 replace score= -0.215 if socc== 2 replace score= 2.738 if socc== 3 replace score= 1.39 if socc== 4 replace score= -0.062 if socc== 5 replace score= -0.737 if socc== 6 *replace score= -0.473 if socc== 7 gen ed2=7-ed1 replace ed2=1 if runiform()<=.1 *apcg score if a5<55 & a5>=25 & socc>=3 & 7>socc [pw=perwt] , age(a5) period(y5) gap(ed2) capt drop *apc* apct score if a5<55 & a5>=25 & (ed1==5) [pw=perwt] , age(a5) period(y5) eststo ed1_5 capt drop *apc* apct score if a5<55 & a5>=25 & (ed1==4) [pw=perwt] , age(a5) period(y5) eststo ed1_4 capt drop *apc* apct score if a5<55 & a5>=25 & (ed1==3) [pw=perwt] , age(a5) period(y5) eststo ed1_3 capt drop *apc* apct score if a5<55 & a5>=25 & (ed1==2) [pw=perwt] , age(a5) period(y5) eststo ed1_2 capt drop *apc* apct score if a5<55 & a5>=25 & (ed1==1) [pw=perwt] , age(a5) period(y5) eststo ed1_1 capt drop *apc* *table for G3_3 esttab ed*, label nodepvar nonumber nose not nostar