搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  矩阵关系图、循环语句图.rar
资料下载链接地址: https://bbs.pinggu.org/a-1842379.html
本附件包括:
  • 矩阵关系图、循环语句图.do
附件大小:
838 Bytes   举报本内容

Stata 12 Graphics

Dawn Koffman

Office ofPopulation Research

Princeton University



输入数据,修改标签

  1. clear
  2. inputstr14 country tvhome birth5years idealnum age1stbirth school agemarriage
  3. bangladesh 33.9 .6 2.3 17.7 4.5 15.2
  4. bolivia 74.8 .8 2.6 20.3 7.6 20.1
  5. colombia 93.4 .4 2.4 20.7 8.6 20.3
  6. dr 83 .5 3.2 19.9 8.6 18.3
  7. egypt 95.9 .7 2.9 21.3 7.3 19.7
  8. haiti 27.9 .8 3.2 20.7 4.3 19.4
  9. india 47.9 .6 2.4 19.2 4.3 17.1
  10. indonesia 74 .5 2.8 20.7 7.5 19.3
  11. morocco 66.6 .7 3.3 21.4 2.7 19.6
  12. nepal 50.7 .6 2.2 19.6 3.6 17.4
  13. pakistan 57.8 .9 4.1 20.5 2.8 18.4
  14. peru 78.1 .6 2.5 21.1 8.8 20.6
  15. end
复制代码
  1. label variable tvhome "TV at home (%)"
  2. label variable school "years of school"
  3. label variable birth5years "births in last 5 years"
  4. label variable idealnum "ideal number of children"
  5. label variable age1stbirth "age at first birth"
  6. label variable school "years of school"
  7. label variable agemarriage "age at first marriage"
复制代码
变量标签

矩阵关系图:

基本格式 graph matrix variable1 variable2 variable3, graph_options

Graph options:
  1. /*
  2. half 展示一半,分析对比较易
  3. by(groupingvariable) 使用分组变量,注意先排序
  4. jitter(#) 大数据集用
  5. 技巧:msymbol(p) 数据集较大时 point
  6. msize(choice) 标记符号 [可选vtiny,tiny,small,medsmall,medium,medlarge,huge,vhuge,large,vlarge,ehuge]
  7. */
复制代码
  1. #delimit ;
  2. local note"Source: Most recent DHS std survey: bangladesh bolivia colombia dr egypt
  3. haiti india indonesia morocco nepal pakistan peru, as of 5/2013";
  4. graph matrix school tvhome idealnum agemarriage age1stbirth birth5years,
  5. half note("`note'", size(vsmall));
  6. #delimit cr
复制代码

关闭half,显示另一半


  1. #delimit ;
  2. local note"Source: Most recent DHS std survey: bangladesh bolivia colombia dr egypt
  3. haiti india indonesia morocco nepal pakistan peru, as of 5/2013";
  4. graph matrix school tvhome idealnum agemarriage age1stbirth birth5years,
  5. note("`note'", size(vsmall));
  6. #delimit cr
复制代码



使用循环语句画图:

  1. #delimit ;
  2. local sample MARRIED;
  3. local note"Source: Most recent DHS standard survey, as of 5/2013"; foreach x in school tvhome {;
  4. foreach y in idealnum agemarriage age1stbirth birth5years {;
  5. twoway scatter `y' `x', mlabel(country) mlabsize(large) ylabel(, angle(0)) note("`note'") name("`x'_`y'", replace); graph export `x'_`y'_`sample'_mostrecent.emf, replace;
  6. };
  7. };
  8. #delimit cr
复制代码
将多个直方图同时保存到一张图的方法:
  1. //Combining many graphs on a page
  2. sysuse auto, clear
  3. graph drop _all
  4. drop make
  5. foreach i of varlist _all{
  6. capture confirm numeric variable `i' if _rc==0
  7. histogram `i', name(`i')
  8. local z "`z' `i'"
  9. graph combine `z'
  10. }
复制代码


3.核密度图
  1. clear all
  2. sysuse auto
  3. kdensity length, bw(20)
复制代码
叠加核密度图方法一:(https://bbs.pinggu.org/thread-3606957-1-1.html)感谢蓝色版主
  1. sysuse auto,clear
  2. kdensity priceif foreign==0 ,addplot( ///
  3. kdensity priceif foreign==1 ) ///
  4. legend(label(1 "国内") label(2 "国外") col(2))
复制代码
叠加核密度图方法二:
  1. sysuse auto,clear

  2. tw (kdensity priceif foreign==0) ///
  3. (kdensity priceif foreign==1) , ///
  4. legend(label(1 "国内") label(2 "国外") col(2))
复制代码



面积图:注:只有在线图下的面积部分具有理论及分析意义时使用。
  1. sysuse auto, clear
  2. summarize price, mean
  3. local mean = r(mean)
  4. kdensity price, gen(x h)
  5. line h x, || area h x ifx < `mean'
复制代码

  1. sysuse gnp96, clear
  2. #delimit ;

  3. twoway area d.gnp96 date, xlabel(36(8)164, angle(90))
  4. ylabel(-100(50)200, angle(0))
  5. ytitle("Billions of 1996 Dollars")
  6. xtitle("")
  7. subtitle("Change in U.S. GNP", position(11))
  8. note("Source: U.S. Department of Commerce, Bureau of Economic Analysis")
  9. ;
  10. #delimit cr
复制代码





//左右同时浮现且保持标题简洁的操作技巧:
//添加xtitle("")
  1. sysuse auto,clear
  2. sort foreign
  3. set scheme lean1
  4. histogram rep78, discrete by(foreign) percent ///
  5. addlabels xlabel(1 "1" 2 "2" 3 "3" 4 "4" 5 "5") ///
  6. gap(25) title("Repair Record in 1978") xtitle("")
复制代码


在下端回避Repair Record in 1978








    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

GMT+8, 2026-1-2 10:34