stata--二維表

什么是二維表(twoway tables)

用來統(tǒng)計(jì)分類變量(categories)的頻數(shù)的

tab命令

二維表基礎(chǔ)命令,統(tǒng)計(jì)一個變量叫一維表,兩個變量叫二維表。
tab后跟的第一個變量可以認(rèn)為是“垂直變量”,第二個變量可以認(rèn)為是“水平變量”。

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
準(zhǔn)備工作要設(shè)定var lab,每個值lab

*準(zhǔn)備工作
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"
效果圖
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容