Stata—描述性统计

1.资料的基本信息

①summarize

summarize:汇总所有变量的名称,个案数目,均值,标准差等,缩写为sum

format age %6.2f:指定age变量的统计量输出时的保留2位小数

sum age, format:结合上个命令,对年龄变量进行描述的汇总保留2位小数

sum age,detail:汇总更加详细的信息

②codebook

codebook没有sum详细

codebook:汇总所有变量

codebook var:汇总var变量

 

③inspect

inspect age:可以画出简单的直方图

 

2.基本信息的统计

①tabulate和table命令

tabulate places:对places变量进行列表统计,此命令可缩写为tab

table places:只有频数统计,不可缩写为tab

tab places price:统计不同地方的价格的列表

tab places price:统计不同places的price的列表

②tabstat命令

tabstat price places:显示2个变量的平均值

tabstat price places, stats(mean med min max):显示2个变量的平均值,中位数等统计量

tabstat price places, stat(mean med min max p25) col(s) format(%6.2f):均值等统计量在表格的行中,并且将结果小数点保持在2位。此命令也可以写为tabstat price places, s(mean med min max) c(s) f(%6.2f)。

tabstat price places, s(mean med min max) c(s) f(%6.2f) by (gender):根据性别分类来陈述上述的统计量。

③结果呈现

(1)将Stata中的结果选中,右击鼠标选择Copy table,直接贴入Excel或者Word。

(2)通过命令将其直接保存在txt文件

tabexport var using results.txt, s(mean sd) replace //此处的tabexport命令第一次使用时应当进行安装,安装命令为ssc install tabexport

shellout results.txt //打开txt文件以便查看结果,此结果可直接复制到Excel中

tabexport var using results.txt, s(mean sd) by(gender) noreshape replace format(%6.2f) //此处根据性别输出var的统计量,并定义均数和标准差的输出显示格式为保留2位小数

tabexport ba004 using results.txt, s(count mean sd) by(rgender) noreshape replace format(%6.0f %6.2f %6.3f) //根据呈现的需求,format命令可以依次定义各个变量

shellout results.txt

posted @ 2021-08-10 15:21  Sunny蝌蚪  阅读(5700)  评论(0编辑  收藏  举报