stata--二维表

作者: 古城路揸fit人 | 来源:发表于2019-10-13 21:33 被阅读0次

什么是二维表(twoway tables)

用来统计分类变量(categories)的频数的

tab命令

二维表基础命令,统计一个变量叫一维表,两个变量叫二维表。
tab后跟的第一个变量可以认为是“垂直变量”,第二个变量可以认为是“水平变量”

sysuse nlsw88, clear
tab union //一维表
tab union sex //二维表

二维表输出命令tabout

tabout race south collgrad using table39.docx, ///
replace style(docx) font(bold) c(freq row col) ///
f(0c 1 1) layout(cb) landscape title(Table 39: ///
Example of rotation with docx output style) ///
fn(nlsw88.dta) open

**c(freq col) ** is the contents option, which determines the cell
contents: frequencies and column percentages

f(0c 1) is the format option and sets the cell numbers as zero decimal points with commas for the frequencies and one decimal point for the column percentages

font(bold) turns on bold formatting for the variable labels and the
second row of the heading;

twidth(11) sets the width of the table to 11 centimetres

title(Table 1 etc) is placed above the table

fn(Source etc) is a footnote placed below the table
准备工作要设定var lab,每个值lab

*准备工作
sysuse nlsw88, clear
la var union "Member of a union"
la def union 0 "Not a union member" ///
1 "Union member", modify
la val union union
la var south "Location"
la def south 0 "Does not live in the South" ///
1 "Lives in the South", modify
la val south south
la var race "Race"
la def race 1 "White" 2 "Black" ///
3 "Other", modify
la val race race
la var collgrad "Education"
la def collgrad 0 "Not college graduate" ///
1 "College graduate", modify
la val collgrad collgrad
la var married "Marital status"
la def married 0 "Single" 1 "Married", modify
la val married married
gen wt = 10 * runiform()
gen int fwt = ceil(wt)
gen inc = 1000 * runiform()
gen income = cond(inc < 300, inc + 360, inc +200)
la var income "Income"
gen sex = cond(wt<5, 1, 2)
la var sex "Sex"
la def sex 1 "Male" 2 "Female", modify
replace sex = cond(wt<0.5, ., sex)
la val sex sex
gen pregnant = cond(wt>8.5, 1, 2)
la var pregnant "Currently pregnant"
la def pregnant 1 "Pregnant" 2 "Not pregnant" ///
, modify
replace pregnant = cond(sex==1, ., pregnant)
la val pregnant pregnant
la var industry "Industry"
la var occupation "Occupation"
效果图

相关文章

  • stata--二维表

    什么是二维表(twoway tables) 用来统计分类变量(categories)的频数的 tab命令 二维表基...

  • Excel透视表人人都知道,可是各位职场精英们,你知道逆透视吗?

    如图所示,图中有两个表,上表是二维表。下表是一维表。 下表(一维表)转换到上表 (二维表),通过数据透视表即可实现...

  • 数据分析(谁说菜鸟不会数据分析笔记)二

    一、数据表 字段与记录组成 包括一维表和二维表,可以用数据透视表完成一维表和二维表的转换 二、数据处理 1、重复数...

  • 事实表与维度表

    前文介绍了一维表和二维表的异同及相互转换 今天再来解释一下事实表与维度表 先来看下表。回忆下,这是一维表二维表? ...

  • Excel数据清洗

    一、数据降维-二维表转一维表 方法一:数据透视表法 此方法仅适用于单行,单列的交叉二维表 1.Alt+D+P,打开...

  • 将一维表格转换成二维表,或者将二维表格转换成一维表,#E灵

    纵向排列的是一维表,同时有横标题纵标题的则是二维表,能不能将一维表和二维表相互转换呢?请看教材。

  • 2018-06-05(数据库简介)

    关系数据模型: 1.概念单一; 2.关系规范化; 3.二维表; 术语: 关系:一张二维表 元组:表中的一行 属性:...

  • 字符集和编码的区别

    字符集(Character set) 是一个系统支持的所有抽象字符的集合。通常以二维表的形式存在,二维表的内容和大...

  • MySQL表操作

    表创建 表的介绍 表是关系数据库的核心 表 = 关系 表是记录的集合 二维表格模型易于人的理解 MySQL默认存储...

  • 非关系型数据库

    关系型数据库 关系:可以理解为一张二维表,每个关系都具有一个关系名,就是通常说的表名元组:可以理解为二维表中的一行...

网友评论

    本文标题:stata--二维表

    本文链接:https://www.haomeiwen.com/subject/wvvkmctx.html