Announcement

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

  • Line Graph Not Smoothed Out

    I am trying to create a line graph for the variable DACC to show how the level of DACC changed over the year. Doing so I used the below code but the graph is not smooth and hard to see how the value have changed over the years

    Code:
    tsline DACC
    Click image for larger version

Name:	Screen Shot 2565-03-31 at 02.04.43.png
Views:	1
Size:	29.6 KB
ID:	1657042



    I have also tried
    Code:
     twoway (line DACC Year)
    But the graph output comes is very messy like a children drawing

    Below are my data which is in panel structure

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 Ticker int Year str23 Industry byte SICCode float DACC
    "TH:2S"    1995 "Industrials"             11           .
    "TH:2S"    1996 "Industrials"             11           .
    "TH:2S"    1997 "Industrials"             11           .
    "TH:2S"    1998 "Industrials"             11           .
    "TH:2S"    1999 "Industrials"             11           .
    "TH:2S"    2000 "Industrials"             11           .
    "TH:2S"    2001 "Industrials"             11           .
    "TH:2S"    2002 "Industrials"             11           .
    "TH:2S"    2003 "Industrials"             11           .
    "TH:2S"    2004 "Industrials"             11           .
    "TH:2S"    2005 "Industrials"             11           .
    "TH:2S"    2006 "Industrials"             11           .
    "TH:2S"    2007 "Industrials"             11  -.08454061
    "TH:2S"    2008 "Industrials"             11  -.25864583
    "TH:2S"    2009 "Industrials"             11    .6085715
    "TH:2S"    2010 "Industrials"             11   .09650405
    "TH:2S"    2011 "Industrials"             11   -.1017216
    "TH:2S"    2012 "Industrials"             11   .11378127
    "TH:2S"    2013 "Industrials"             11  -.05965737
    "TH:2S"    2014 "Industrials"             11  -.04307863
    "TH:A"     1995 "Property & Construction" 77           .
    "TH:A"     1996 "Property & Construction" 77           .
    "TH:A"     1997 "Property & Construction" 77           .
    "TH:A"     1998 "Property & Construction" 77           .
    "TH:A"     1999 "Property & Construction" 77           .
    "TH:A"     2000 "Property & Construction" 77           .
    "TH:A"     2001 "Property & Construction" 77           .
    "TH:A"     2002 "Property & Construction" 77           .
    "TH:A"     2003 "Property & Construction" 77           .
    "TH:A"     2004 "Property & Construction" 77    .7635902
    "TH:A"     2005 "Property & Construction" 77   .06726224
    "TH:A"     2006 "Property & Construction" 77   -.1024842
    "TH:A"     2007 "Property & Construction" 77   .09083974
    "TH:A"     2008 "Property & Construction" 77  -.02267651
    "TH:A"     2009 "Property & Construction" 77  -.15725097
    "TH:A"     2010 "Property & Construction" 77    .0957468
    "TH:A"     2011 "Property & Construction" 77  .032091457
    "TH:A"     2012 "Property & Construction" 77    .1184249
    "TH:A"     2013 "Property & Construction" 77    .2663026
    "TH:A"     2014 "Property & Construction" 77    .2288631
    "TH:AA"    1995 "Industrials"             11    .1406714
    "TH:AA"    1996 "Industrials"             11    .0505299
    "TH:AA"    1997 "Industrials"             11   .11710031
    "TH:AA"    1998 "Industrials"             11   .14672938
    "TH:AA"    1999 "Industrials"             11  -.05598317
    "TH:AA"    2000 "Industrials"             11  -.01284377
    "TH:AA"    2001 "Industrials"             11  .004790202
    "TH:AA"    2002 "Industrials"             11   .05033767
    "TH:AA"    2003 "Industrials"             11   .04497265
    "TH:AA"    2004 "Industrials"             11  -.12834519
    "TH:AA"    2005 "Industrials"             11   .05263968
    "TH:AA"    2006 "Industrials"             11   .09047706
    "TH:AA"    2007 "Industrials"             11  .011825196
    "TH:AA"    2008 "Industrials"             11           .
    "TH:AA"    2009 "Industrials"             11           .
    "TH:AA"    2010 "Industrials"             11           .
    "TH:AA"    2011 "Industrials"             11           .
    "TH:AA"    2012 "Industrials"             11           .
    "TH:AA"    2013 "Industrials"             11           .
    "TH:AA"    2014 "Industrials"             11           .
    "TH:AAV"   1995 "Services"                55           .
    "TH:AAV"   1996 "Services"                55           .
    "TH:AAV"   1997 "Services"                55           .
    "TH:AAV"   1998 "Services"                55           .
    "TH:AAV"   1999 "Services"                55           .
    "TH:AAV"   2000 "Services"                55           .
    "TH:AAV"   2001 "Services"                55           .
    "TH:AAV"   2002 "Services"                55           .
    "TH:AAV"   2003 "Services"                55           .
    "TH:AAV"   2004 "Services"                55           .
    "TH:AAV"   2005 "Services"                55           .
    "TH:AAV"   2006 "Services"                55           .
    "TH:AAV"   2007 "Services"                55           .
    "TH:AAV"   2008 "Services"                55           .
    "TH:AAV"   2009 "Services"                55           .
    "TH:AAV"   2010 "Services"                55   1.0919831
    "TH:AAV"   2011 "Services"                55   .28426614
    "TH:AAV"   2012 "Services"                55     3.43393
    "TH:AAV"   2013 "Services"                55  -.03935567
    "TH:AAV"   2014 "Services"                55 -.017541166
    "TH:ABICO" 1995 "Agro & Food Industry"    22           .
    "TH:ABICO" 1996 "Agro & Food Industry"    22           .
    "TH:ABICO" 1997 "Agro & Food Industry"    22           .
    "TH:ABICO" 1998 "Agro & Food Industry"    22           .
    "TH:ABICO" 1999 "Agro & Food Industry"    22           .
    "TH:ABICO" 2000 "Agro & Food Industry"    22           .
    "TH:ABICO" 2001 "Agro & Food Industry"    22    .3811837
    "TH:ABICO" 2002 "Agro & Food Industry"    22 -.068777665
    "TH:ABICO" 2003 "Agro & Food Industry"    22   -.1509448
    "TH:ABICO" 2004 "Agro & Food Industry"    22  -1.1338484
    "TH:ABICO" 2005 "Agro & Food Industry"    22    .6798385
    "TH:ABICO" 2006 "Agro & Food Industry"    22 -.013820863
    "TH:ABICO" 2007 "Agro & Food Industry"    22  .066848315
    "TH:ABICO" 2008 "Agro & Food Industry"    22   -.1630021
    "TH:ABICO" 2009 "Agro & Food Industry"    22    .1760944
    "TH:ABICO" 2010 "Agro & Food Industry"    22  .027172344
    "TH:ABICO" 2011 "Agro & Food Industry"    22    .1821229
    "TH:ABICO" 2012 "Agro & Food Industry"    22    .2805742
    "TH:ABICO" 2013 "Agro & Food Industry"    22   .04285799
    "TH:ABICO" 2014 "Agro & Food Industry"    22   .06678031
    end
    format %ty Year

  • #2
    Because your data is in panel format, you have multiple different observations for the DACC variable per year. For example, in 2014, it is equal to .06678031 for TH:ABICO, and -.017541166 for TH:AAV. You are graphing all of these observations in the same plot, which is why it looks the way it does.

    What are you hoping to graph? Do you want individual plots on the value of DACC by year for each ticker? Or perhaps the mean value of DACC across tickers by year? You need to provide more detail on what your intended output is before more specific advice can be given.
    Last edited by Ali Atia; 30 Mar 2022, 14:54.

    Comment


    • #3
      Ali Atia Thank you for providing your insight, I now understand where the issues is. Essentially, my ambition is to make a graph like below to show how the value changes over time.

      Click image for larger version

