楼主: 匿名
20427 212

[Stata] [Stata] 如何添加直角坐标系及极坐标系及SDAS_绘图实例 [推广有奖]

101
niuniuyiwan 在职认证  发表于 2015-9-1 12:58:33
  1. clear
  2. input str14 country school1 school2 agemarriage1 agemarriage2
  3. bangladesh 3.3 4.5 14.8 15.2
  4. bolivia 6.9 7.6 19.8 20.1
  5. colombia 7.9 8.6 20.3 20.3
  6. dr 7.9 8.6 18.3 18.3
  7. egypt 5.5 7.3 18.9 19.7
  8. haiti 3.1 4.3 19.6 19.4
  9. india 3.6 4.3 16.9 17.1
  10. indonesia 5.9 7.5 18.1 19.3
  11. morocco 1.6 2.7 18.7 19.6
  12. nepal 2.4 3.6 16.9 17.4
  13. pakistan 1.5 2.8 17.9 18.4
  14. peru 8.1 8.8 20.2 20.6
  15. end

  16. set more off
  17. keep if inlist(country,"bangladesh","bolivia","colombia","dr","egypt","haiti","india","indonesia")
  18. collapse (mean) school2, by(school1 country)
  19. sort country school1
  20. generate date1=_n

  21. tsset date1  //set to time series so lag "l." and
  22.              // forward "f." operators can be used
  23.                          // see help tsvarlist
  24.                         
  25. twoway pcarrow school1 l.school1 f.school1 school1, mlab(date1) ///
  26. ytitle("This month Deg. C")                            ///
  27. xtitle("Previous month Deg. C")                        ///
  28. title("Temperature Cycle Melbourne - Deg. C")   ///
  29. subtitle("Years 1940 1950 1960 1970 2010")
复制代码

一个粗糙的例子

Graph.png

  1. insheet using "IDCJAC0002_087031_Data1.csv", clear  
  2. //or whatever data you have
  3. set more off
  4. keep if inlist(year,1940, 1950, 1960, 1970,2010)
  5. collapse (mean) MeanmaximumtemperatureC, by(month year)
  6. sort year month
  7. generate date1=_n

  8. tsset date1  //set to time series so lag "l." and
  9.              // forward "f." operators can be used
  10.                          // see help tsvarlist
  11.                         
  12. twoway pcarrow MeanmaximumtemperatureC l.MeanmaximumtemperatureC f.MeanmaximumtemperatureC MeanmaximumtemperatureC, mlab(date1) ///
  13. ytitle("This month Deg. C")                            ///
  14. xtitle("Previous month Deg. C")                        ///
  15. title("Temperature Cycle Melbourne - Deg. C")   ///
  16. subtitle("Years 1940 1950 1960 1970 2010")
复制代码

1.PNG

IDCJAC0002_087031.zip (8.16 KB) 本附件包括:

  • IDCJAC0002_087031_Data1.csv
  • IDCJAC0002_087031_Data12.csv
  • IDCJAC0002_087031_Note.txt

                                                 对元数据及do-file变量进行了修改

Graph.png







102
niuniuyiwan 在职认证  发表于 2015-9-1 13:02:37
  1. webuse nlswork, clear

  2. local ytitle "`: var label ln_wage'"

  3. set seed 2803
  4. generate rnd = runiform()
  5. bysort idcode (rnd): generate byte select = _n == 1
  6. statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N) if select, ///
  7. by(grade) clear: ci ln_wage

  8. levelsof grade, local(levels)

  9. twoway rcap ub lb grade || ///
  10. scatter mean grade, ytitle(`ytitle') legend(off) ///
  11. subtitle("95% confidence intervals for mean", place(w)) xlabel(`levels')
复制代码

Graph.png



103
niuniuyiwan 在职认证  发表于 2015-9-1 13:05:37
  1. // Controlling date labels
  2. clear

  3. input str40 time       x
  4. "5jan2011 15:00:30"    1
  5. "1feb2011 17:30:32"    2
  6. "1march2011 18:10:30"  6
  7. "1april2011 05:05:01"  2
  8. "1march2011 15:10:30"  12
  9. end
  10. list

  11. generate double time1=clock(time,"DMY hms")

  12. local t1=tc(1jan2011 12:00:0)
  13. local t2=1000*60*60*24*10
  14. local t3=tc(1may2011 12:0:0)

  15. scatter x time1, xlab(`t1'(`t2')`t3' ,                ///
  16. format(%tcddmonccyy_hh:mm) angle(45)) xtitle("Time")

  17. *(Nick Cox - Stata list,  Monday, 23 Jan 2011)
复制代码

Graph.png



104
niuniuyiwan 在职认证  发表于 2015-9-1 13:09:03
  1. // Stacked bar graph - reshaping the data

  2. //creating the data

  3. clear
  4. set obs 1000
  5. egen id = seq(), block(10)
  6. egen time = seq(), to(10)
  7. format time %tq
  8. gen time2=string(time, "%tq")
  9. gen sector = ceil(3 * runiform())
  10. bysort id: replace sector=sector[1]
  11. label define sector 1 "SECTOR 1" 2 "SECTOR 2" 3 "SECTOR 3"
  12. label values sector sector
  13. gen sales=exp(rnormal())*1000
  14. gen sales2=2*sales

  15. //reshaping the data
  16. gen obs = _n
  17. rename sales sales1
  18. reshape long sales, i(obs) j(which)

  19. graph bar (sum) sales ,  over(sector) over(which) ///
  20. over(time2, label(labsize(vsmall))) asyvars stack legend(size(vsmall))
复制代码

Graph.png



105
niuniuyiwan 在职认证  发表于 2015-9-1 13:12:08
  1. // Odds ratio graph

  2. ** requires 2 user written graphs: parmest and egenmore
  3. ** if not already installed:

  4. ssc install parmest
  5. ssc install egenmore

  6. sysuse nlsw88, clear
  7. logit union married never_married collgrad south

  8. parmest, norestore eform
  9. egen axis= axis(estimate), label(parm)

  10. twoway bar  estimate axis, base(1) horizontal barw(.5) ///
  11.             xline(1) ylab(, valuelabel angle(0)) ||    ///
  12.        rcap min95 max95 axis, horizontal               ///
  13.             legend(order(1 "point estimate"            ///
  14.                          2 "95% conf. int.") pos(6))   ///
  15.             xtitle("odds ratio") ytitle("")

  16. *(Maarten L. Buis - Statalist,  14/09/2010)
复制代码

Graph.png



106
niuniuyiwan 在职认证  发表于 2015-9-1 13:13:43
  1. // Odds ratio graph

  2. ** requires 2 user written graphs: parmest and egenmore
  3. ** if not already installed:

  4. ssc install parmest
  5. ssc install egenmore

  6. sysuse nlsw88, clear
  7. logit union married never_married collgrad south

  8. parmest, norestore eform
  9. egen axis= axis(estimate), label(parm)

  10. twoway scatter   axis estimate, ///
  11.             xline(1) ylab(, valuelabel angle(0)) ||    ///
  12.        rcap min95 max95 axis, horizontal               ///
  13.             legend(order(1 "point estimate"            ///
  14.                          2 "95% conf. int.") pos(6))   ///
  15.             xtitle("odds ratio") ytitle("")
复制代码

Graph.png



107
niuniuyiwan 在职认证  发表于 2015-9-1 13:17:13
  1. //2nd Row of axis labels

  2. webuse turksales, clear
  3. line sales t,                              ///
  4.     xtick(119.5(4)159.5, tlength(*1.5))    ///
  5.     xmlabel(120/159,                       ///
  6.         noticks format(%tqq))              ///
  7.     xlabel(121.5(4)157.5,                  ///
  8.         noticks format(%tqCY) labgap(2.5)) ///
  9.     xtitle("")

  10. *(Maarten Buis - Stata list,  Thu, 7 Nov 2013)
复制代码

Graph.png



108
niuniuyiwan 在职认证  发表于 2015-9-4 10:08:03
  1. //sequence plot  序列图
  2. *修改数据下载地址
  3. ssc install sq
  4. use http://fmwww.bc.edu/repec/bocode/y/youthemp.dta,clear
  5. reshape long st, i(id) j(order)
  6. sqset st id order
  7. sqindexplot, scheme(vg_palec)
复制代码

Graph.png



109
niuniuyiwan 在职认证  发表于 2015-9-4 10:09:03
  1. //3.asciiplot  二维码图

  2. ssc install asciiplot

  3. asciiplot       
复制代码

Graph.png



110
niuniuyiwan 在职认证  发表于 2015-9-4 10:11:02
  1. //Venn diagram using venndiag 维恩图之一

  2. ssc install venndiag

  3. clear
  4. input hayfever        eczema        asthma        freq
  5. 1        0        0        31088
  6. 1        1        0        9863
  7. 0        1        0        43522
  8. 0        1        1        9258
  9. 0        0        1        35299
  10. 1        0        1        11024
  11. 1        1        1        6200
  12. 0        0        0        345262
  13. end

  14. list

  15. expand freq

  16. venndiag asthma eczema hayfever
复制代码

fr.png



您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-7 12:42