stata备忘录

慈云数据 2024-03-13 技术支持 59 0

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) 

时间趋势图1

等价命令

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

时间趋势图2

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

时间趋势图3

字体大小 option
字体大小optiondescription
zerono size whatsoever, vanishingly small
minusculesmallest
quarter_tiny
third_tiny
half_tiny
tiny
vsmall
small
medsmall
medium
medlarge
large
vlarge
huge
vhugelargest
tenthone-tenth the size of the graph
quarterone-fourth the size of the graph
thirdone-third the size of the graph
halfone-half the size of the graph
fulltext the size of the graph
sizeany size you want
节点样式 eg: msymbol(O) mlcolor(gs5) mfcolor(gs12)
symbolstyleSynonym(if any)Description
circleOsolid
diamondDsolid
triangleTsolid
squareSsolid
plus+
XX
arrowfAfilled arrow head
arrowa
pipe
VV
smcircleosolid
smdiamonddsolid
smsquaressolid
smtriangletsolid
smplus
smxx
smvv
circle_hollowOhhollow
diamond_hollowDhhollow
triangle_hollowThhollow
square_hollowShhollow
smcircle_hollowohhollow
smdiamond_hollowdhhollow
smtriangle_hollowthhollow
smsquare_hollowshhollow
pointpa small dot
noneia symbol that is invisible
线样式
linepatternstyleDescription
solidsolid line
dashdashed line
dotdotted line
dash_dot
shortdash
shortdash_dot
longdash
longdash_dot
blankinvisible line
formulae.g.,-. or --… etc.
A formula is composed of any combination of
lsolid line
_(underscore) a long dash
-(hyphen) a medium dash
.short dash (almost a dot)
#small amount of blank space
颜色
blackedkbluegs12limeorange
blueeggshellgs13ltblueorange_red
bluishgrayeltbluegs14ltbluishgraypink
bluishgray8eltgreengs15ltbluishgray8purple
brownemeraldgs16ltkhakired
chocolateemidbluegs2magentasand
cranberryerosegs3maroonsandb
cyanforest_greengs4midbluesienna
dimgraygoldgs5midgreenstone
dkgreengraygs6mintsunflowerlime
dknavygreengs7navyteal
dkorangegs0gs8navy8white
ebbluegs1gs9noneyellow
ebggs10khakiolive
edkbggs11lavenderolive_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
微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon