问题背景
I would like to have an option in my program that allows any twoway option to be used (see help twoway_options) and have run into a problem when using quotes either with just whitespace or within subcommands as demonstrated below.
sysuse gnp96, clear
capture prog drop adding_quotes
prog def adding_quotes
syntax [, tw_opts(string)]
line gnp96 date, `tw_opts'
end
// throws error
adding_quotes, tw_opts(text(7000 97 "Middle Text"))
adding_quotes, tw_opts(xtitle(" "))
// runs
adding_quotes, tw_opts(text(7000 97 `""Middle Text""'))
adding_quotes, tw_opts(xtitle(""))
I would also note that doing away with the syntax command will also solve the problem, but I would rather keep it in and not have to parse the whole command.
Is it possible to change the syntax command so that the two commands that throw errors work?
解决方法
Two suggestions and a comment:
- You want to allow any twoway options, which you will pass to a graph command. It's simplest just to use a wildcard * in syntax and let syntax (and in this case twoway) do all the work.
sysuse gnp96, clear
capture prog drop adding_quotes
prog def adding_quotes
syntax [, * ]
line gnp96 date, `options'
end
adding_quotes, text(7000 97 "Middle Text")
adding_quotes, xtitle(" ")
-
As above, the
xlabel(" ")
call was illegal regardless. You're probably influenced by terminology elsewhere to think of what Stata calls axis titles as axis labels. For Stata, the axis labels are the individual text labels, by default in twoway at various numeric positions on the axes. -
In other problems specifying that an option argument is string asis inhibits the stripping of double quotes.
欢迎加入Stata连享会(公众号: StataChina)
网友评论