Name:	Screen Shot 2565-03-31 at 12.34.43.png
Views:	1
Size:	277.1 KB
ID:	1657109

      Source: Chen et al., 2008

      Based on your explanation, do you think to achieve this I should take DACC summed for all ticker in a year and plot or take mean of all years and plot ? Or would be great if you could suggest any other means to achieve this.

      Thank you for your help

      Comment


      • #4
        Your question on how to aggregate cannot be answered without knowledge of the subject. Usually, a stock market index is a weighted average of selected shares and that is how one keeps track of stock market movements. With many stocks, the sum or mean can be biased due to missing data and entry of new firms in latter years of the sample. You need to find out what is the common method of aggregation in the literature. Otherwise, the following shows how you do it with summing. For means, delete "(sum)" in the code below.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str9 Ticker int Year str23 Industry byte SICCode float DACC
        "TH:2S"    1995 "Industrials"             11           .
        "TH:2S"    1996 "Industrials"             11           .
        "TH:2S"    1997 "Industrials"             11           .
        "TH:2S"    1998 "Industrials"             11           .
        "TH:2S"    1999 "Industrials"             11           .
        "TH:2S"    2000 "Industrials"             11           .
        "TH:2S"    2001 "Industrials"             11           .
        "TH:2S"    2002 "Industrials"             11           .
        "TH:2S"    2003 "Industrials"             11           .
        "TH:2S"    2004 "Industrials"             11           .
        "TH:2S"    2005 "Industrials"             11           .
        "TH:2S"    2006 "Industrials"             11           .
        "TH:2S"    2007 "Industrials"             11  -.08454061
        "TH:2S"    2008 "Industrials"             11  -.25864583
        "TH:2S"    2009 "Industrials"             11    .6085715
        "TH:2S"    2010 "Industrials"             11   .09650405
        "TH:2S"    2011 "Industrials"             11   -.1017216
        "TH:2S"    2012 "Industrials"             11   .11378127
        "TH:2S"    2013 "Industrials"             11  -.05965737
        "TH:2S"    2014 "Industrials"             11  -.04307863
        "TH:A"     1995 "Property & Construction" 77           .
        "TH:A"     1996 "Property & Construction" 77           .
        "TH:A"     1997 "Property & Construction" 77           .
        "TH:A"     1998 "Property & Construction" 77           .
        "TH:A"     1999 "Property & Construction" 77           .
        "TH:A"     2000 "Property & Construction" 77           .
        "TH:A"     2001 "Property & Construction" 77           .
        "TH:A"     2002 "Property & Construction" 77           .
        "TH:A"     2003 "Property & Construction" 77           .
        "TH:A"     2004 "Property & Construction" 77    .7635902
        "TH:A"     2005 "Property & Construction" 77   .06726224
        "TH:A"     2006 "Property & Construction" 77   -.1024842
        "TH:A"     2007 "Property & Construction" 77   .09083974
        "TH:A"     2008 "Property & Construction" 77  -.02267651
        "TH:A"     2009 "Property & Construction" 77  -.15725097
        "TH:A"     2010 "Property & Construction" 77    .0957468
        "TH:A"     2011 "Property & Construction" 77  .032091457
        "TH:A"     2012 "Property & Construction" 77    .1184249
        "TH:A"     2013 "Property & Construction" 77    .2663026
        "TH:A"     2014 "Property & Construction" 77    .2288631
        "TH:AA"    1995 "Industrials"             11    .1406714
        "TH:AA"    1996 "Industrials"             11    .0505299
        "TH:AA"    1997 "Industrials"             11   .11710031
        "TH:AA"    1998 "Industrials"             11   .14672938
        "TH:AA"    1999 "Industrials"             11  -.05598317
        "TH:AA"    2000 "Industrials"             11  -.01284377
        "TH:AA"    2001 "Industrials"             11  .004790202
        "TH:AA"    2002 "Industrials"             11   .05033767
        "TH:AA"    2003 "Industrials"             11   .04497265
        "TH:AA"    2004 "Industrials"             11  -.12834519
        "TH:AA"    2005 "Industrials"             11   .05263968
        "TH:AA"    2006 "Industrials"             11   .09047706
        "TH:AA"    2007 "Industrials"             11  .011825196
        "TH:AA"    2008 "Industrials"             11           .
        "TH:AA"    2009 "Industrials"             11           .
        "TH:AA"    2010 "Industrials"             11           .
        "TH:AA"    2011 "Industrials"             11           .
        "TH:AA"    2012 "Industrials"             11           .
        "TH:AA"    2013 "Industrials"             11           .
        "TH:AA"    2014 "Industrials"             11           .
        "TH:AAV"   1995 "Services"                55           .
        "TH:AAV"   1996 "Services"                55           .
        "TH:AAV"   1997 "Services"                55           .
        "TH:AAV"   1998 "Services"                55           .
        "TH:AAV"   1999 "Services"                55           .
        "TH:AAV"   2000 "Services"                55           .
        "TH:AAV"   2001 "Services"                55           .
        "TH:AAV"   2002 "Services"                55           .
        "TH:AAV"   2003 "Services"                55           .
        "TH:AAV"   2004 "Services"                55           .
        "TH:AAV"   2005 "Services"                55           .
        "TH:AAV"   2006 "Services"                55           .
        "TH:AAV"   2007 "Services"                55           .
        "TH:AAV"   2008 "Services"                55           .
        "TH:AAV"   2009 "Services"                55           .
        "TH:AAV"   2010 "Services"                55   1.0919831
        "TH:AAV"   2011 "Services"                55   .28426614
        "TH:AAV"   2012 "Services"                55     3.43393
        "TH:AAV"   2013 "Services"                55  -.03935567
        "TH:AAV"   2014 "Services"                55 -.017541166
        "TH:ABICO" 1995 "Agro & Food Industry"    22           .
        "TH:ABICO" 1996 "Agro & Food Industry"    22           .
        "TH:ABICO" 1997 "Agro & Food Industry"    22           .
        "TH:ABICO" 1998 "Agro & Food Industry"    22           .
        "TH:ABICO" 1999 "Agro & Food Industry"    22           .
        "TH:ABICO" 2000 "Agro & Food Industry"    22           .
        "TH:ABICO" 2001 "Agro & Food Industry"    22    .3811837
        "TH:ABICO" 2002 "Agro & Food Industry"    22 -.068777665
        "TH:ABICO" 2003 "Agro & Food Industry"    22   -.1509448
        "TH:ABICO" 2004 "Agro & Food Industry"    22  -1.1338484
        "TH:ABICO" 2005 "Agro & Food Industry"    22    .6798385
        "TH:ABICO" 2006 "Agro & Food Industry"    22 -.013820863
        "TH:ABICO" 2007 "Agro & Food Industry"    22  .066848315
        "TH:ABICO" 2008 "Agro & Food Industry"    22   -.1630021
        "TH:ABICO" 2009 "Agro & Food Industry"    22    .1760944
        "TH:ABICO" 2010 "Agro & Food Industry"    22  .027172344
        "TH:ABICO" 2011 "Agro & Food Industry"    22    .1821229
        "TH:ABICO" 2012 "Agro & Food Industry"    22    .2805742
        "TH:ABICO" 2013 "Agro & Food Industry"    22   .04285799
        "TH:ABICO" 2014 "Agro & Food Industry"    22   .06678031
        end
        format %ty Year
        
        collapse (sum) DACC, by(Year)
        tsset Year
        tsline DACC, scheme(s1mono) xtitle("")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.1 KB
