Announcement

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

  • How can I overlay curves in one graph?

    Hello,

    I need to have the trend of employment for total, male, and female in one plot. It is easy to have it for male and female using collapse, but how can I overlay the trend for total sample?

    use temp,clear
    collapse (mean) emp , by( sex year)
    twoway (connect emp year if sex==1) (connect emp year if sex==2)

    I appreciate it if somebody could help me !

  • #2
    Here is an example:

    Code:
    sysuse nlsw88, clear
    expand 2, gen(new)
    replace married = 2 if new==1
    label define marlbl 2 "total", add
    collapse (mean) wage, by(married age)
    separate wage, by(married)
    twoway line wage? age
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks a lot Maarten. I have stata 9 and it gives me this error :

      . expand 2, gen(new)
      option gen() not allowed

      Comment


      • #4
        You evidently didn't read the Advice in the FAQ!
        11. State the version of Stata used

        The current version of Stata is 13.1. Please specify if you are using an earlier version; otherwise, the answer to your question is likely to refer to commands or features unavailable to you. Moreover, as bug fixes and new features are issued frequently by StataCorp, make sure that you update your Stata before posting a query, as your problem may already have been solved.

        I don't have access to Stata 9 on this machine, but at a guess this modification of Maarten's code might work

        Code:
         
        sysuse nlsw88, clear 
        local Np1 = _N + 1 
        expand 2 
        replace married = 2 in `Np1'/L 
        label def marlbl 2 "total", add 
        collapse (mean) wage, by(married age) 
        separate wage, by(married) 
        line wage? age

        Comment

        Working...
        X