*! version 0.1.0 3/8/94 gr16: STB-23 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'" if ("`group'"=="") { tempvar all mac def _group `all' quietly gen byte `group'=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 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 uk=`uj'+1 local i=`ui' local j=`i'+1 while `marker'[`i'] !=2 { replace `marker'=0 in `i' replace `dx'=`1'-`1'[`i'] in `j'/`uk' replace `dy'=`2'-`2'[`i'] in `j'/`uk' replace `theta'=0 in `j'/`uk' replace `theta'=. if `dx'==0 & `dy'==0 in `j'/`uk' replace `theta'=`dy' /(abs(`dx') + abs(`dy')) if `dy'!=0 in `j'/`uk' replace `theta'=2-`theta' if `dx'<0 in `j'/`uk' replace `theta'=4+`theta' if `dx'>=0 & `dy'<0 in `j'/`uk' replace `theta'=`theta'-2 in `j'/`uk' replace `theta'=. if `theta'<`theta'[`i'] in `j'/`uk' sort `theta' in `j'/`uk' local i=`j' local j=`j'+1 } 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' graph `gm',`cm' `sm' if ("`group'"=="all") { quietly drop `group' } di "`vm'" di "You can redraw the graph with the command:" di in green "graph ""`gm'"", ""`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'""*" end exit