Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Richard Herron <richard.c.herron@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Unable to clear "invalid syntax r(197);" error in user-written .ado file |
Date | Thu, 4 Oct 2012 22:24:23 -0400 |
I wrote an .ado file to trim data in the left and right tails, but I can't get past an "invalid syntax r(197)" error. My -syntax- line is as follows. * begin syntax line syntax varlist(numeric) [if] [in] /// [, Byvar(string fyear) Tail(real 0.5) Suffix(string tr)] * end syntax line I would like to use a -varlist- so that I can loop over the supplied variables, but I can't clear the error using -varname- or by dropping the -if- and -in- statements. I also tried making the options required without defaults, but that didn't work either. What is my misunderstanding of syntax? Thank you! Below is the complete .ado file. I use Stata SE 11.2 (64 bit) on Windows 7. * begin .ado file *! 0.1 Richard Herron 10/3/2012 program atrim version 11.2 syntax varlist(numeric) [if] [in] /// [, Byvar(string fyear) Tail(real 0.5) Suffix(string tr)] * rather than -bysort- twice below sort `byvar' * not necessary to tokenize; loop varlist foreach x of local varlist { * determine percentiles by `byvar': egen num = count(`x') if !missing(`x') by `byvar': egen ran = rank(`x') if !missing(`x') generate pct = 100 * (ran - 0.5) / num * replace tails with -sysmiss- generate test = if inrange(pct, `tail', `=100 - `tail'') generate `x'_`suffix' = cond(test, `x', .) * drop "temporary" variables drop num ran pct test } end * end .ado file * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/