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]

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


From   Aaron Kirkman <[email protected]>
To   [email protected]
Subject   st: Why does Stata return an invalid syntax error in this ado file?
Date   Fri, 19 Oct 2012 17:18:08 -0500

Dear Statalist,

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?

Thank you,

Aaron Kirkman
*
*   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