Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Aaron Kirkman <ak1795mailserv@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 19 Oct 2012 18:23:24 -0500 |

Hi Nick, As always, thank you for the corrections and advice, especially about -set trace on-. The suggested work perfectly. Aaron On Fri, Oct 19, 2012 at 5:58 PM, Nick Cox <njcoxstata@gmail.com> wrote: > Except that as advised "String" should be "string". > > On Fri, Oct 19, 2012 at 11:53 PM, Nick Cox <njcoxstata@gmail.com> 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 >> <ak1795mailserv@gmail.com> 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/ * * 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/

**References**:**st: Why does Stata return an invalid syntax error in this ado file?***From:*Aaron Kirkman <ak1795mailserv@gmail.com>

**Re: st: Why does Stata return an invalid syntax error in this ado file?***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Why does Stata return an invalid syntax error in this ado file?***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Why does Stata return an invalid syntax error in this ado file?** - Next by Date:
**Re: st: mlabel on marginsplot?** - Previous by thread:
**Re: st: Why does Stata return an invalid syntax error in this ado file?** - Index(es):