我在Stata中创建了一个双向汇总表,但我很难输出结果。
使用auto.dta
示例数据集作为示例,我尝试构建一个表,显示mpg
的均值和标准偏差,以及另外两个变量expensive
和{{ 1}})。
我的代码目前看起来如下:
foreign
我想要显示的表可以通过以下两个命令之一创建:
sysuse auto.dta, replace
gen expensive = (price > 5000)
tabulate expensive foreign, sum(mpg)
Means, Standard Deviations and Frequencies of Mileage (mpg)
| Car type
expensive | Domestic Foreign | Total
-----------+----------------------+----------
0 | 22.137931 28.875 | 23.594595
| 4.3648281 4.8825491 | 5.2305696
| 29 8 | 37
-----------+----------------------+----------
1 | 16.913043 22.428571 | 19
| 3.4629604 6.4416229 | 5.4467115
| 23 14 | 37
-----------+----------------------+----------
Total | 19.826923 24.772727 | 21.297297
| 4.7432972 6.6111869 | 5.7855032
| 52 22 | 74
我也可以使用table expensive foreign, c(mean mpg sd mpg) row col
----------------------------------------
| Car type
expensive | Domestic Foreign Total
----------+-----------------------------
0 | 22.1379 28.875 23.5946
| 4.364828 4.882549 5.23057
| 29 8 37
|
1 | 16.913 22.4286 19
| 3.46296 6.441623 5.446712
| 23 14 37
|
Total | 19.8269 24.7727 21.2973
| 4.743297 6.611187 5.785503
| 52 22 74
----------------------------------------
仔细估算相同的结果,但这不会计算行和列总数。
我的问题是,collapse
(使用tabulate
选项)命令和sum
命令似乎都不能输出。我已尝试转换为矩阵,但使用table
选项的tabulate
不允许使用sum
选项而matcell
似乎同样不合作。
我熟悉table
,tabstat
等,但无法使用任何这些软件包创建我需要的双向表。任何帮助都会非常感激。
答案 0 :(得分:1)
社区贡献命令asdoc
的作用完全是这样:
. asdoc table expensive foreign, c(mean mpg sd mpg count mpg) row col
----------------------------------------
| Car type
expensive | Domestic Foreign Total
----------+-----------------------------
0 | 22.1379 28.875 23.5946
| 4.364828 4.882549 5.23057
| 29 8 37
|
1 | 16.913 22.4286 19
| 3.46296 6.441623 5.446712
| 23 14 37
|
Total | 19.8269 24.7727 21.2973
| 4.743297 6.611187 5.785503
| 52 22 74
----------------------------------------
Click to Open File: Myfile.doc
或者,可以使用社区贡献的命令tabout
:
. tabout expensive foreign using table1.txt, c(mean mpg) sum replace
Table output written to: table1.txt
Car type
Domestic Foreign Total
Mean mpg Mean mpg Mean mpg
expensive
0 22.1 28.9 23.6
1 16.9 22.4 19.0
Total 19.8 24.8 21.3
. tabout expensive foreign using table2.txt, c(sd mpg) sum replace
Table output written to: table2.txt
Car type
Domestic Foreign Total
Sd mpg Sd mpg Sd mpg
expensive
0 4.4 4.9 5.2
1 3.5 6.4 5.4
Total 4.7 6.6 5.8
. tabout expensive foreign using table3.txt, c(count mpg) sum replace
Table output written to: table3.txt
Car type
Domestic Foreign Total
Count mpg Count mpg Count mpg
expensive
0 29.0 8.0 37.0
1 23.0 14.0 37.0
Total 52.0 22.0 74.0
答案 1 :(得分:0)
一个简单的解决方案是使用 <div class="container-fluid">
<div class="row" id="headers">
<div class="menu col-xs-3">
<div>
<div class="col-xs-12 menu-item"><a id="about-me-nav">About Me</a></div>
<div class="col-xs-12 menu-item"><a>Portfolio</a></div>
<div class="col-xs-12 menu-item"><a href="./resume.html">Resume</a></div>
<div class="col-xs-12 menu-item"><a>Contact</a></div>
</div>
</div>
<div class="col-xs-9 main">
<h1>Header</h1>
</div>
<div class="col-xs-9 content auto-content-div">
</div>
来获取再现所需表格的数据集,然后将数据集导出为body, html {
height: 100%;
width: 100%;
}
#headers, .container-fluid {
height: 100%;
}
.menu {
background: url("http://www.space.com/images/i/000/041/737/original/milky-way-chile-praniski.jpg") no-repeat;
height: 100%;
}
.main {
background-color: #021615;
text-align: center;
}
.menu-item:first-child {
padding-top: 4.5em;
}
.menu-item {
padding-top: 4em;
text-align: center;
}
.content {
height: 100%;
background-color: rgba(12, 122, 86, 0.32) ;
}
例如
collapse
然后
csv