# Stata绘图：一个干净整洁的-Stata-图形模板qlean

Stata 连享会   主页 || 视频 || 推文

## 1. 导言

Stata默认的背景学名称为 light bluish gray，但通常情况下若不加以修饰，图形可能常常不能达到 使用者的审美要求 ，此时我们可以通过设定绘图模版 `scheme` 的方式来快捷更改图形的整体风格。例如，Stata官方提供了彩色模板 `s2color` 以及两个黑白模版 `s1mono``s2mono`,在我们往期推文中也曾向读者们介绍过 `tufte``burd``lean1``lean2` 等绘图模版，详见 Stata黑白图形模板：中文期刊风格的纯黑白图形。此外，现在已经可以使用外部命令 `grstyle` 随意更改 Stata 图形模板了，可通过修改设定以使其适用于期刊的黑白模式。

## 3. 应用方法

#### 3.1 散点图

``````. sysuse "auto.dta", clear
. twoway scatter price weight
. twoway scatter price weight, scheme(qlean)
. twoway scatter price weight, scheme(qleanmono)
``````

``````. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1
. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1, scheme(qlean)
. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1, scheme(qleanmono)
``````

#### 3.2 折线图

``````. sysuse uslifeexp,clear

. twoway line le_male   year || line le_female year
. twoway line le_male   year || line le_female year, scheme(qlean)
. twoway line le_male   year || line le_female year, scheme(qleanmono)
``````

#### 3.3 矩阵图

``````sysuse lifeexp, clear
gen lgnppc = ln(gnppc)
gr matrix popgr lexp lgnp safe
gr matrix popgr lexp lgnp safe, scheme(qlean)
gr matrix popgr lexp lgnp safe, scheme(qleanmono)
``````

### 3.4 条形图

``````. sysuse nlsw88, clear
. graph hbar (mean) wage, over(smsa) over(married) over(collgrad)
. graph hbar (mean) wage, over(smsa) over(married) over(collgrad) scheme(qlean)
``````

## 4. 几个推荐的黑白模版

``````. ssc install scheme_tufte, replace
. ssc install scheme-burd, replace
. net install gr0002_3.pkg
``````

``````. sysuse auto, clear
. twoway lfitci mpg weight || scatter mpg weight
``````
``````. twoway lfitci mpg weight || scatter mpg weight, scheme(qlean) mc(ply3)
``````
``````. twoway lfitci mpg weight || scatter mpg weight, scheme(tufte)
``````
``````. twoway lfitci mpg weight || scatter mpg weight, scheme(burd)
``````
``````. twoway lfitci mpg weight || scatter mpg weight, scheme(lean1)
``````
``````. twoway lfitci mpg weight || scatter mpg weight, scheme(lean2)
``````

## 5. 代码汇总

``````. sysuse "auto.dta", clear
. twoway scatter price weight
. twoway scatter price weight, scheme(qlean)
. twoway scatter price weight, scheme(qleanmono)

. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1
. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1, scheme(qlean)
. twoway scatter price weight if foreign==0 ||  scatter price weight if foreign==1, scheme(qleanmono)

. sysuse uslifeexp,clear

. twoway line le_male   year || line le_female year
. twoway line le_male   year || line le_female year, scheme(qlean)
. twoway line le_male   year || line le_female year, scheme(qleanmono)

. sysuse lifeexp, clear
. gen lgnppc = ln(gnppc)
. gr matrix popgr lexp lgnp safe
. gr matrix popgr lexp lgnp safe, scheme(qlean)
. gr matrix popgr lexp lgnp safe, scheme(qleanmono)

. sysuse nlsw88, clear
. graph hbar (mean) wage, over(smsa) over(married) over(collgrad)
. graph hbar (mean) wage, over(smsa) over(married) over(collgrad) scheme(qlean)

. ssc install scheme_tufte, replace
. ssc install scheme-burd, replace
. net install gr0002_3.pkg

. sysuse auto, clear
. twoway lfitci mpg weight || scatter mpg weight
. twoway lfitci mpg weight || scatter mpg weight, scheme(qlean) mc(ply3)
. twoway lfitci mpg weight || scatter mpg weight, scheme(tufte)
. twoway lfitci mpg weight || scatter mpg weight, scheme(burd)
. twoway lfitci mpg weight || scatter mpg weight, scheme(lean1)
. twoway lfitci mpg weight || scatter mpg weight, scheme(lean2)
``````

## 相关课程

http://lianxh.duanshu.com

### 课程一览

Stata数据清洗 游万海 直播, 2 小时，已上线

Note: 部分课程的资料，PPT 等可以前往 连享会-直播课 主页查看，下载。

#### 关于我们

• Stata连享会 由中山大学连玉君老师团队创办，定期分享实证分析经验。直播间 有很多视频课程，可以随时观看。
• 连享会-主页知乎专栏，300+ 推文，实证分析不再抓狂。
• 公众号推文分类： 计量专题 | 分类推文 | 资源工具。推文分成 内生性 | 空间计量 | 时序面板 | 结果输出 | 交乘调节 五类，主流方法介绍一目了然：DID, RDD, IV, GMM, FE, Probit 等。
• 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

✏ 连享会学习群-常见问题解答汇总：
https://gitee.com/arlionn/WD