设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5410|回复: 0

Stata绘图:简单好用的37条外部命令

[复制链接]

36

主题

201

金钱

340

积分

入门用户

发表于 2019-6-12 16:07:01 | 显示全部楼层 |阅读模式

aaplot
用于散点的线性或二次拟合,显示拟合方程及R方
1.jpg
示例:
  1. *安装
  2. ssc install aaplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. gen gpm = 1000 / mpg
  6. label var gpm "Gallons per thousand miles"
  7. *拟合
  8. aaplot gpm weight, name(plot)
复制代码


beamplot
用于以均值为支点的“跷跷板”图示
2.jpg
示例:
  1. *安装
  2. ssc install beamplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制以均值为支点的“跷跷板”
  6. beamplot mpg, by(foreign) over(rep78)
复制代码


bihist
绘制双变量双向直方图
3.jpg
示例:
  1. *安装
  2. ssc install bihist
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *以汽车里程数分组,绘制车型的双向直方图
  6. bihist mpg, by(foreign)
复制代码


binscatter
解决大样本情况下,散点图过于拥挤无法直观解释的问题
4.jpg
示例:
  1. *安装
  2. ssc install binscatter
  3. *导入1988年女性调查的数据
  4. sysuse nlsw88, clear
  5. keep if inrange(age,35,44) & inrange(race,1,2)
  6. *工作年限和工资之间的关系
  7. scatter wage tenure,title("Graph produced by Scatter") name(plot1)
  8. binscatter wage tenure
  9. *二次拟合
  10. binscatter wage tenure, line(qfit) xscale(range(0,25)) xlabel(0(5)25) ylabel(0(10)40) yscale(range(0,40)) title("Graph produced by Binscatter") name(plot2)
  11. graph combine plot1 plot2
复制代码


byhist
绘制双变量单向直方图
5.jpg
示例:
  1. *安装
  2. ssc install byhist
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *以汽车里程数分组,绘制车型的单向直方图
  6. byhist mpg, by(foreign)
复制代码


catplot
显示变量的频率或百分比
7.jpg
8.jpg
示例:
  1. *安装
  2. ssc install catplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *指定分类
  6. gen himpg = mpg > 25
  7. label def himpg 1 "mpg > 25" 0 "mpg <= 25"
  8. label val himpg himpg
  9. *绘制直方图
  10. catplot himpg rep78 foreign
  11. *绘制直方图
  12. catplot  rep78, over(for) stack asyvars  perc(for) blabel(bar, position(center) format(%3.1f)) legend(off)
复制代码


cbarplot
显示频率的中心条状图
8.jpg
示例:
  1. *安装
  2. ssc install cbarplot
  3. *输入数据
  4. clear
  5. input levels freqcores freqblanks freqtools
  6. 25 21 32 70
  7. 24 36 52 115
  8. 23 126 650 549
  9. 22 159 2342 1633
  10. 21 75 487 511
  11. 20 176 1090 912
  12. 19 132 713 578
  13. 18 46 374 266
  14. 17 550 6182 1541
  15. 16 76 846 349
  16. 15 17 182 51
  17. 14 4 51 14
  18. 13 29 228 130
  19. 12 135 2227 729
  20. end
  21. reshape long freq, i(levels) j(kind) string
  22. *以百分比形式显示频率
  23. cbarplot levels kind [fw=freq], percent(levels)
复制代码


cdfplot
绘制样本累积分布函数
9.jpg
示例:
  1. *安装
  2. ssc install cdfplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *以车长分组,为车型的值指定单独的样本累积分布函数
  6. cdfplot length [fw=rep78], by(foreign) norm saving(mygraph,replace)
复制代码


ciplot
显示均值和置信区间
10.jpg
示例:
  1. *安装
  2. ssc install ciplot
  3. *导入美国城市的气温数据
  4. sysuse citytemp, clear
  5. *绘制置信区间
  6. ciplot heatdd cooldd, by(division) xla(, ang(45))
  7. cmogram
复制代码


以某变量为条件,显示另一变量的均值、中位数、频数、比例
11.jpg
示例:
  1. *安装
  2. ssc install cmogram
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *以车重为条件,控制汽车价格,显示汽车里程数的均值
  6. cmogram mpg weight, histopts(bin(5)) lfit cutpoint(3250) lineat(3000 3250 3500) controls(price)
复制代码



cpyxplot
绘制指定变量之间的交叉散点图
12.jpg
示例:
  1. *安装
  2. ssc install cpyxplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制车型与维修记录、与里程数、与车圈、与车长的散点图
  6. cpyxplot foreign \rep78 mpg turn length
