美文网首页统计分析
Stata: 在我的程序中接纳另一个程序的所有选项

Stata: 在我的程序中接纳另一个程序的所有选项

作者: stata连享会 | 来源:发表于2019-01-13 09:12 被阅读100次

Source: Stackoverflow - Stata ado syntax with double quotes

问题背景

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:

  1. 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(" ")
  1. 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.

  2. In other problems specifying that an option argument is string asis inhibits the stripping of double quotes.


欢迎加入Stata连享会(公众号: StataChina)

相关文章

网友评论

    本文标题:Stata: 在我的程序中接纳另一个程序的所有选项

    本文链接:https://www.haomeiwen.com/subject/sddkdqtx.html