Announcement

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

  • How to Plot panel data as a time series ????

    Dear Statilist

    May it is very simple but still I cannot find my answer

    I have panel data for 29 countries and T= 40 years
    I want to plot my dependent variable as a time series (only one line)

    I used the following command but it plots the mean for the series since I want to plot the original panel data series ?
    Any help?

    PHP Code:
    xtset CountryID Year
    lgraph GDP Year

    then it gives me this graph
    [/PHP]

    it gives me the following graph
    Click image for larger version

Name:	Graph statalist.jpg
Views:	1
Size:	25.6 KB
ID:	1629956


    So any idea to plot the panel data as one line without plotting the mean??

  • #2
    lgraph is a community-contributed command from SSC, as you are asked to explain. See https://www.statalist.org/forums/help#stata -- you're not completely new to Statalist, so you should know that you are asked to read the FAQ Advice before posting.

    As its help explains,
    lgraph defaults to showing the mean across panels across time.

    If you don't want that, you need something else.

    Let me guess. Your choice of
    lgraph likely came from Googling furiously and finding a mention of lgraph and then installing it and running it without studying the help very closely. If my guess is right, that is the wrong way round.

    Start looking within Stata. Sometimes it then appears that the best way to do something is using a community-contributed command. But you're right: this is a very simple task.and official Stata offers commands to do it. You have panel data and want to plot them. So, for example looking at the menu
    Graphics then Panel-data line plots leads you to the xtline command.

    But with panel data there is no such thing as "a line" to show the series. There is a choice between separate graphs for each panel with a line in each and a combined graph for all series showing several series superimposed or overlaid.

    What will work best depends on your data, including how many countries you have. If it's 200-odd, it is possible that nothing works very well, but you have to try it and come back to us with a more specific problem.

    Comment


    • #3
      Dear Dr Nick
      Thanks for yoyr response

      Actually your guess is totally not true , I studied different materials and book in STATA about panel data and how to plot it but still I did not find my answer???
      I know that the
      PHP Code:
      lgraph 
      plots the mean and I know about the
      PHP Code:
      xtline 
      but this command plot the panel individually or overlay it in one graph , but my question is there any similar
      PHP Code:
      xtline 
      to plot the pane data in one line one graph similar to the time series variable???

      Comment


      • #4
        It is hard for me to imagine that studying many materials would not identify xtline as the first command to try here. Still, I take you at your word.

        On your question: as already stated, I can't imagine how panel data could be plotted as "one line" unless you select just one panel or collapse across panels in some way. So, sorry, but I don't understand what you seek here. Can you give a reference to literature with such a graph?

        Comment


        • #5
          Dear Mr. Cox

          First of all, thank you for your prompt answers with respect to various topics on the website. I would appreciate it if you could help me with the following question. I am aware one should read the FAQ before posting but due to time constraints and watching numerous videos & posts I have decided to appeal to your help nonetheless. My data looks as follows:
          Firms Years Scores
          Company A - 2009 - 83
          Company A - 2010 - 66
          ...
          Company A - 2022 - 90

          Company B - 2009 - 77
          ...
          Company B - 2022 - 80
          ...
          Company Z - ... - ...

          I would like to make a line plot to see the evolution of the scores. However, "line scores years" lists all the observations in each year, not the mean across the sample in each year. If I try to circumvent this problem by for example tsset years or xtset, STATA reasons the problem of repeated values (years) in the dataset.

          I appreciate your time and willingness of helping us solve these problems.

          Looking forward to hearing from you

          Raymond

          Comment


          • #6
            The FAQ is not there to waste your time, it is there to help you write answerable questions. Right now you are asking us to invest our time to make your question answerable, just because you have "time constraints". This way you are claiming that your time is more valueable than ours. For you that is obviously true, but why would we think so?

            You try to give us an example of what your data looks like. That is a good idea, but your execution still needs some work. Please see the FAQ on how to give us an example of your data.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              I agree with Maarten Buis. What can be said easily is that with panel data

              Code:
              tsset years 
              would fail for precisely the reason stated, repeated values, because you need to specify a panel identifier too.

              Comment


              • #8
                Dear Mr. Cox, Dear Mr. Buis

                Thank you for your comments.

                My data looks as follows

                [CODE]
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str50 Firms                   Years Score            Score2
                "ADCOCK INGRAM HLGS LD Healthcare"   2009 "50"               "50"              
                "ADCOCK INGRAM HLGS LD Healthcare"   2010 "42.5"            "42.5"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2011 "70"               "70"              
                "ADCOCK INGRAM HLGS LD Healthcare"   2012 "70"               "70"              
                "ADCOCK INGRAM HLGS LD Healthcare"   2013 "77.98"          "77.98"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2014 "81.73"           "81.73"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2015 "80"                "80"              
                "ADCOCK INGRAM HLGS LD Healthcare"   2016 "81.52"           "66.52"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2017 "88.48"           "73.48"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2018 "90.56"           "76.14"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2019 "93.69"           "78.69"            
                "ADCOCK INGRAM HLGS LD Healthcare"   2020 "95.28"            "98"              
                "ADCOCK INGRAM HLGS LD Healthcare"   2021 ""                                
                "ADCOCK INGRAM HLGS LD Healthcare"   2022 ""                  
                 JSE LTD                             2009  70.4               60      
                ...
                 JSE LTD                             2022   80                65
                In total I have 100 companies with 1400 observations, ranging from 2007 until 2022. "" means there are no observed values for that company in that year.

                I destring Score and Years by
                Code:
                 destring Score Years, replace force
                I would like to have a line graph with the years on the x-as and the scores on the y-as. The years range from 2007 until 2022, the values can range from 0 to 125.

                I code
                Code:
                 line Score Years
                This results in a messy graph. I then code
                Code:
                sort Years
                Now when

                Code:
                line Score Years
                I receive the following graph
                Click image for larger version

Name:	Graph.png
Views:	1
Size:	77.8 KB
ID:	1634455

                Therefore, each observation in each year was counted as an individual observation. I am searching for the answer to have the data in a line graph with one observation/datapoint for each year which would be the mean of all the observed values in that year for each firm.

                Regards

                Comment

                Working...
                X