*! version 0.1.0 3/8/94 v 0.2.0 6/19/97 STB-41 gr16.2 *! v 0.2.0 corrects right/left multiple points graphing program define condraw version 3.1 local varlist "req ex min(3) max(3)" local options /* */ "`options' Hull(int 1) Group(str) GRno(int 0) Dr(str) Vid(str)" parse "`*'" parse "`varlist'",parse(" ") local hullno "`hull'" local grnum "`grno'" tempvar flg local flg=0 if ("`group'"=="") { tempvar all mac def _group `all' quietly gen byte `group'=1 local flg=1 } if ("`dr'"=="") { mac def _dr "dr" } if ("`vid'"=="") { mac def _vid "hv" } tempvar touse mark `touse' markout `touse' `varlist' quietly count if `3'==`hullno' if _result(1)==0 { di in red "Requested hull exceeds the maximum number of" di in red "hulls assigned for any group" quietly summarize `3' di in red "There are only " _result(6) " hulls assigned" exit } if (`grnum'>0) { local fs=`grnum' local ls=`grnum' } else { quietly summarize `group' local fs=_result(5) local ls=_result(6) } tempvar mk loc quietly gen byte `loc'=. quietly gen `mk'=0 local uj=0 local gm=" `2'" local cm="c(." local sm="s(" local vm="Variables: " tempvar theta marker dx dy quietly gen byte `marker'=. quietly gen `theta'=-1e37 quietly gen `dx'=. quietly gen `dy'=. quietly gen `dr'=0 quietly gen byte zuse=0 quietly while `fs'<=`ls' { local flag=1 while `fs'<=`ls' & `flag'==1 { replace `mk'=-1e37 if `3'==`hullno' & `group'==`fs' sort `mk' `group' count if `group'==`fs' & `mk'!=0 if _result(1)==0 { local flag=1 if `fs'==real("`grno'") { n di in red "No hull points for group " `grno' n di in red "drop dr and try another group or hull" exit } } else { local fs=`fs'-1 local flag=0 } local fs=`fs'+1 } local ui=1 local uj=_result(1) sort `2' `1' in `ui'/`uj' replace `marker'=1 in `ui'/`uj' replace `marker'=2 in `ui' expand `marker' replace `marker'=0 in `ui' replace `dr'=1 if `marker'==2 sort `marker' `mk' local i=`ui' local j=`i'+1 quietly replace zuse=1 if `marker'==2 tempvar id gen byte `id'=. local uk=`uj'+1 while `i' < `uj' { replace `marker'=0 in `i' replace `dx'=`1'-`1'[`i'] in `j'/`uj' replace `dy'=`2'-`2'[`i'] in `j'/`uj' replace `theta'=0 in `j'/`uj' replace `theta'=. if `dx'==0 & `dy'==0 in `j'/`uj' replace zuse=2 if `dx'==0 & `dy'==0 & `marker'!=2 in `j'/`uj' count if `dx'==0 & `dy'==0 in `j'/`uj' local du=_result(1) replace `id'=_n in `i'/`uk' sort zuse `id' in `j'/`uk' replace `theta'=`dy' /(abs(`dx') + abs(`dy')) if `dy'!=0 in `j'/`uj' replace `theta'=2-`theta' if `dx'<0 in `j'/`uj' replace `theta'=4+`theta' if `dx'>=0 & `dy'<0 in `j'/`uj' replace `theta'=`theta'-2 in `j'/`uj' replace `theta'=. if `theta'<`theta'[`i'] in `j'/`uj' if `theta'[`j']~=1 { sort zuse `theta' `2' in `j'/`uj' } local i=`j' local j=`j'+1 local uj=`uj'-`du' } di "`vid'" local var="`vid'"+"`fs'" tempvar `var' gen `var'=. replace `var'=`2' in `ui'/`uk' if `fs'!=`ls' { local gm="`gm'"+ " `var'" local cm="`cm'"+"l" local sm="`sm'"+"[`group']" local vm="`vm'"+" `var'" } else { local gm="`gm'"+" `var'"+ " `1'" local cm="`cm'"+"l)" local sm="`sm'"+"[`group'])" local vm="`vm'"+" `var'"+" were created" } replace `marker'=. in `ui'/`uk' replace `mk'=. in `ui'/`uk' replace `loc'=_n in `ui'/`uk' local uj=`uj'+1 local fs=`fs'+1 } sort `3' `group' `loc' if `flg'==1 { graph `gm' if zuse!=2, `cm' s(o) } else { graph `gm' if zuse!=2, `cm' `sm' } if ("`group'"=="all") { quietly drop `group' } di "`vm'" di "You can redraw the graph with the command:" if `flg'==1 { di in green "graph ""`gm'" " if zuse!=2, " "`cm'" " s(o)" } else { di in green "graph ""`gm'" " if zuse!=2, " "`cm'"" " "`sm'"" } di "You can now change the graph options, add titles, save, etc." di "To use the same data set to generate a different graph or to eliminate" di "all the created variables use the following sequence of commands" di "(making sure to follow the order given):" di in green ". drop if " "`dr'""==1" di in green ". drop " "`dr'"" " "`vid'""*" " zuse" end exit