在 Stata12 中工作,我需要绘制 5 个直方图,矩阵的每一列一个MAT,其中:
mata: MAT = uniform(1000, 5)
我知道一种可能性是mm_histogram()用于获取直方图每个区间的中心、宽度和密度。对于第一列,我们有:
mata: HIST_DAT = mm_histogram(MAT[.,1])
但后来我不知道如何继续绘制数据(在 Stata 或 Mata 中)。
非常感谢您的任何建议。
编辑:这个问题也出现在Statalist档案中
在 Stata12 中工作,我需要绘制 5 个直方图,矩阵的每一列一个MAT,其中:
mata: MAT = uniform(1000, 5)
我知道一种可能性是mm_histogram()用于获取直方图每个区间的中心、宽度和密度。对于第一列,我们有:
mata: HIST_DAT = mm_histogram(MAT[.,1])
但后来我不知道如何继续绘制数据(在 Stata 或 Mata 中)。
非常感谢您的任何建议。
编辑:这个问题也出现在Statalist档案中
有一个简单的答案:将矩阵列复制到 Stata 变量并使用histogram. 其他任何事情都只是迂回或近似。
很难看出这个问题的核心是什么,但如果兴趣是绘制随机数的直方图,那么在 Stata 中将它们创建为变量会容易得多:
. set obs 500
. gen y = runiform()
. histogram y
为了完整起见,绘制相对于MAT列的直方图的代码是:
clear all
set obs 1000
mata:
// Mata matrix of results
MAT = uniform(500, 5)
// generates Stata variables from within Mata
Stata_vars = st_addvar("float", ("V1", "V2", "V3", "V4", "V5"))
// stores MAT columns in the first 500 obs. of the Stata variables
st_store((1::rows(MAT)), Stata_vars, MAT)
end
然后我们只需要输入:
hist(V1)
forV1或任何其他V2-V5新创建的 Stata 变量。