#delim cr version 9.1 /* Examples for censlope. */ clear set memory 1m set scheme sj /* Examples from the auto data */ sysuse auto, clear /* Examples from the auto data. */ censlope weight length, tdist censlope weight length, tdist transf(z) censlope weight length, tdist transf(z) centile(25(25)75) censlope weight length, tdist transf(z) ystar(resid) egen intercept = median(resid) gene wthat = weight - resid + intercept label var wthat "Fitted weight" twoway scatter weight length || line wthat length, lpattern(solid) graph export figseq4.eps, replace more /* Create Figure 1 for pctlslope.pdf. */ tempfile diffs gene us=!foreign lab def us 0 "Non-US" 1 "US" lab val us us lab var us "US origin" censlope trunk foreign, tdist tr(z) cendif trunk, by(us) tdist saving(`diffs',replace) matr cimat=r(cimat) matr Dsmat=r(Dsmat) matr list cimat matr list Dsmat local yl1=Dsmat[1,3] local yl2=Dsmat[1,2] local yl3=Dsmat[1,4] local xl1=cimat[1,3] local xl2=cimat[1,2] local xl3=cimat[1,4] preserve use `diffs',clear gene double Dstar_l=1 replace Dstar_l=Dstar_r[_n-1] if(_n!=1) lab var Dstar_l "D-star to left of difference" expand 3 sort diff by diff:gene byte linseq=_n lab var linseq "Line point within difference" sort diff linseq gene double Dsline=Dstar replace Dsline=Dstar_l if(linseq==1) replace Dsline=Dstar_r if(linseq==3) lab var Dsline "Line for Dstar(theta)" replace Dstar=. if(linseq!=2) * Add points at beginning and end * local diffmin=-20 local diffmax=10 expand 2 if((_n==1)|(_n==_N)) sort diff linseq replace linseq=0 if(_n==1) replace diff=`diffmin' if(_n==1) replace Dsline=1 if (_n==1) replace linseq=4 if(_n==_N) replace diff=`diffmax' if(_n==_N) replace Dsline=-1 if (_n==_N) replace Dstar=. if((_n==1)|(_n==_N)) sort diff linseq desc /* z-transform Dstar variables and Y-axis lines */ foreach STUB in star sline { gene double Z`STUB' = D`STUB' replace Z`STUB' = 0.999999999999999 if Z`STUB' > 0.999999999999999 & !missing(Z`STUB') replace Z`STUB' = -0.999999999999999 if Z`STUB' < -0.999999999999999 & !missing(Z`STUB') replace Z`STUB' = 0.5 * log( (1+Z`STUB') / (1-Z`STUB') ) } foreach STUB in l1 l2 l3 { local z`STUB' = `y`STUB'' if `z`STUB'' > 0.999999999999999 & !missing(`z`STUB'') { local z`STUB' = 0.999999999999999 } if `z`STUB'' < -0.999999999999999 & !missing(`z`STUB'') { local z`STUB' = -0.999999999999999 } local z`STUB' = 0.5 * log( (1+`z`STUB'') / (1-`z`STUB'') ) } lab var Zstar "Zetastar(beta)" lab var Zsline "Line for Zetastar(beta)" desc summ diff Zstar Zsline, de twoway scatter Zstar diff , msym(square_hollow) || line Zsline diff, lpattern(solid) ||, /// xlabel(`diffmin'(5)`diffmax') /// yline(`zl1' `zl2' `zl3', lpattern(shortdash)) xline(`xl1' `xl2' `xl3', lpattern(shortdash)) /// ytitle("Zeta-star for difference (Fisher's z-transform)") /// xtitle("Difference in trunk space (cubic feet)") /// legend(off) graph export figseq1b.eps, replace more scal zetainf=Zsline[1] twoway scatter Zstar diff , msym(square_hollow) || line Zsline diff if abs(Zsline)