- 閱讀權(quán)限
- 255
- 威望
- 0 級(jí)
- 論壇幣
- 14017 個(gè)
- 通用積分
- 1902.7157
- 學(xué)術(shù)水平
- 1119 點(diǎn)
- 熱心指數(shù)
- 1167 點(diǎn)
- 信用等級(jí)
- 1061 點(diǎn)
- 經(jīng)驗(yàn)
- 8347 點(diǎn)
- 帖子
- 1625
- 精華
- 1
- 在線時(shí)間
- 2458 小時(shí)
- 注冊(cè)時(shí)間
- 2010-10-10
- 最后登錄
- 2024-11-19
學(xué)科帶頭人
還不是VIP/貴賓
- 威望
- 0 級(jí)
- 論壇幣
- 14017 個(gè)
- 通用積分
- 1902.7157
- 學(xué)術(shù)水平
- 1119 點(diǎn)
- 熱心指數(shù)
- 1167 點(diǎn)
- 信用等級(jí)
- 1061 點(diǎn)
- 經(jīng)驗(yàn)
- 8347 點(diǎn)
- 帖子
- 1625
- 精華
- 1
- 在線時(shí)間
- 2458 小時(shí)
- 注冊(cè)時(shí)間
- 2010-10-10
- 最后登錄
- 2024-11-19
| 開心 2024-4-7 06:44:11 |
---|
簽到天數(shù): 342 天 連續(xù)簽到: 5 天 [LV.8]以壇為家I
|
相似文件
換一批
經(jīng)管之家送您一份
應(yīng)屆畢業(yè)生專屬福利!
求職就業(yè)群
經(jīng)管之家聯(lián)合CDA
送您一個(gè)全額獎(jiǎng)學(xué)金名額~ !
感謝您參與論壇問題回答
經(jīng)管之家送您兩個(gè)論壇幣!
+2 論壇幣
Stata 繪圖概述(4)柱狀圖 條形圖 在實(shí)際繪圖中,柱狀圖(histogram)和條形圖(bar chart)看起來很像,但兩者其實(shí)不同。柱狀圖通常用來呈現(xiàn)變量的分布及整體趨勢(shì),而條形圖經(jīng)常用來比較變量大小。柱狀圖將數(shù)據(jù)按照一定的區(qū)間分組,而條形圖將數(shù)據(jù)分類。
| 柱狀圖 | 條形圖 | 1 | 呈現(xiàn)變量分布 | 比較變量 | 2 | 橫軸是量化數(shù)據(jù) | 橫軸是類別 | 3 | 不同柱一般不能重新排序 | 不同條可以任意重新排序 | 資料來源:http://blog.sina.com.cn/s/blog_5f234d4701019xvd.html |
- sysuse sp500, clear
- #delimit ;
- histogram volume, freq
- xaxis(1 2)
- ylabel(0(10)60, grid)
- xlabel(12321 "mean"
- 9735 "-1 s.d."
- 14907 "+1 s.d."
- 7149 "-2 s.d."
- 17493 "+2 s.d."
- 20078 "+3 s.d."
- 22664 "+4 s.d.", axis(2) grid gmax)
- xtitle("", axis(2))
- subtitle("S&P 500, January 2001 - December 2001")
- note("Source: Yahoo!Finance and Commodity Systems, Inc.")
- ;
- #delimit cr
復(fù)制代碼- sysuse sp500, clear
- #delimit ;
- histogram volume, freq normal
- xaxis(1 2)
- ylabel(0(10)60, grid)
- xlabel(12321 "mean"
- 9735 "-1 s.d."
- 14907 "+1 s.d."
- 7149 "-2 s.d."
- 17493 "+2 s.d."
- 20078 "+3 s.d."
- 22664 "+4 s.d."
- , axis(2) grid gmax)
- xtitle("", axis(2))
- subtitle("S&P 500, January 2001 - December 2001")
- note("Source: Yahoo!Finance and Commodity Systems, Inc.")
- ;
- #delimit cr
復(fù)制代碼 |
<--------grid代表網(wǎng)格
<--------添加normal代表正態(tài)曲線 | 自定義直方圖寬度的一種方法:- sysuse auto, clear
- su mpg
- local width=1
- histogram mpg ,width(`width') freq ///
- addplot(function y =`width'*`=_N'*normalden(x,`r(mean)',`r(sd)'), ra(10 45))
- sysuse auto, clear
- su mpg
- local width=2 // <-----------根據(jù)需要改變
- histogram mpg ,width(`width') freq ///
- addplot(function y =`width'*`=_N'*normalden(x,`r(mean)',`r(sd)'), ra(10 45))
- sysuse auto, clear
- su mpg
- local width=3 // <-----------根據(jù)需要改變
- histogram mpg ,width(`width') freq ///
- addplot(function y =`width'*`=_N'*normalden(x,`r(mean)',`r(sd)'), ra(10 45))
- sysuse auto, clear
- su mpg
- local width=4 // <-----------根據(jù)需要改變
- histogram mpg ,width(`width') freq ///
- addplot(function y =`width'*`=_N'*normalden(x,`r(mean)',`r(sd)'), ra(10 45))
復(fù)制代碼 |
| - //Combining many graphs on a page
- sysuse auto, clear
- graph drop _all
- drop make
- foreach i of varlist _all{
- capture confirm numeric variable `i' if _rc==0
- histogram `i', name(`i')
- local z "`z' `i'"
- graph combine `z'
- }
復(fù)制代碼 多變量直方圖的繪制,可使用循環(huán)語句,合并到同一幅圖中。 |
|
條形圖 1. 對(duì)于同一數(shù)據(jù)條形圖的繪制,由于hbar支持的標(biāo)簽長(zhǎng)度更長(zhǎng),因此使用graph hbar要比graph bar 好些。
2. 使用graph bar|hbar|box|hbox|dot 描述類別變量時(shí),選項(xiàng)為over( ) ,不是by( ) |
- sysuse citytemp, clear
- #delimit ;
- graph bar tempjuly tempjan, over(region) bargap(-30)
- legend( label(1 "July") label(2 "January") )
- ytitle("Degrees Fahrenheit")
- title("Average July and January temperatures")
- subtitle("by regions of the United States")
- note("Source: U.S. Census Bureau, U.S. Dept. of Commerce") ;
- #delimit cr
復(fù)制代碼 |
| - sysuse citytemp, clear
- #delimit ;
- graph bar tempjuly tempjan, over(region) bargap(-30)
- legend( label(1 "July") label(2 "January") )
- ytitle("Degrees Fahrenheit")
- title("Average July and January temperatures")
- subtitle("by regions of the United States")
- note("Source: U.S. Census Bureau, U.S. Dept. of Commerce")
- blabel(bar, position(inside) format(%9.1f) color(white)) ;
- #delimit cr
復(fù)制代碼 |
| - sysuse citytemp, clear
- #delimit ;
- graph bar (mean) tempjuly tempjan,
- over(division, label(labsize(*.75)))
- over(region)
- bargap(-30) nofill
- ytitle("Degrees Fahrenheit")
- legend( label(1 "July") label(2 "January") )
- title("Average July and January temperatures")
- subtitle("by region and division of the United States")
- note("Source: U.S. Census Bureau, U.S. Dept. of Commerce") ;
- #delimit cr
復(fù)制代碼 |
| - sysuse citytemp, clear
- #delimit ;
- graph hbar tempjan, over(division) over(region) nofill
- ytitle("Degrees Fahrenheit")
- title("Average January temperature")
- subtitle("by region and division of the United States")
- note("Source: U.S. Census Bureau, U.S. Dept. of Commerce") ;
- #delimit cr
復(fù)制代碼 |
| - sysuse nlsw88, clear
- #delimit ;
- graph bar wage, over(smsa, descend gap(-30)) over(married)
- over(collgrad, relabel(1 "Not college graduate" 2 "College graduate"))
- ytitle("")
- title("Average Hourly Wage, 1988, Women Aged 34-46")
- subtitle("by College Graduation, Marital Status, and SMSA residence")
- note("Source: 1988 data from NLS, U.S. Dept. of Labor, Bureau of Labor Statistics") ;
- #delimit cr
復(fù)制代碼 |
| - sysuse educ99gdp, clear
- generate total = private + public
- #delimit ;
- graph hbar (asis) public private,
- over(country, sort(total) descending) stack
- title("Spending on tertiary education as % of GDP, 1999",
- span pos(11))
- subtitle(" ")
- note("Source: OECD, Education at a Glance 2002", span) ;
- #delimit cr
復(fù)制代碼 |
|
混搭不同顏色區(qū)別變量
- clear
- input ///
- id w software mark
- 1 1 1 129
- 2 1 2 103
- 3 1 3 171
- 4 1 4 98
- 5 1 5 110
- 6 1 6 13
- 7 1 7 4
- 8 1 8 7
- 9 1 9 49
- 10 1 10 60
- end
- label define kk ///
- 1 "Stata " ///
- 2 "MATLAB®" ///
- 3 "SPSS" ///
- 4 "R" ///
- 5 "EViews" ///
- 6 "Hadoop" ///
- 7 "WinBUGs" ///
- 8 "Gauss " ///
- 9 "Python" ///
- 10 "SAS"
- label value software kk
- label define w 1 "計(jì)量經(jīng)濟(jì)學(xué)與統(tǒng)計(jì)軟件使用大調(diào)查"
- label value w w
- graph bar (asis) mark, over(id) over(software,label(angle(45))) over(w) ///
- ylabel( 0(20)190, angle(45)) ///
- blabel(bar, position(12) format(%9.0f) color(black)) ///
- scheme(s2color) legend(off) ///
- bargap(5) title({bf:萬萬個(gè)論壇幣大放送之二} ) subtitle("經(jīng)管代碼庫(kù)") ///
- nofill ytitle("投票數(shù)") ///
- bar(1, color(gold)) ///
- bar(6, color(gold)) ///
- bar(2, color(gs13)) ///
- bar(7, color(gs13)) ///
- bar(3, color(sienna)) ///
- bar(8, color(sienna)) ///
- bar(4, color(cyan)) ///
- bar(9, color(cyan)) ///
- bar(5, color(pink)) ///
- bar(10, color(pink))
復(fù)制代碼 |
掃碼加我 拉你入群
請(qǐng)注明:姓名-公司-職位
以便審核進(jìn)群資格,未注明則拒絕
|
|
-
總評(píng)分: 經(jīng)驗(yàn) + 100
論壇幣 + 100
學(xué)術(shù)水平 + 5
熱心指數(shù) + 5
信用等級(jí) + 5
查看全部評(píng)分
|