用stata画13个变量的带平滑线的散点图
下面是使用Stata画13个变量的带平滑线的散点图的代码和示例:
sysuse auto, clear
graph twoway scatter mpg weight || lfit mpg weight, name(graph1, replace)
graph twoway scatter mpg length || lfit mpg length, name(graph2, replace)
graph twoway scatter mpg turn || lfit mpg turn, name(graph3, replace)
graph twoway scatter mpg displacement || lfit mpg displacement, name(graph4, replace)
graph twoway scatter mpg gear_ratio || lfit mpg gear_ratio, name(graph5, replace)
graph twoway scatter mpg foreign || lfit mpg foreign, name(graph6, replace)
graph twoway scatter mpg price || lfit mpg price, name(graph7, replace)
graph twoway scatter weight length || lfit weight length, name(graph8, replace)
graph twoway scatter weight turn || lfit weight turn, name(graph9, replace)
graph twoway scatter weight displacement || lfit weight displacement, name(graph10, replace)
graph twoway scatter weight gear_ratio || lfit weight gear_ratio, name(graph11, replace)
graph twoway scatter weight foreign || lfit weight foreign, name(graph12, replace)
graph twoway scatter weight price || lfit weight price, name(graph13, replace)
这个代码将数据集“auto”中的13个变量分别与“mpg”和“weight”绘制在同一张图中,每张图都带有平滑线。在Stata中,使用“||”运算符可以将多个图形组合在一起。
例如,第一个图形的代码是:
graph twoway scatter mpg weight || lfit mpg weight, name(graph1, replace)
这将“mpg”和“weight”变量的散点图组合在一起,并添加了一个平滑线。在这个命令中,“name(graph1, replace)”表示将这张图命名为“graph1”。
最终,所有13张图都会被保存在Stata的“Graph”窗口中,可以通过单击和拖动来重新排列它们。
原文地址: https://www.cveoy.top/t/topic/bqCo 著作权归作者所有。请勿转载和采集!