Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating graphs

    Hi everyone

    I have recently started to use Stata, and struggling to create graphs. Which codes should I use to create the attached graph? Please assist.

    Click image for larger version

Name:	graph.PNG
Views:	2
Size:	80.9 KB
ID:	1500698

  • #2
    Looks like a case for

    Code:
    help twoway connected
    to me.

    Comment


    • #3
      The data in the first graph isn't too hard to recreate, so going on Nick's advice, you want something like below. Note that you can change colors and opacity to match your preferences.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float MyVar byte Age float Year
       2.4  1 2012
         3  1 2017
       5.6  2 2012
       5.8  2 2017
      17.4  3 2012
      15.6  3 2017
      28.4  4 2012
      27.5  4 2017
        36  5 2012
      34.7  5 2017
      31.6  6 2012
      39.4  6 2017
        28  7 2012
      35.9  7 2017
      19.7  8 2012
      30.3  8 2017
      14.8  9 2012
      22.2  9 2017
       9.7 10 2012
      17.6 10 2017
       2.4 11 2012
       7.4 11 2017
      end
      label values Age age
      label def age 1 "0-14", modify
      label def age 2 "15-19", modify
      label def age 3 "20-24", modify
      label def age 4 "25-29", modify
      label def age 5 "30-34", modify
      label def age 6 "35-39", modify
      label def age 7 "40-44", modify
      label def age 8 "45-49", modify
      label def age 9 "50-54", modify
      label def age 10 "55-59", modify
      label def age 11 "60+", modify
      Code:
      tw (connect MyVar Age if Year==2012, mlab(MyVar) msize(large) ///
      xlab( 1(1)11,val))(connect MyVar Age if Year==2017, mlab(MyVar) ///
      mlabpos(9) msize(large) xlab(,val) xscale(range(0.5 11.5) noextend) ///
      scheme(s1color) leg(order(1 "2012" 2 "2017")))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	92.1 KB
ID:	1500711

      Comment


      • #4
        Thank you Nick and Andrew, besides Help on Stata is there a guide you can recommend for beginners in using Stata?

        Comment


        • #5
          The first documentation written is also the best in my view. Just keep reading [U] in the .pdf documentation.

          Comment

          Working...
          X