Stata 中“制表双向”频率计数表的 5×5 矩阵
我想创建一个 5×5 网格的 tabulate Twoway
频率计数表,如下表所示。
使用嵌套的 foreach
循环生成每个子表很容易,但是长列表输出比 5×5 网格更难解释(并且具有冗余条目 - 它提供对称矩阵的两半)。
Stata可以制作这样的表格吗?需要明确的是,我稍后可以弄清楚 LaTeX,我只是对获得清晰简洁的控制台输出感兴趣。
谢谢!下面是一些使用 auto
数据执行基础操作的代码,但生成一个列表而不是矩阵。 xtile
来自 egenmore
包
sysuse auto, clear
global vars price mpg headroom trunk weight
foreach x of global vars {
egen d_`x' = xtile(`x'), nquantiles(2)
}
* can make diagonal entries
tabulate d_price d_price
* can make off-diagonal entries
tabulate d_price d_mpg
* crude solution that generates list output with redundant entries
foreach x of global vars {
foreach y of global vars {
tabulate d_`x' d_`y'
}
}
I would like to create a 5-by-5 grid of tabulate twoway
frequency count tables, like the following table.
Generating each sub-table is easy with nested foreach
loops, but the long list output is more difficult to interpret than a 5-by-5 grid (and has redundant entries -- it provides both halves of the symmetric matrix).
Is it possible to make a table like this in Stata? To be clear, I can figure out the LaTeX later, I am just interested in getting clear and concise console output.
Thanks! Here is some code that does the basics using the auto
data, but generates a list instead of a matrix. xtile
is from the egenmore
package
sysuse auto, clear
global vars price mpg headroom trunk weight
foreach x of global vars {
egen d_`x' = xtile(`x'), nquantiles(2)
}
* can make diagonal entries
tabulate d_price d_price
* can make off-diagonal entries
tabulate d_price d_mpg
* crude solution that generates list output with redundant entries
foreach x of global vars {
foreach y of global vars {
tabulate d_`x' d_`y'
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在循环中添加了一些矩阵运算。
它有点类似于我的名为
meantab
的程序,位于 http:// /code.google.com/p/kk-adofiles/I've added some matrix operations into your loop.
It is a little similar to my program named
meantab
, at http://code.google.com/p/kk-adofiles/