clear all program define apct, rclass version 11.0 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=. * 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 5 6 ) scalar `bic0'=e(bic) est store mcoho0 di "" di "" di "**************************************************" di "####### APCT = APC with cohort Trend########" di "**************************************************" di "" gen omega=. glm `nomy1' `listcoh' age_00* per_* `control' `in' [`weight' `exp'] if `coco'!=1 & `coco'<`maco' & `touse', /// `options' constraints (1 3 5 6) 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 set linesize 100 gen d3=. foreach gogo in fr { noi { if "`gogo'"== "at" local fifi "at87 at94 at97 at00 at04" if "`gogo'"== "au" local fifi "au85 au89 au95 au01 au03" if "`gogo'"== "ca" local fifi "ca87 ca91 ca94 ca98 ca04" if "`gogo'"== "de" local fifi "de84 de89 de94 de00 de04 " if "`gogo'"== "dk" local fifi "dk87 dk92 dk95 dk00 dk04 " if "`gogo'"== "es" local fifi "es90 es95 es00 es04 " if "`gogo'"== "fi" local fifi "fi87 fi91 fi95 fi00 fi04 " if "`gogo'"== "fr" local fifi "fr78 fr84 fr89 fr94 fr00 fr05 fr10" if "`gogo'"== "hu" local fifi "hu91 hu94 hu99 hu05 " if "`gogo'"== "il" local fifi "il86 il92 il97 il01 il05 " if "`gogo'"== "it" local fifi " it86 it91 it95 it00 it04" if "`gogo'"== "lu" local fifi "lu85 lu91 lu94 lu00 lu04 " if "`gogo'"== "mx" local fifi "mx84 mx89 mx94 mx98 mx04" if "`gogo'"== "nl" local fifi "nl83 nl90 nl93 nl99 nl04 " if "`gogo'"== "no" local fifi "no86 no91 no95 no00 no04" if "`gogo'"== "pl" local fifi "pl86 pl92 pl95 pl99 pl04" if "`gogo'"== "se" local fifi " se87 se92 se95 se00 se05" if "`gogo'"== "tw" local fifi "tw86 tw91 tw95 tw00 tw05" if "`gogo'"== "uk" local fifi "uk86 uk91 uk94 uk99 uk04 " if "`gogo'"== "us" local fifi "us86 us91 us94 us00 us04 " *"us69 us74 us79 us86 us91 us94 us00 us04 us10" foreach toto in `fifi' { local perso "$`toto'p" local house "$`toto'h" qui use hid ppopwgt age sex relation educ immigr nchildren educ_c ethnic_c deflat partner occ* using `perso' , clear qui joinby hid using `house' keep hid ppopwgt age sex relation educ deflat year iso2 hpopwgt immigr ethnic_c dhi dpi hmi deflator nchildren educ_c npers partner region_c occ* local save "t`toto'" qui save `save' , replace } clear gen d3=. foreach toto in `fifi' { local save "t`toto'" qui append using `save' } replace reg =0 if "`gogo'" != "de" *replace "`gogo'" = "gb" if "`gogo'" == "uk" drop defl* *joinby iso2 year using http://www.louischauvel.org/deflatworld.dta *gen deflator=d *noi su defl *replace rate=1 if rate ==. *replace defl = defl/rate if year= 25 & age < 75 gen page=floor(age/5)*5 gen page5=floor(age/5) gen coco=year-page *keep if (page >= 25 & page <=70) gen year5=year replace year =int((year-1980)/5) gen educ2=int(educ) gen pwe2=int(pweight) recode nchil (4/max=3) } di "`gogo'" *qui keep if educ<4 *keep if reg <10 qui gen moy =. replace immigr=immigr==1 recode immigr (.=0) replace ethni=ethni!=1 replace ethni=0 if ethni==. replace immi =ethni if "`gogo'" =="us" replace region_c=0 if region_c==. gen altl=region_c<10 keep if region_c<9 | yearini!=2010 keep if alt==1 noi su ye* noi tab page year5 [w= pweight], s(dhie) nofreq nost w noobs recode occ1_c (48=60) gen occ0=int(occ1_c/10) recode occ0 (7 8 9 10 . =10) ta yearini /*replace dhie = dhie / 739 * 2403 / 6.58 if yearini==1978 replace dhie = dhie / 1389 * 2403 / 6.58 if yearini==1984 replace dhie = dhie / 1656 * 2403 / 6.58 if yearini==1989 replace dhie = dhie / 1876 * 2403 / 6.58 if yearini==1994 replace dhie = dhie / 2028 * 2403 / 6.58 if yearini==2000 replace dhie = dhie / 2230 * 2403 / 1 if yearini==2005 replace dhie = dhie / 2403 * 2403 / 1 if yearini==2010 */ *gen dhie2 = int(dhie) ************ *keep if relation==1000 *keep if occ0<7 gen mdhie=. forvalues i = 1980(5)2010 { su dhie [w= pweight] if year5==`i' replace mdhie =r(mean) if year5==`i' } replace dhie = dhie*0.711 /mdhie if yearini==1978 replace dhie = dhie* 0.704 /mdhie if yearini==1984 replace dhie = dhie* 0.760 /mdhie if yearini==1989 replace dhie = dhie* 0.80 /mdhie if yearini==1994 replace dhie = dhie* 0.891 /mdhie if yearini==2000 replace dhie = dhie* 0.95 /mdhie if yearini==2005 replace dhie = dhie * 1 /mdhie if yearini==2010 gen dhie2 = int(dhie * 100) noi tab year5 [w= pweight] , s(dhie2) nofreq nost w noobs noi tab occ0 year5 [w= pweight] , s(mdhie) nofreq nost w noobs noi di "XXXXXXXX" noi di "XXXXXXXX" noi di "TABLE INFRA!" noi di "POUR G2.3 G2.4!" noi di "XXXXXXXX" noi di "XXXXXXXX" noi tab occ0 year5 [w= pweight] , s(dhie2) nofreq nost w noobs noi tab educ year5 [w= pweight] , s(dhie2) nofreq nost w noobs gen ldhie2=ln(dhie2) noi tab page year5 [w= pweight] if year5<=2010 & year5>=1980 & page>=25 & page<65 , s(ldhie) nofreq nost w noobs noi tab occ0 year5 [w= pweight] , s(dhie2) nofreq nost w noobs noi tab occ0 year5 [w= pweight] , s(ldhie) nofreq nost w noobs xi: apct ldhie [pw= pweight] if year5<=2010 & year5>=1980 & page>=25 & page<65 , age(page) period(year5) drop res* pred* eststo m1`gogo' xi: apct ldhie i.educ i.sex i.nchil i.partn [pw= pweight] if year5<=2010 & year5>=1980 & page>=25 & page<65 , age(page) period(year5) drop res* pred* eststo m2`gogo' } esttab, compress nogaps not