—其他图形绘制一、绘制曲线图l scatter mpg weight || line hat lo hi weight, pstyle(p2 p3 p3) sort // scatter mpg weigh要求以mpg为y轴变量,weight为x轴变量绘制散点图;linehat lo hi weight, pstyle(p2 p3 p3) 要求以hat lo 和hi为y轴变量,weight为x轴变量绘制散点图;选项sort要求对weight进行排序,需要强调的是sort必须加上否则会得到没有意义的图形
l line le_wm year, yaxis(1 2) xaxis(1 2) || line le_bm year || linediff year || lfit diff year ||, ylabel(0(5)20, axis(2) gmin angle(horizontal)) ylabel(0 20(10)80, gmax angle(horizontal)) ytitle("", axis(2)) xlabel(1918, axis(2)) xtitle("",axis(2)) ylabel(, axis(2) grid) ytitle("Life expectancy at birth(years)") title("White andblack life expectancy") subtitle("USA, 1900-1999") note("Source: National Vital Statistics, Vol 50, No. 6" "(1918 dip caused by 1918Influenza Pandemic)") legend(label(1 "White males") label(2 "Blackmales")) legend(col(1)pos(3)) //1、美国男性预期寿命随时间变化的曲线标绘图;2、美国女性预期寿命随时间变化的曲线标绘图;3、美国男女预期寿命差异随时间变化的曲线标绘图4;美国男女预期寿命差异对时间的一次拟合线
二、绘制一次/二次拟合图/lowess图形l scatter mpg weight || lfit mpg weight ||, by(foreign, total row(1)) //根据分类变量foreign绘制复合图形,包括mpg和weight的散点图以及mpg和weight的一次拟合图
l scatter mpg weight || qfit mpg weight ||, by(foreign, total row(1)) //根据分类变量foreign绘制复合图形,包括mpg和weight的散点图以及mpg和weight的二次拟合图
l twoway scatter mpg weight || lfit mpg weight || lowess mpg weight,by(foreign) //根据分类变量foreign绘制复合图形,包括mpg和weight的散点图、mpg和weight的一次拟合图以及lowess修匀拟合图
三、绘制条形图l graph bar (mean) tempjuly tempjan, over(region) bargap(-30) legend(label(1 "July") label(2 "January") ) ytitle("DegreesFahrenheit")title("Average July and January temperatures")subtitle("byregions of the United States")note("Source: U.S. Census Bureau, U.S. Dept. ofCommerce") //表明对tempjuly和tempjan 均值绘制条形图,over(region)表示以变量region为分类变量,对图例的文字说明进行重新定义,对第一个条形图的文字说明是“July”,对第二个条形图的文字说明是“January”,每两个条形图之间距离降为-30
l graph bar (mean) tempjuly tempjan, over(region) over(division)nofill bargap(-30) legend( label(1 "July") label(2"January") ) ytitle("Degrees Fahrenheit")title("Average July andJanuary temperatures")subtitle("by regions of the UnitedStates")note("Source: U.S.Census Bureau, U.S. Dept. of Commerce") //表明对tempjuly和tempjan绘制条形图,over(division)over(region)表示先以division为分类变量,再以变量region为分类变量, 去掉那些没有观测值的分类