clear all set varabbrev on di "$S_DATE $S_TIME" use $mydata/workshop2023/uslisready , replace keep if a5<=80 keep if a5>=25 su * *cohorts c5 gen c5=y5-a5 *tricks to determine max and mn cohort su a5 y5 c5 gen tmpconame=string(c5) noi ta tmpconame encode tmpconame , gen(tmpconum) noi su tmpconum local cmax=r(max) local cmin=r(min) noi di `cmin' " " `cmax' *ceduc : years of education, centered su edyrs gen ceduc=edyrs-r(mean) *generate genderratio var gen genderratio=sex==2 /* *fracrank of personnal income by age-period capt drop tmp recode pippp (min/0=0) (.=0) gen frpi=. forvalues a=25(5)80 { forvalues y=1975(5)2020 { fracrank pippp [w=ppop] if `a'==a5 & `y'==y5 , gen(tmp) replace frpi =tmp if `a'==a5 & `y'==y5 drop tmp } } gen lgtpi=logit(frpi) gen X=round(lgtpi,.5) ta a5 y5 [w=ppop] if X>=2 , s(gend) nofr nost noobs */ *the main commands apcd/apctlag *xi: apcd ledhi i.educ [pw=ppop] , age(a5) period(y5) capt drop *apc* *apctlag ledhi ceduc [pw=ppop] , age(a5) period(y5) *xi: apcd ledhi ceduc [pw=ppop] , age(a5) period(y5) capt drop *apc* *apctlag ledhi ceduc [pw=ppop] , age(a5) period(y5) *apctlag BA [pw=ppop] if sex==1, age(a5) period(y5) *apctlag BA [pw=ppop] if sex==2, age(a5) period(y5) *apctlag educ [pw=ppop] , age(a5) period(y5) *apctlag gend [pw=ppop] if BA==1, age(a5) period(y5) apctlag BA [pw=ppop] , age(a5) period(y5) eret li capt drop *apc* *retrieve the matrix coefficients for graphics * many tricks ahead... mat a=e(b) mat A=a' mat li A mat V=e(V) gen estim=. gen esse=. local dmax= `cmax'-2 forvalues j=1/`dmax' { local k= `j'+`cmin' replace estim = A[`j',1] if tmpconum==`k' replace esse = sqrt(V[`j',`j']) if tmpconum==`k' } capt drop tmp* collapse estim esse [w=ppop] , by(c5 ) keep if est!=. gen sup=est+2*esse gen inf=est-2*esse tabstat est sup inf , by(c5) twoway (line est c5) (line sup c5) (line inf c5), legend(off) graphexportpdf $mypdf/graphteststata2.pdf, replace di "$S_DATE $S_TIME"