Announcement

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

  • How to create graph

    Hello,

    I was wondering if anyone could tell me how to create a graph that's similar to this one. I would like a different line for each ethnicity, and would like the x axis to be different time periods (I have 25 quarters) and the y axis to be the mean of hourly pay. Thanks for any help!



    Click image for larger version

Name:	Screen Shot 2018-12-09 at 20.08.19.png
Views:	1
Size:	134.2 KB
ID:	1487748

  • #2
    Code:
    help twoway connected
    For better advice, please give a data example (FAQ Advice #12).

    Comment


    • #3
      Thanks for your help! Sorry I've only recently joined statalist and am new to stata so I will try my best to give an example!
      I have around 60,000 observations that consists of 7 different ethnicities. I have 25 quarters starting from Q3 2012 - Q3 2018. I would like to create a connected line graph where each point on the line represents mean hourly pay of all observations of that ethnicity in each quarter, and would like there 2 be 7 lines, one to represent each ethnicity. I have hourly pay for each observation, their ethnicity and the quarter the question was asked in.
      Hope this is clear, and again thanks so much for any help provided!

      Comment


      • #4
        FAQ Advice #12 means https://www.statalist.org/forums/help#stata which explains what we mean by a data example. Being new is more than fine, but extra reason to study the FAQ Advice as requested.

        Consider this example which you can type in your Stata:

        Code:
        . webuse grunfeld, clear 
        
        . egen wanted = mean(invest), by(company year)
        
        . separate wanted, by(company) veryshortlabel
        
                      storage   display    value
        variable name   type    format     label      variable label
        --------------------------------------------------------------------------------------------------------------------------------------------------
        wanted1         float   %9.0g                 1
        wanted2         float   %9.0g                 2
        wanted3         float   %9.0g                 3
        wanted4         float   %9.0g                 4
        wanted5         float   %9.0g                 5
        wanted6         float   %9.0g                 6
        wanted7         float   %9.0g                 7
        wanted8         float   %9.0g                 8
        wanted9         float   %9.0g                 9
        wanted10        float   %9.0g                 10
        
        twoway connected wanted1-wanted7 year , ysc(log) yla(10 20 50 100 200 500 1000, ang(h)) ytitle(invest)
        For the Grunfeld data the egen step is silly as invest is already a single value for each company and year. But the corresponding step is vital in your case to get means by ethnicity and quarter.

        Some of the graph details are naturally specific to the data example, but logarithmic scale is often a good idea for pay or salaries, although perhaps not so much in your case.

        Similarly I would want to compare means with (e.g.) geometric means or medians. but the procedure is similar.

        Comment


        • #5
          Thanks so much for all your help! My apologies, I'll read the FAQ advice now.

          Comment

          Working...
          X