Stata备忘录
1. 画图
(1)时间趋势图
label var year "年份"
label var per "制造业增加值比重[左轴]"
label var tjj "工业增加值比重[右轴]"
graph twoway (connect per year ,yaxis(1) color(black) ) ///
(connect tjj year ,yaxis(2) color(black) lpattern(dash) ) ///
, graphregion(color(white)) xlabel(2003(2)2019) ///
ytitle("世界银行制造业增加值比重(%)",axis(1) height(5)) ///
ytitle("国家统计局工业增加值比重(%)",axis(2) height(5)) ///
note(数据来源:World Bank Open Data、国家统计局) xline(2011)

等价命令
tw (connect value1819 season , ///
lcolor(black) lpattern(dash) msymbol(O) mlcolor(gs5) mfcolor(gs12)) ///
(connect value2020 season , ///
lcolor(black) lpattern(solid) msymbol(S) mlcolor(gs5) mfcolor(gs12)) ///
,graphregion(color(white)) ///
legend(label(1 "18-19年平均") label(2 "2020年") ) ///
xlabel(1 "第一季度" 2 "第二季度" 3 "第三季度" 4 "第四季度" ,labsize(small) )
label var year "年份"
tw bar mR1 year,yaxis(2) bc(balck) sort barwidth(0.9) fintensity(inten0) ///
ylabel(0(2000)6000, axis(2)) ///
xlabel(2014(1)2021)|| ///
connect percent_R year,yaxis(1) lc(black) lp(dash) mc(blace) ///
ylabel(0.5 "50%" 0.6 "60%" 0.7 "70%" 0.8 "80%" ,axis(1)) ||, ///
graphregion(color(white) ) ///
bgcolor(white) ///
title("中国数字内容企业(游戏)收入金额及占全球市场比重", c(black) size(*0.8)) ///
ytitle("占比(%)",axis(1) height(7)) ///
ytitle("收入额(百万美元)",axis(2) height(5)) ///
legend(label(1 "中国数字内容企业(游戏)收入占全球市场比重") label(2 "中国数字内容企业(游戏)收入金额") ) ///
legend(size(small) col(1)) ///
note("数据源自:app annie")
graph save "Graph" "$path\output\playdata_1_percent_and_value_of_Chinese_Apps_Export.gph",replace

use hs_adj_year_PQV_2000_2015.dta,clear
use hs_adj_year_PQV_2000_2015_cregime10,clear
merge m:1 hs_adj using equipment
replace BEC=4 if BEC==1 & equipment!=1
destring hs_adj,replace
reghdfe lnV i.year if year!=2006 & BEC==2, a(hs)
est store result_accessories
reghdfe lnV i.year if year!=2006 & BEC==4, a(hs)
est store result_equipment
reghdfe lnV i.year if year!=2006 & BEC==0, a(hs)
est store result_noncapital
#d ;
coefplot
(result_accessories,c(l) label("accessories") lp(dash) lc(black) mc(black) ms(smcircle_hollow) offset(-0.07))
(result_equipment ,c(l) label("equipment") lp(solid) lc(black) mc(black) ms(smcircle_hollow))
(result_noncapital,c(l) label("noncapital") lp(dot) lc(black) mc(black) ms(smcircle_hollow) offset(0.07))
, vertical
drop(_cons) byopts(xrescale)
xlabel(1 "2001" 3"2003" 5"2005" 6"2007" 8"2009" 10"2011" 12"2013" 14"2015")
graphregion(color(white))
legend(size(small) col(3))
;
#d cr

字体大小 option
字体大小option | description |
---|
zero | no size whatsoever, vanishingly small |
minuscule | smallest |
quarter_tiny | |
third_tiny | |
half_tiny | |
tiny | |
vsmall | |
small | |
medsmall | |
medium | |
medlarge | |
large | |
vlarge | |
huge | |
vhuge | largest |
tenth | one-tenth the size of the graph |
quarter | one-fourth the size of the graph |
third | one-third the size of the graph |
half | one-half the size of the graph |
full | text the size of the graph |
size | any size you want |
节点样式 eg: msymbol(O) mlcolor(gs5) mfcolor(gs12)
symbolstyle | Synonym(if any) | Description |
---|
circle | O | solid |
diamond | D | solid |
triangle | T | solid |
square | S | solid |
plus | + | |
X | X | |
arrowf | A | filled arrow head |
arrow | a | |
pipe | | |
V | V | |
smcircle | o | solid |
smdiamond | d | solid |
smsquare | s | solid |
smtriangle | t | solid |
smplus | | |
smx | x | |
smv | v | |
circle_hollow | Oh | hollow |
diamond_hollow | Dh | hollow |
triangle_hollow | Th | hollow |
square_hollow | Sh | hollow |
smcircle_hollow | oh | hollow |
smdiamond_hollow | dh | hollow |
smtriangle_hollow | th | hollow |
smsquare_hollow | sh | hollow |
point | p | a small dot |
none | i | a symbol that is invisible |
线样式
linepatternstyle | Description |
---|
solid | solid line |
dash | dashed line |
dot | dotted line |
dash_dot | |
shortdash | |
shortdash_dot | |
longdash | |
longdash_dot | |
blank | invisible line |
formula | e.g.,-. or --… etc. |
A formula is composed of any combination of | |
l | solid line |
_ | (underscore) a long dash |
- | (hyphen) a medium dash |
. | short dash (almost a dot) |
# | small amount of blank space |
颜色
black | edkblue | gs12 | lime | orange |
---|
blue | eggshell | gs13 | ltblue | orange_red |
bluishgray | eltblue | gs14 | ltbluishgray | pink |
bluishgray8 | eltgreen | gs15 | ltbluishgray8 | purple |
brown | emerald | gs16 | ltkhaki | red |
chocolate | emidblue | gs2 | magenta | sand |
cranberry | erose | gs3 | maroon | sandb |
cyan | forest_green | gs4 | midblue | sienna |
dimgray | gold | gs5 | midgreen | stone |
dkgreen | gray | gs6 | mint | sunflowerlime |
dknavy | green | gs7 | navy | teal |
dkorange | gs0 | gs8 | navy8 | white |
ebblue | gs1 | gs9 | none | yellow |
ebg | gs10 | khaki | olive | |
edkbg | gs11 | lavender | olive_teal | |
(2)柱状图
#delimit ;
graph bar cn_wzje_80 cn_wzje_81 if wzlx==0, over(sec) bargap(-30)
ytitle("吸引外资金额")
legend( label(1 "08年前") label(2 "08年后") )
title("各行业吸引外资2008年前后对比")
subtitle("中国中西部服务业")
note("中国中西部服务业") ;
#delimit cr

(3)散点图
tw (scatter delta_v2_v3 delta_v1_v2 if delta_v1_v2>=-0.3& delta_v1_v2 = -0.3&delta_v2_v3=6&ks=6&ks=1400 & year