program def onewplot 
*! 1.2.1 NJC 18 October 1999 
* 1.1.0 NJC 27 April 1999 
* 1.0.0 NJC 23 April 1999 
	version 6.0
	syntax varlist(min=1 numeric) [if] [in] [ , Frac(real 0.8) STack /* 
	*/ by(varname) Symbol(str) Ylabel(str) L1title(str) * ] 

	tempvar touse  
	mark `touse' `if' `in' 

	local noby = "`by'" == ""
	tokenize `varlist' 
	local nvars : word count `varlist' 
	if `nvars' > 1 { 
		if "`by'" != "" { 
			di in r /* 
		*/ "by( ) may not be combined with more than one variable"
			exit 198
		}	
		else {
			preserve
			local i 1
		        while `i' <= `nvars' {
                		local labels "`labels' `i' ``i''"
		                local i = `i' + 1
		        }
			tempvar data 
			stack `varlist' if `touse', into(`data') clear 
			label var `data' "`varlist'"
			tempname stlbl
			label def `stlbl' `labels' 
		        label val _stack `stlbl'
			if "`stack'" != "" { 
				tempvar count 
				sort _stack `data' 
				qui by _stack `data' : gen `count' = _n - 1  
				su `count', meanonly
				qui if r(max) > 0 { 
					replace _stack = /* 
					*/ _stack + `frac' * `count' / r(max) 
				} 	
			}	
		}
	}	
	else { 
		if "`by'" == "" {
			tempvar by
			gen byte `by' = 1
			tempname bylbl 
			label def `bylbl' 1 "`varlist'"
			label val `by' `bylbl' 
		}
		else {
			capture confirm numeric variable `by'
			if _rc == 7 { 
				tempvar by2
				encode `by', gen(`by2')
				_crcslbl `by2' `by' 
				local by "`by2'" 
			}	
			su `by' if `touse', meanonly 
			local range "`r(min)'/`r(max)'" 
		}	
		if "`stack'" != "" { 
			tempvar count bycount 
			sort `touse' `by' `varlist' 
			qui by `touse' `by' `varlist' : gen `count' = _n - 1 
			qui gen `bycount' = `by' 
			su `count' if `touse', meanonly 
			qui if r(max) > 0 { 
				replace `bycount' = /* 
				*/ `bycount' + `frac' * `count' / r(max) 
			} 	
			_crcslbl `bycount' `by'
			local bylab : value label `by' 
			label val `bycount' `bylab' 
		} 	
	}	

	if "`symbol'" == "" { 
		tempvar pipe
		gen str1 `pipe' = "|" 
		local symbol "sy([`pipe'])"
	}
	else local symbol "sy(`symbol')" 
	
	if `"`ylabel'"' == `""' { 
		if `noby' { local ylabel "yla(1/`nvars')" }
		else local ylabel "yla(`range')" 
	}	
	else local ylabel `"yla(`ylabel')"'  

	if `"`l1title'"' == `""' & `noby' { 
		local l1title `"l1title(" ")"' 
	} 
	else local l1title `"l1title("`l1title'")"' 

	if "`by'" != "" { 
		if "`stack'" != "" { 
			graph `bycount' `varlist' if `touse', /* 
			*/ `l1title' `symbol' `ylabel' `options' 
		} 	
		else graph `by' `varlist' if `touse' , /*
		*/ `l1title' `symbol' `ylabel' `options'     
	}
	else {
		graph _stack `data', /* 
		*/ `l1title' `symbol' `ylabel' `options' 
	}	
end