【发布时间】:2015-04-24 14:14:53
【问题描述】:
我有一种情况,我需要使用两个变量 mpg 和 make 中的值来创建图表。变量mpg 是一个数值变量,make 是一个带空格的字符串变量。当我忽略 make 变量中的值时,以下代码能够使用 mpg 中的值来创建图形。但是,我希望变量 make 中的相应字符串值出现在图形字幕中。出于某种原因,这段代码在遍历变量 mpg
中的几个值后给出了错误 too many ')' or ']'sysuse auto.dta, clear
gsort - trunk
keep in 1/5
levelsof mpg, local(levels)
global xlist `levels'
levelsof make, local(levelsdes)
global ylist `levelsdes'
sysuse auto.dta, clear
gen bar=1
local k 1 2 3 4 5
local n : word count $xlist
forvalues x =1/`n' {
local i : word `x' of $xlist
local z : word `x' of `k'
local j : word `x' of $ylist
egen a_`i'= total(bar) if mpg == `i'
twoway (bar a_`i' mpg ), subtitle(`j') title(Trends in Error `i')
graph export "`z'.png", as(png) replace
}
【问题讨论】:
-
将 display “-- `i' -- `j' -- `z' --” 添加到您的循环中,您将看到问题的开始。
标签: stata