I'm trying to use prior code to create a Turnip plot in STATA 11.2. I keep getting a r(198) error when running the code. It seems to get caught up when I'm setting my resolution. It doesn't like `resolut' == 0 ... any advice? Thank you.

*! Version 1.0.0 (STB-58: gr45)
*turnip.do capture program drop turnip
program define turnip
version 6.0

syntax varlist(min=1 max=1) [if] [, RESolution(real 0) Truev(real -0.000000001) *]

f index("`options'", "by(") !=0 {
di ""
di "* * * BY option is not allowed * * *"
di ""
di " Instead, use the IF option -- set YLABEL and YSCALE "
di" to ensure identical sizing"
di ""
exit
}

set more 1

/* TURNIP generator eg, turnip mpg [if foreign==1] [,RESolution(0)] Truev(1) [ylabel(10 20 30 40 50)] [xlabel(-30 0 30)] [yline(0) TItle(passthru)]

*/ *local ttt= "ttt" + substr("`varlist'", 1, 4)
tempvar ttt

*default resolution if `resolut' == 0 {
quietly sum `varlist'
local resolut = r(sd)/2.5
}

if `resolut'>=0 {
quietly gen `ttt '= round(`varlist',`resolut')
}

else {
quietly gen `ttt' = `varlist'
/* suspend all rounding */
}


/*TRUEV(alue) option: Suspends rounding of certain values (e.g., only let true 0's appear as 0's...everyone else gets rounded to the nearest category) */ if `truev'~= -0.000000001{ local faker=int(`truev'/`resolut') local i=1 while `i'<_N { local rttt=round(`ttt'[`i'], .000001) local rtruev=round(`truev',.000001) if `rttt'==`rtruev'& `varlist'[`i']>`ttt'[`i'] { quietly replace `ttt'=(`faker'+1)*`resolut' in `i'} if `rttt'==`rtruev'& `varlist'[`i']<`ttt'[`i'] { quietly replace `ttt'=(`faker'-1)*`resolut' in `i'} local i = `i' + 1 } } *calculate x-axis coordinates tempvar horiz quietly gen `horiz'=. sort `ttt' preserve capture keep `if' /* this will allow for -if- option*/ *at each level of ttt, create spacing variable called `horiz' , symmetric around 0 quietly by `ttt':quietly replace `horiz' =round(_n/2,1) -.5 quietly by `ttt':quietly replace `horiz' =-1*`horiz' if (mod(_n,2)==1) *center turnip rows with an odd number of members by moving them over by .5 tempvar h_ct quietly egen `h_ct'=count(`ttt'), by(`ttt') quietly replace `horiz' =`horiz' + .5 if (mod(`h_ct',2)==1) */ *to get n per graph row: **tab `ttt'** and look at obs number * di "# of observations per turnip row is the frequency below:" label var `ttt' "`varlist'" tab `ttt' *default xlabel if index("`options'", "xlabel")<1 { quietly sum `horiz' local defx=round(2*r(max), 1) local ndefx=round(-1*`defx', 1) local options = "`options'" + " xlabel(`ndefx' `defx')" } *default ylabel if index("`options'", "ylabel")<1 { quietly sum `ttt' local fixy = (r(max) - r(min))*0.1 local defy= round((r(min) - `fixy'), 1) local ndefy=round((r(max) + `fixy'), 1) local options = "`options'" + " ylabel(`defy' `ndefy' )" } local dflag="none" local d="" *yline mean option local a=index("`options'", "yline(mean)") if `a'!=0{ local dflag="mean" quietly sum `varlist' /*use varlist not tttvarlist ! */ local b=`a'+ 5 local c = `a' + 10 local d = _result(3) local f = length("`options'") local options = substr("`options'", 1, `b') + substr("`d'", 1, 4) + /* */ substr("`options'", `c', `f') * now add mean to ylabel local a=index("`options'", "ylabel(") if `a' > 0 { local b = `a' + 6 local c = `a' + 7 local f = length("`options'") local options = substr("`options'", 1, `b') + " `d' " /* */ + substr("`options'", `c', `f') } } *yline median option local a=index("`options'", "yline(median)") if `a'!=0{ local dflag="median" quietly sum `varlist', det /*use varlist not tttvarlist ! */ local b=`a'+ 5 local c = `a' + 12 local d = _result(10) local f = length("`options'") local options = substr("`options'", 1, `b') + substr("`d'", 1, 4) + /* */ substr("`options'", `c', `f') * now add mean to ylabel local a=index("`options'", "ylabel(") if `a' > 0 { local b = `a' + 6 local c = `a' + 7 local f = length("`options'") local options = substr("`options'", 1, `b') + " `d' " /* */ + substr("`options'", `c', `f') } } di "options: `options'" di "resolution: `resolut'" if "`dflag'" != "none" {di "yline: `d' (`dflag')"} di " " graph `ttt' `horiz' , `options' b2title(" ") l1title("`varlist'") xtick(0) restore end