Announcement

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

  • Drawing a line graph that shows the mean of a variable

    Good afternoon everyone,
    I am completely new to Stata and I have been struggling for many hours trying to find an answer to my question until I decided to address the Stata forum.

    I have performed an event study and calculated cumulative abnormal returns (CARs) for both target and acquiring firms, for each day of the event window -5, +5. I would like to display on a line graph, the average CAR for acquirers for each day of the event window and the average CAR for targets on another graph. Could you please help me figure out a command line to perform such action. I would be also curious to know the command to show both the acquirer and target on the same graph.

    Please find attached a screenshot of what my dataset looks like: the variable "event_day" should be used for the x-axis, and "car" for the y-axis.
    Please find also attached of the kind of output I am trying to reach.

    Thank you very much for your help.

    Aurélien


    Click image for larger version

Name:	Screen Shot 2016-08-22 at 20.46.21.png
Views:	1
Size:	52.0 KB
ID:	1353994 Click image for larger version

Name:	Screen Shot 2016-08-22 at 20.53.02.png
Views:	1
Size:	16.2 KB
ID:	1353993

  • #2
    Please read the FAQ, especially #12, for information about how to show example data in a more useful way than a screen shot of the browse window. (If I want to experiment with your data, first I have to click on the screenshot to make it large enough to be readable. But doing that obscures everything else in your post, so going back and forth between them is a pain But once I've done that, I can't copy your data and paste it into my Stata to experiment with. In the future, please use -dataex- to post results. You can install the -dataex- command from SSC and -help dataex- will explain how to use it.

    Since I can't really use your data as an example, I'll show you how to do it using the built-in auto-data set. In this example, foreign plays the role of your Target vs Acquirer variable, price plays the role of your CAR, and rep78 plays the role of your day variable. The first two -graph commands- plot the two curves separately. The last one puts them both on the same graph.

    Code:
    clear*
    sysuse auto
    
    collapse (mean) price, by(foreign rep78)
    
    graph twoway line price rep78 if foreign == 0, name(graph0, replace)
    graph twoway line price rep78 if foreign == 1, name(graph1, replace)
    
    separate price, by(foreign)
    graph twoway line price0 price1 rep78, name(graph_both, replace)
    ​​​​​​​While in this example foreign plays the role of your variable firm, foreign is a numeric variable, whereas firm appears to be a string (I'm guessing because it shows up reddish brown in the screenshot.) So instead of -foreign == 0- you will need -firm == "Target"-, with the quote marks.
    ​​​​​​​

    Comment


    • #3
      Hello Clyde,
      Apologies for how I presented my example data, I will take into account from now on!
      Thank you very much for your fast and clear answer, it works perfectly. For the second command (which plots the two curves on the same graph), I have just added an extra line to collapse both "price" variables, as follows:
      Code:
      separate price, by(foreign)  
      collapse (mean) price0 price1, by(foreign)  
      graph twoway line price0 price1 rep78, name(graph_both, replace)
      Thanks a lot for your help, it is much appreciated!

      Comment


      • #4
        Here's another approach that does not require use of -collapse-, and therefore, the original data remain available for use afterwards (without re-opening the file).

        Code:
        clear
        sysuse auto
        quietly anova price foreign##rep78 // Estimate a two-way (foreign x rep78) ANOVA model
        quietly margins rep78#foreign // Get the cell means
        marginsplot, noci ytitle(Mean Price) // Plot the cell means
        Here's a somewhat lengthier version. It shows that means obtained via the -mean- command match the cell means from -anova-.

        Code:
        clear
        sysuse auto
        
        // Generate a table of the means:
        mean price, over(rep78 foreign)
        // Now use -margins- to get the cell means from a two-way ANOVA:
        quietly anova price foreign##rep78
        margins rep78#foreign
        // Notice that the cell means from -anova- match the means from -mean-
        // Now plot the cell means:
        marginsplot, noci ytitle(Mean Price)
        HTH.

        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Thank you very much for your answer Bruce! This approach is very useful as well.
          I noticed that the -mean- command doesn't allow the "foreign" variable in the example to be a string, I then generated a new dummy variable. Also, the anova doesn't allow "rep78" to have negative values (days in my case). However, it is good because it doesn't collapse data and it is well worth knowing!
          Best,
          Aurélien

          Comment

          Working...
          X