复制代码


cvxhull
绘制凸包图
13.jpg
示例:
  1. *安装
  2. ssc install cvxhull
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. gen foreign1=foreign
  6. label define for 1 For 0 Dom
  7. label values  foreign1 for
  8. *在散点图中显示汽车里程数的范围及每一个标有组值的点,每组观测值将计算出最多2层hull并共享一个组值
  9. cvxhull  mpg weight, group(foreign) hulls(2) scat(mlab(foreign1) mlabpos(c) msym(i) ysc(r(0,60)))
复制代码


cycleplot
把时间序列数据中每个周期的值垂直地绘制出来
14.jpg
示例:
  1. *安装
  2. ssc install cycleplot
  3. *导入美国GNP数据
  4. use "D:\us_gnp.dta", clear
  5. *按季度分解
  6. cycleplot gnp96 quarter year, length(4)
复制代码


devnplot
显示数据的平均值偏离
15.jpg
示例:
  1. *安装
  2. ssc install devnplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *依维修记录分组标记汽车里程数的数值及其均值
  6. devnplot mpg rep78
复制代码


drarea
用不同颜色解决区域重叠覆盖的问题
16.jpg
示例:
  1. *安装
  2. ssc install drarea
  3. *导入标普500指数数据
  4. sysuse sp500, clear
  5. generate high2 = high+15*uniform()
  6. generate low2 = low+15*uniform()
  7. *分颜色绘图
  8. drarea high low high2 low2 date in 1/20
复制代码


eclplot
标记置信区间
17.jpg
示例:
  1. *安装
  2. ssc install eclplot
  3. ssc install parmest
  4. ssc install sencode
  5. *导入1978年汽车交易的数据
  6. sysuse auto, clear
  7. *创建一个输出数据集
  8. parmby "xi:regress mpg i.foreign i.rep78", label norestore
  9. *创建一个带有值标签的数值变量
  10. sencode parm,gene(parmid)
  11. *使用参数标签来标记垂直置信区间
  12. eclplot estimate min95 max95 parmid
复制代码


ellip
绘制置信椭圆
18.jpg
示例:
  1. *安装
  2. ssc install ellip
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制置信椭圆
  6. ellip mpg weight, by(foreign, total legend(off)) total tlabel(Total as a by-group) plot(scatter mpg weight)
复制代码


grcomb
组合相同类型的多个图
19.jpg
示例:
  1. *安装
  2. ssc install grcomb
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *同时显示汽车价格、里程数、维修记录及发动机排量的箱线图
  6. grcomb graph box price mpg rep78 displacement, v(1)
复制代码


hangroot
检查数据分布
20.jpg
示例:
  1. *安装
  2. ssc install hangroot
  3. *导入1988年女性调查的数据
  4. sysuse nlsw88, clear
  5. *绘制收入的分布曲线
  6. hangroot wage,bar
复制代码


hmap
绘制热图
21.jpg
示例:
  1. *安装
  2. ssc install hmap
  3. *输入数据
  4. clear all
  5. set obs 64
  6. generate n=int(uniform()*10)
  7. generate x=1+int((_n-1)/8)
  8. generate y=1+mod((_n-1),8)
  9. label define xlab 1 "one" 2 "two" 7 "seven" 8 "eight"
  10. label define ylab 3 "three" 4 "four" 5 "five" 6 "six"
  11. label value x xlab
  12. label value y ylab
  13. table y x [fw=n]
  14. *绘制热图
  15. hmap x y n
复制代码


linkplot
显示成对数据的结构
22.jpg
示例:
  1. *安装
  2. ssc install linkplot
  3. *输入10个男孩的A和B材料鞋子的数据(Box,Hunter and Hunter,1978)
  4. input A B id
  5. 13.2 14.0 1
  6. 8.2 8.8 2
  7. 10.9 11.2 3
  8. 14.3 14.2 4
  9. 10.7 11.8 5
  10. 6.6 6.4 6
  11. 9.5 9.8 7
  12. 10.8 11.3 8
  13. 8.8 9.3 9
  14. 13.3 13.6 10
  15. end
  16. rename A wearA
  17. rename B wearB
  18. reshape long wear, string i(id) j(j)
  19. encode j, gen(material)
  20. *链接成对数据
  21. linkplot material wear, link(id) yla(1 2, valuelabel) ysc(r(0.5 2.5)) yla(, ang(h))
复制代码


netplot
生成社会网络分析的网络图
23.jpg
示例:
  1. *安装
  2. ssc install netplot
  3. *导入社会网络数据
  4. sysuse network1a,clear
  5. *生成网络图
  6. netplot x_c y_c, label