ID:	1657121

        Last edited by Andrew Musau; 31 Mar 2022, 01:36.

        Comment


        • #5
          Andrew Musau Thank you Andrew for your help. Don't want to bore you about my work, but shortly the DACC variable is the earnings management by firms in a particular year. My ambition is to show in a graph what was the level of DACC in each year. In such case to my understanding the SUM should work.

          In the literature although they don't say what aggregation method was used to plot the graph, they report the DACC number in descriptive statistics table

          Just wanted to check what command should I add to show all the years (1995, 1996, 1997) or increase the scaling of the years in the X axis.

          Thank you once again for your help
          Last edited by Farhan Hasnat; 01 Apr 2022, 04:29.

          Comment


          • #6
            Code:
            tsline DACC, scheme(s1mono) xtitle("") xlab(1995/2015, labsize(2))
            Last edited by Andrew Musau; 02 Apr 2022, 07:18.

            Comment


            • #7
              Andrew Musau Thank you for your help, it worked perfectly

              Comment


              • #8
                Originally posted by Andrew Musau View Post
                Your question on how to aggregate cannot be answered without knowledge of the subject. Usually, a stock market index is a weighted average of selected shares and that is how one keeps track of stock market movements. With many stocks, the sum or mean can be biased due to missing data and entry of new firms in latter years of the sample. You need to find out what is the common method of aggregation in the literature. Otherwise, the following shows how you do it with summing. For means, delete "(sum)" in the code below.

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str9 Ticker int Year str23 Industry byte SICCode float DACC
                "TH:2S" 1995 "Industrials" 11 .
                "TH:2S" 1996 "Industrials" 11 .
                "TH:2S" 1997 "Industrials" 11 .
                "TH:2S" 1998 "Industrials" 11 .
                "TH:2S" 1999 "Industrials" 11 .
                "TH:2S" 2000 "Industrials" 11 .
                "TH:2S" 2001 "Industrials" 11 .
                "TH:2S" 2002 "Industrials" 11 .
                "TH:2S" 2003 "Industrials" 11 .
                "TH:2S" 2004 "Industrials" 11 .
                "TH:2S" 2005 "Industrials" 11 .
                "TH:2S" 2006 "Industrials" 11 .
                "TH:2S" 2007 "Industrials" 11 -.08454061
                "TH:2S" 2008 "Industrials" 11 -.25864583
                "TH:2S" 2009 "Industrials" 11 .6085715
                "TH:2S" 2010 "Industrials" 11 .09650405
                "TH:2S" 2011 "Industrials" 11 -.1017216
                "TH:2S" 2012 "Industrials" 11 .11378127
                "TH:2S" 2013 "Industrials" 11 -.05965737
                "TH:2S" 2014 "Industrials" 11 -.04307863
                "TH:A" 1995 "Property & Construction" 77 .
                "TH:A" 1996 "Property & Construction" 77 .
                "TH:A" 1997 "Property & Construction" 77 .
                "TH:A" 1998 "Property & Construction" 77 .
                "TH:A" 1999 "Property & Construction" 77 .
                "TH:A" 2000 "Property & Construction" 77 .
                "TH:A" 2001 "Property & Construction" 77 .
                "TH:A" 2002 "Property & Construction" 77 .
                "TH:A" 2003 "Property & Construction" 77 .
                "TH:A" 2004 "Property & Construction" 77 .7635902
                "TH:A" 2005 "Property & Construction" 77 .06726224
                "TH:A" 2006 "Property & Construction" 77 -.1024842
                "TH:A" 2007 "Property & Construction" 77 .09083974
                "TH:A" 2008 "Property & Construction" 77 -.02267651
                "TH:A" 2009 "Property & Construction" 77 -.15725097
                "TH:A" 2010 "Property & Construction" 77 .0957468
                "TH:A" 2011 "Property & Construction" 77 .032091457
                "TH:A" 2012 "Property & Construction" 77 .1184249
                "TH:A" 2013 "Property & Construction" 77 .2663026
                "TH:A" 2014 "Property & Construction" 77 .2288631
                "TH:AA" 1995 "Industrials" 11 .1406714
                "TH:AA" 1996 "Industrials" 11 .0505299
                "TH:AA" 1997 "Industrials" 11 .11710031
                "TH:AA" 1998 "Industrials" 11 .14672938
                "TH:AA" 1999 "Industrials" 11 -.05598317
                "TH:AA" 2000 "Industrials" 11 -.01284377
                "TH:AA" 2001 "Industrials" 11 .004790202
                "TH:AA" 2002 "Industrials" 11 .05033767
                "TH:AA" 2003 "Industrials" 11 .04497265
                "TH:AA" 2004 "Industrials" 11 -.12834519
                "TH:AA" 2005 "Industrials" 11 .05263968
                "TH:AA" 2006 "Industrials" 11 .09047706
                "TH:AA" 2007 "Industrials" 11 .011825196
                "TH:AA" 2008 "Industrials" 11 .
                "TH:AA" 2009 "Industrials" 11 .
                "TH:AA" 2010 "Industrials" 11 .
                "TH:AA" 2011 "Industrials" 11 .
                "TH:AA" 2012 "Industrials" 11 .
                "TH:AA" 2013 "Industrials" 11 .
                "TH:AA" 2014 "Industrials" 11 .
                "TH:AAV" 1995 "Services" 55 .
                "TH:AAV" 1996 "Services" 55 .
                "TH:AAV" 1997 "Services" 55 .
                "TH:AAV" 1998 "Services" 55 .
                "TH:AAV" 1999 "Services" 55 .
                "TH:AAV" 2000 "Services" 55 .
                "TH:AAV" 2001 "Services" 55 .
                "TH:AAV" 2002 "Services" 55 .
                "TH:AAV" 2003 "Services" 55 .
                "TH:AAV" 2004 "Services" 55 .
                "TH:AAV" 2005 "Services" 55 .
                "TH:AAV" 2006 "Services" 55 .
                "TH:AAV" 2007 "Services" 55 .
                "TH:AAV" 2008 "Services" 55 .
                "TH:AAV" 2009 "Services" 55 .
                "TH:AAV" 2010 "Services" 55 1.0919831
                "TH:AAV" 2011 "Services" 55 .28426614
                "TH:AAV" 2012 "Services" 55 3.43393
                "TH:AAV" 2013 "Services" 55 -.03935567
                "TH:AAV" 2014 "Services" 55 -.017541166
                "TH:ABICO" 1995 "Agro & Food Industry" 22 .
                "TH:ABICO" 1996 "Agro & Food Industry" 22 .
                "TH:ABICO" 1997 "Agro & Food Industry" 22 .
                "TH:ABICO" 1998 "Agro & Food Industry" 22 .
                "TH:ABICO" 1999 "Agro & Food Industry" 22 .
                "TH:ABICO" 2000 "Agro & Food Industry" 22 .
                "TH:ABICO" 2001 "Agro & Food Industry" 22 .3811837
                "TH:ABICO" 2002 "Agro & Food Industry" 22 -.068777665
                "TH:ABICO" 2003 "Agro & Food Industry" 22 -.1509448
                "TH:ABICO" 2004 "Agro & Food Industry" 22 -1.1338484
                "TH:ABICO" 2005 "Agro & Food Industry" 22 .6798385
                "TH:ABICO" 2006 "Agro & Food Industry" 22 -.013820863
                "TH:ABICO" 2007 "Agro & Food Industry" 22 .066848315
                "TH:ABICO" 2008 "Agro & Food Industry" 22 -.1630021
                "TH:ABICO" 2009 "Agro & Food Industry" 22 .1760944
                "TH:ABICO" 2010 "Agro & Food Industry" 22 .027172344
                "TH:ABICO" 2011 "Agro & Food Industry" 22 .1821229
                "TH:ABICO" 2012 "Agro & Food Industry" 22 .2805742
                "TH:ABICO" 2013 "Agro & Food Industry" 22 .04285799
                "TH:ABICO" 2014 "Agro & Food Industry" 22 .06678031
                end
                format %ty Year
                
                collapse (sum) DACC, by(Year)
                tsset Year
                tsline DACC, scheme(s1mono) xtitle("")
                [ATTACH=CONFIG]n1657121[/ATTACH]
                Andrew Musau Since I did not find any clue on aggregation of the data, my advisors suggested to using mean as the method of aggregation. While I created a variable with the mean by year (using the below code), to created the graph I have a feeling I am doing something wrong here. Would be really kind of you if you could provide you advice on this method. Thanking you in advance

                Code:
                bysort Year: egen DACC_Mean = mean(DACC_w)

                Comment


                • #9
                  That is fine.

                  Code:
                  bysort Year: egen DACC_Mean = mean(DACC_w)
                  line DACC_Mean Year, sort

                  Comment


                  • #10
                    Andrew Musau Thank you Andrew for your kind support

                    Comment

                    Working...
                    X