stata常用作图指令包你满意
Stata Stata 作图常用指令作图常用指令
SStata tata 作图常用指令作图常用指令
1.茎叶图1.茎叶图
1.1.茎叶图茎叶图
stem x1,line(2)
(做x1的茎叶图,每一个十分位的树茎都被拆分成两段来显示,前半段为0~4,
后半段为5~9)
stem x1,width(2)
(做 x1 的茎叶图,每一个十分位的树茎都被拆分成五段来显示,每个小树茎的
组距为2)
stem x1,round(100)
(将x1除以100后再做x1的茎叶图)
2.直方图2.直方图
2.2.直方图直方图
histogram mpg, discrete frequency normal xlabel(1(1)5)
(discrete 表示变量不连续,frequency 表示显示频数,normal 加入正太分布
曲线,xlabel设定x轴,1和 5为极端值,(1)为单位)
histogram price, fraction norm
(fraction 表示 y 轴显示小数,除了 frequency 和 fraction 这两个选择之外,
该命令可替换为“percent”百分比,和“density”密度;未加上 discrete 就
表示将price当作连续变量来绘图)
histogram price, percent by(foreign)
(按照变量“foreign”的分类,将不同类样本的“price”绘制出来,两个图分
左右排布)
histogram mpg, discrete by(foreign, col(1))
(按照变量“foreign”的分类,将不同类样本的“mpg”绘制出来,两个图分上
下排布)
histogram mpg, discrete percent by(foreign, total) norm
(按照变量“foreign”的分类,将不同类样本的“mpg”绘制出来,同时绘出样
本整体的“总”直方图)
3.二变量图3.二变量图
3.3.二变量图二变量图
graph twoway lfit price weight || scatter price weight
(作出price和weight的回归线图——“lfit”,然后与price 和weight的散
点图相叠加)
twoway scatter price weight,mlabel(make)
(做price和weight的散点图,并在每个点上标注“make”,即厂商的取值)
twoway scatter price weight || lfit price weight,by(foreign)
(按照变量 foreign 的分类,分别对不同类样本的 price 和 weight 做散点图和
回归线图的叠加,两图呈左右分布)
twoway scatter price weight || lfit price weight,by(foreign,col(1))
(按照变量 foreign 的分类,分别对不同类样本的 price 和 weight 做散点图和
回归线图的叠加,两图呈上下分布)
twoway scatter price weight [fweight= displacement],msymbol(oh)
(画出price和weight的散点图,“msybol(oh)”表示每个点均为中空的圆圈,
[fweight= displacement]表示每个点的大小与displacement的取值大小成比例)
twoway connected y1 time, yaxis(1) || y2 time, yaxis(2)
(画出 y1 和 y2 这两个变量的时间点线图,并将它们叠加在一个图中,左边
“yaxis(1)”为y1的度量,右边“yaxis(2)”为y2的)
twoway line y1 time,yaxis(1) || y2 time,yaxis(2)
(与上图基本相同,就是没有点,只显示曲线)
graph twoway scatter var1 var4 || scatter var2 var4 || scatter var3 var4
(做三个点图的叠加)
graph twoway line var1 var4 || line var