*! version 1.34 am 25Nov99 (STB-54: gr43) program define overlay version 6.0 syntax [varlist] [if], BY(string) [SAVING(string) FUNCtion(string) YLAB(numlist) XLAB(numlist) DEBUG ROUND(real 0.001) *] local gopt "`options'" tokenize "`varlist'" preserve if "`if'"~="" { keep `if' } if "`func'"~="" { di "Sometimes overlay.ado will fail to give you the correct graph" di "This is due to selecting a function that is not graph" di di " The user may have to select XLAB and YLAB options that do not change by group" di "See also the end Diagnostics" } *********************************************** * How many levels does the by variable have * and put them into the matrix mine *********************************************** tempvar bygrp if "`by'"~="" { sort `by' qui by `by': gen `bygrp'=cond(_n==1,1,.) qui replace `bygrp'=sum(`bygrp') local bylev = `bygrp'[_N] } *********************************************** * Saving the file or not. * NB if file exists it is deleted!! *********************************************** if ("`saving'"~="") { cap confirm new file `saving'.gph if _rc~=0 { di "Deleteing file...`saving'.gph" !rm `saving'.gph } di "Saving file... `saving'.gph" gph open, saving(`saving') } else { gph open } if "`debug'"~="" { gph close } *********************************************** * Loop through all the levels of the * by variable *********************************************** local pen 1 local i 1 while `i' <= `bylev' { local pen=`pen'+1 local pen= mod(`pen',10) if "`ylab'"=="" { summ `1' local min=string(round(r(min),`round')) local max=string(round(r(max),`round' )) local mid=string(round(r(mean),`round' )) local ylab = "`min',`mid',`max'" } if "`xlab'"=="" { summ `2' local min=string(round(r(min),`round' )) local max=string(round(r(max),`round' )) local mid=string(round(r(mean),`round' )) local xlab = "`min',`mid',`max'" } if "`function'"=="" { graph `varlist' if `bygrp'==`i', xlab(`xlab') ylab(`ylab') pen(`pen') `gopt' } else { cap `function' `varlist' if `bygrp'==`i', pen(`pen') xlab(`xlab') ylab(`ylab') `gopt' if _rc~=0 { local warning "Pen option not working Lines will not be distinct" cap `function' `varlist' if `bygrp'==`i', xlab(`xlab') ylab(`ylab') `gopt' if _rc~=0 { local warning "Pen and xlab/ylab options do not work hence the y and x scales might be wrong in the composite graph" di "`function' `varlist' if `bygrp'==`i', `gopt'" sto `function' `varlist' if `bygrp'==`i', `gopt' ston } } } local i = `i'+1 } gph close restore if "`warning'"~="" { di "Extra Diagnostic errors" di "-----------------------" di "`warning'" } end