复制代码


pdplot
绘制帕累托图
24.jpg
示例:
  1. *安装
  2. ssc install pdplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制汽车里程数的帕累托图
  6. pdplot mpg
复制代码


plotmatrix
绘制矩阵图
25.jpg
示例:
  1. *安装
  2. ssc install plotmatrix
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *线性回归
  6. reg price mpg trunk weight length turn, nocons
  7. mat regmat = e(V)
  8. *绘制矩阵
  9. plotmatrix, m(regmat) c(red) ylabel(,angle(0))
复制代码


sixplot
显示单变量的六种数据诊断及描述性统计图
26.jpg
示例:
  1. *安装
  2. ssc install sixplot
  3. *导入预期寿命数据
  4. sysuse uslifeexp,clear
  5. *生成男性预期寿命的统计图
  6. sixplot le_male
复制代码


spineplot
使图的宽度与频率呈比例
27.jpg
示例:
  1. *安装
  2. ssc install spineplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制直方图
  6. spineplot foreign rep78
复制代码


spmap
绘制等值线地图、比例符号地图等地图
28.jpg
示例:
  1. *安装
  2. ssc install spmap
  3. *导入意大利地图数据
  4. use "D:\Italy-RegionsData.dta", clear
  5. *绘制意大利地图
  6. spmap relig1 using "D:\Italy-RegionsCoordinates.dta", id(id)
复制代码


statplot
在不借助图例的情况下,使用坐标轴标记数据
29.jpg
示例:
  1. *安装
  2. ssc install statplot
  3. *导入人口调查的数据
  4. sysuse census, clear
  5. *显示不同地区的结婚数与离婚数
  6. statplot marriage divorce, over(region) s(sum) xpose
复制代码


stripplot
绘制航线图
30.jpg
31.jpg
32.jpg
示例:
  1. *安装
  2. ssc install stripplot
  3. *导入血压数据
  4. sysuse bplong, clear
  5. egen group = group(age sex), label
  6. *绘制航线图
  7. stripplot bp*, bar over(when) by(group, compact col(1) note("")) ysc(reverse) subtitle(, pos(9) ring(1) nobexpand bcolor(none) placement(e)) ytitle("") xtitle(Blood pressure (mm Hg))
  8. *导入1978年汽车交易的数据
  9. sysuse auto, clear
  10. *绘制航线图
  11. stripplot mpg, over(rep78) stack h(0.5) bar(lcolor(red))
  12. *绘制航线图
  13. gen pipe = "|"
  14. stripplot price, over(rep78) box(barw(0.3)) ms(none) mla(pipe) boffset(0.3)
复制代码


tabplot
直方图的列联表示
33.jpg
示例:
  1. *安装
  2. ssc install tabplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制车型与维修记录的列联表
  6. tabplot foreign rep78, percent(foreign)
复制代码


tddens
绘制网格上的双变量核密度图
34.jpg
示例:
  1. *安装
  2. ssc install tddens
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制汽车价格和里程数的双变量核密度图
  6. tddens price mpg, s b
复制代码


triplot
绘制三个变量的百分比
35.jpg
示例:
  1. *安装
  2. ssc install triplot
  3. *输入数据
  4. clear
  5. input a1 a2 a3 str10 name
  6. 0.10 0.10 0.80 John
  7. 0.80 0.10 0.10 Fred
  8. 0.25 0.25 0.50 Jane
  9. 0.90 0.5 0.5 Helen
  10. 0.10 0.20 0.70 Ed
  11. 0.50 0.25 0.25 Kate
  12. 0.20 0.60 0.20 Michael
  13. 0.25 0.25 0.50 Darren
  14. 0.5 0.90 0.5 Samar
  15. end
  16. *绘制三角图
  17. triplot a1  a2  a3, mlab(name)
复制代码


vioplot
绘制小提琴图
36.jpg
示例:
  1. *安装
  2. ssc install vioplot
  3. *导入1978年汽车交易的数据
  4. sysuse auto, clear
  5. *绘制小提琴图
  6. vioplot mpg, over(rep78) horizontal name(myplot)
复制代码


zmap
定义笛卡尔坐标,特别针对空间数据的处理
37.jpg
示例:
  1. *安装
  2. ssc install zmap
  3. *导入1988年女性调查的数据
  4. sysuse nlsw88, clear
  5. *生成工资、当前职级与年龄的直角坐标系
  6. zmap wage age grade, ms(S ..) ysc(on) xsc(on)
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表