twoway (scatter d size , msymbol(Oh)) , title(\债务与企业规模\//同时用图与曲线选项 命令可以简写,如下列命令等价 sysuse auto, clear
graph twoway scatter d size
twoway scatter d size //graph可以省略 scatter d size //twoway graph都可以省略 gr tw sc d size tw sc d size sc d size
8.2.2 曲线类型
STATA 提供各种曲线类型,包括点(scatter)、线(line)、面(area),直方图(histogram)、 条形图(bar)、饼图(pie)、函数曲线(function)以及矩阵图(matrix)等。对时间序列数据有以ts 开头的一系列特殊命令,如tsline。还有一类是对双变量的回归拟合图(lfit、qfit 、lowess)等。可以用帮助命令查看。 help graph
help towway
(1)曲线从大的方面可以分为点线面,在同一个图中可以容纳多条曲线,甚至是不同类型 的曲线。先来看单个曲线类型。
例5:数据集d.dta 中有5904个样本,其中变量d为企业的杠杆水平,year 为年份(1998-2006),画出公司代码dm为2的各年杠杆水平的散点图、折线图和面积图, 点
use \桌面\\d.dta\ , clear scatter d year if dm==2
线
line d year if dm==2,sort
面
tw area d year if dm==2,sort
(2)几种基本的曲线类型
任务9.2:使用中国上市公司的杠杆水平d、公司规模size 及公司成长性growth和公司性质(是否是中央控股企业),公司所处的行业sic2(证监会所处行业标志) 等变量绘制各种图,数据文件为type_f.dta。
use \桌面\\d.dta\ ,clear 直方图:histogram twoway histogram d
核估计图: kdensity twoway kdensity d
条形图:bar 和hbar graph bar d, over(sic2)
graph hbar d, over(sic2)
箱形图box 和hbox graph hbox d, over(sic2)
graph box d, over(sic2)
饼图:pie
graph pie d, over(sic2)
矩阵图 matrix
graph matrix d size growth
点阵图 dot
graph dot d, over(sic2)
(3)更多细分的曲线类型
例5:使用浦发银行(股票代码为600000)的2008年8月股价数据ret.dta绘制各种图,其中tclose 为收盘价,topen 为开盘价,tdate 为交易日,year为年份,month为月份,date为日期,high为当日最高股价,low为当日最低股价。 use \桌面\\ret.dta\
twoway dropline tclose date if month==8 //2008年8月浦发银行的股价图