假设我在Stata中使用了一些twoway
图命令。在不采取任何行动的情况下,Stata将根据数据中的最小和最大值y和x值,为y和x轴的范围选择一些合理的值,但也基于一些算法,该算法决定何时将范围扩展到'0‘这样的数字,而不是'0.0139’。精彩的!太棒了。
现在假设在我画完我的图之后,我想把一些非常重要的文本放在上面,我想要对文本的准确位置做出选择。拥有所显示的轴的最小值和最大值将是有用的:,如何获得这些min和最大值?(在调用图形命令之前或在调用图形命令时)。
注:我不是问如何设置y或x轴范围。
发布于 2022-09-27 16:19:00
我喜欢Nick的建议,但是如果您真的下定决心,您可能可以通过在set trace on
之后检查输出来找到这些值。下面是一些极其低效的代码,似乎在我有限的测试中起作用。三个注意事项:
当我导入日志文件时,我得到以下消息:Note: Unmatched quote while processing row XXXX; this can be due to a formatting problem in the file or because a quoted data element spans multiple lines. You should carefully inspect your data after importing. Consider using option bindquote(strict) if quoted data spans multiple lines or option bindquote(nobind) if quotes are not used for binding data.
cap log close _all
set linesize 255
log using "log", replace text
clear
set obs 3
gen xvar = rnormal(0,10)
gen yvar = rnormal(0,.01)
set trace on
twoway scatter yvar xvar
set trace off
cap log close _all
* now read the log file in and find the desired info
import delimited "log.log", delimiter("SOME_RANDOM_TEXT") clear
keep v1
keep if regexm(v1,"forvalues yf") | regexm(v1,"forvalues xf")
drop if regexm(v1,"delta")
split v1, parse("=") gen(new)
gen axis = "vertical" if regexm(v1,"yf")
replace axis = "horizontal" if regexm(v1,"xf")
keep axis new*
duplicates drop
loc my_regex = "(.*[0-9]+)\((.*[0-9]+)\)(.*[0-9]+)"
gen min = regexs(1) if regexm(new3,"`my_regex'")
gen delta = regexs(2) if regexm(new3,"`my_regex'")
gen max_temp= regexs(3) if regexm(new3,"`my_regex'")
destring min max delta , replace
gen max = min + delta* int((max_temp-min)/delta)
list axis min delta max
其他人可能会有改进的想法!
https://stackoverflow.com/questions/70977297
复制相似问题