Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Why does Stata return an invalid syntax error in this ado file?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Why does Stata return an invalid syntax error in this ado file?
Date   Fri, 19 Oct 2012 23:58:29 +0100

Except that as advised "String" should be "string".

On Fri, Oct 19, 2012 at 11:53 PM, Nick Cox <[email protected]> wrote:
> General tips
>
> 1. Use -set trace on- to see where the program stops.
>
> 2. Always report the return code. Here it is 197, meaning that
> -syntax- itself is problematic.
>
> Specific tips
>
> 3. The bug is that the argument of -generate()- should be given as
> "string", not "String".
>
> 4. Your -generate()- option is compulsory. If it is empty, the program
> won't run. Hence the -if- test is superfluous. Your program can start
>
> program define statetofips
>          version 8
>          syntax varname , Generate(String)
>          quietly  {
>                  gen int `generate' = .
>                  replace `generate' = <stuff>
>                  ...
>          }
>
> 5. Other small changes suggested above.
>
> On Fri, Oct 19, 2012 at 11:18 PM, Aaron Kirkman
> <[email protected]> wrote:
>
>> I'm writing a simple ado file, --statetofips--, to assign fips codes
>> to observations based on the state name. If I run the following code,
>> I do not receive an error:
>>
>> ##
>> clear
>> input str8 state
>> Alabama
>> Alabama
>> Alabama
>> Alaska
>> Alaska
>> Alaska
>> Arizona
>> Arizona
>> Arizona
>> Arkansas
>> end
>>
>> gen int fips = .
>> replace fips = 1 if lower(state) == "alabama"
>> replace fips = 2 if lower(state) == "alaska"
>> replace fips = 4 if lower(state) == "arizona"
>> ##
>>
>> However, if I run this code, I receive an "invalid syntax" error:
>>
>> ##
>> clear
>> input str8 state
>> Alabama
>> Alabama
>> Alabama
>> Alaska
>> Alaska
>> Alaska
>> Arizona
>> Arizona
>> Arizona
>> Arkansas
>> end
>>
>> discard
>> statetofips state, generate(fips)
>> ##
>>
>> These are the contents of --statetofips.ado--, which is located in the
>> same directory as the above do file:
>>
>> ##
>> program define statetofips
>>         syntax varname , Generate(String)
>>         if "`generate'" != "" {
>>                 quietly gen int `generate' = .
>>         }
>>         replace `generate' = 1 if lower(`varlist') == "alabama"
>>         replace `generate' = 2 if lower(`varlist') == "alaska"
>>         replace `generate' = 4 if lower(`varlist') == "arizona"
>>         replace `generate' = 5 if lower(`varlist') == "arkansas"
>>         replace `generate' = 6 if lower(`varlist') == "california"
>>
>> end
>> ##
>>
>> I reduced --statetofips.ado-- to its simplest form, and the error persists:
>>
>> ##
>> program define statetofips
>>         syntax varname , Generate(String)
>> end
>> ##
>>
>>
>> What is causing the syntax error in the 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index