Announcement

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

  • How to create a line chart of two groups in panel data

    Hi

    I have a dataset of 160,000 companies, over a timespan of 16 years. The companies are "divided" by a dummy variable for "1=rich CEOs" and "0=poor CEOs". What i would like to do is to create a chart where i can see the development of the Revenues of the mean of the two groups over the period. Why i imagine is: y axis= Revenue, x axis=year, and two lines comparing the rich and poor CEOs.

    I have already tried xtline and lgraph commands but cand seem to figure them out...

    Any help is much appreciated.

  • #2

    Code:
    egen mean_revenue = mean(revenue), by(dummy year) 
    egen tag = tag(dummy year) 
    line mean_revenue year if tag & dummy == 1, sort || line mean_revenue year if tag & dummy == 0, legend(order(1 "rich CEOs" 2 "poor CEOs") ring(0) pos(11) col(1))

    Comment


    • #3
      Thank you Nick!
      This is exactly how I want the setup to be, but I don't get why there's not a singular line of the dummy variable "poor"
      Do you have any idea of what i can do to fix this... :/ ?

      Click image for larger version

Name:	Skjermbilde 2018-05-31 kl. 10.21.07.png
Views:	1
Size:	339.2 KB
ID:	1446884

      Comment


      • #4
        Evidently you need the sort option on both line calls. Also, my guess was wrong that there would be space for the legend in the top left-hand corner.

        I have also to suggest that you should rethink taking means here. The vast difference implies to me analysis on logarithmic scale and thus geometric means as a better summary. I don't know what currency units you're dealing with, hence whatever in what is below.


        Code:
        egen gmean_revenue = mean(ln(revenue)), by(dummy year)  
        replace gmean_revenue = exp(gmean_revenue)  
        egen tag = tag(dummy year)
        
        line gmean_revenue year if tag & dummy == 1, sort || line gmean_revenue year if tag & dummy == 0, sort ///
        ysc(log) yla(1e7 "10" 5e6 "5" 2e6 "2" 1e6 "1" , ang(h)) ytitle(Geometric mean revenue (million whatever)) ///
        legend(order(1 "rich CEOs" 2 "poor CEOs")) xtitle("")

        Comment


        • #5
          I get this:
          Is there anything I would need to define before I un this?

          Thank you!!
          Click image for larger version

Name:	Skjermbilde 2018-05-31 kl. 12.42.19.png
Views:	1
Size:	43.1 KB
ID:	1446912

          Comment


          • #6
            In interactive mode the /// need to be omitted. The last three lines are all one command. Alternatively run the code from a do-file editor window.

            Comment

            Working...
            X